Skip to content

Conversation

JAORMX
Copy link
Collaborator

@JAORMX JAORMX commented Oct 10, 2025

Summary

Implement external authentication configuration for MCP servers via a new MCPExternalAuthConfig custom resource. This enables MCP servers to exchange incoming authentication tokens for tokens that can be used with external services via RFC-8693 OAuth 2.0 Token Exchange.

Implementation

  • MCPExternalAuthConfig CRD: Namespace-scoped configuration resource
  • Controller: Implements finalizer to prevent deletion while referenced, hash-based change detection to trigger MCPServer reconciliation
  • MCPServer Integration: Configuration injected into deployments via RunConfig ConfigMap
  • Security: OAuth client secret provided through TOOLHIVE_TOKEN_EXCHANGE_CLIENT_SECRET environment variable referencing a Kubernetes Secret

Testing

  • Unit tests: 83% average coverage
  • Integration tests for MCPServer external auth handling
  • E2E Chainsaw tests validating end-to-end flow
  • Example manifests included

Related

  • Proposal: docs/proposals/token-exchange-middleware.md

🤖 Generated with Claude Code

@JAORMX JAORMX force-pushed the external-auth-controller-impl branch from 6bea254 to b185a87 Compare October 10, 2025 13:38
Implement external authentication configuration for MCP servers via a new
MCPExternalAuthConfig custom resource. This enables MCP servers to exchange
incoming authentication tokens for tokens that can be used with external
services via RFC-8693 OAuth 2.0 Token Exchange.

The MCPExternalAuthConfig is namespace-scoped and can only be referenced by
MCPServers in the same namespace. The controller implements a finalizer to
prevent deletion while referenced, and uses hash-based change detection to
efficiently trigger MCPServer reconciliation when configuration changes.

Configuration is injected into MCPServer deployments via RunConfig ConfigMap
with the OAuth client secret provided through a TOOLHIVE_TOKEN_EXCHANGE_CLIENT_SECRET
environment variable that references a Kubernetes Secret, following security
best practices.

The controller follows the same pattern as MCPToolConfig, including:
- ReferencingServers status field for tracking which MCPServers reference the config
- Proper reconcile flow that updates status with referencing servers
- Correct SetupWithManager watch handler that reconciles only the specific
  MCPServers that reference a changed ExternalAuthConfig (not all configs in namespace)
- Status updates during deletion when config is still referenced

Includes comprehensive unit tests (83% coverage), integration tests, E2E
Chainsaw tests, and example manifests.

Co-Authored-By: Jakub Hrozek <[email protected]>
Co-authored-by: Claude <[email protected]>
Co-authored-by: Juan Antonio Osorio <[email protected]>
Signed-off-by: Juan Antonio Osorio <[email protected]>
@JAORMX JAORMX force-pushed the external-auth-controller-impl branch from b185a87 to c61617d Compare October 10, 2025 14:06
Copy link

codecov bot commented Oct 10, 2025

Codecov Report

❌ Patch coverage is 28.54123% with 338 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.56%. Comparing base (81e6666) to head (c61617d).

Files with missing lines Patch % Lines
...thv-operator/api/v1alpha1/zz_generated.deepcopy.go 0.00% 101 Missing ⚠️
...d/thv-operator/controllers/mcpserver_controller.go 19.26% 82 Missing and 6 partials ⚠️
...or/controllers/mcpexternalauthconfig_controller.go 61.14% 59 Missing and 9 partials ⚠️
...md/thv-operator/controllers/mcpserver_runconfig.go 6.94% 66 Missing and 1 partial ⚠️
cmd/thv-operator/main.go 0.00% 14 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #2150      +/-   ##
==========================================
- Coverage   48.84%   48.56%   -0.28%     
==========================================
  Files         242      244       +2     
  Lines       30722    31194     +472     
==========================================
+ Hits        15005    15149     +144     
- Misses      14595    14901     +306     
- Partials     1122     1144      +22     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants