Open
Conversation
Remove manual login tools and automatically start device flow and polling when no auth token is found.
Contributor
🎯 Coverage Target Met!📈 Coverage Metrics
📊 Test Statistics
🔍 Files Needing Coverage
📝 Report generated on Node.js v24.13.1 • View workflow • Coverage by Vitest + v8 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Goal
To introduce support for Dynamic Request-Level Authentication (OAuth) across the SmartBear MCP Server. Previously, the server required static, server-level credentials to be provided via environment variables at startup, making it unsuitable for multi-tenant environments or usage behind an API gateway where the active user context changes per request. This change allows the server to extract authentication tokens dynamically from incoming HTTP request headers and implements RFC 9293 OAuth discovery.
Design
To achieve request-level authentication without polluting the
@modelcontextprotocol/sdksignatures, the solution leverages Node'sAsyncLocalStorageto propagate the HTTP request headers deep into the tool execution layer.AsyncLocalStoragefor Request Context: A newrequestContextStoragewraps the execution of incoming MCP stream/HTTP requests. Tool implementations can callgetRequestHeader()deep within their business logic to pull context tokens securely and dynamically./.well-known/oauth-protected-resourceendpoint. When a client connects without credentials, the server responds with a401 Unauthorizedand includes aWWW-Authenticateheader, pointing the client to the Authorization Server to begin the OAuth flow.ConfigurationSchemadefinitions (e.g., BugSnag, Qmetry, Zephyr, Swagger, etc.) have been updated to mark authentication fields as.optional(). TheisConfigured()checks have been relaxed to allow the tools to successfully mount to the server at startup, deferring the credential requirement until the actual tool is invoked (at which point it checks the dynamic request context or falls back to the static config).Changeset
src/common/request-context.tsimplementingAsyncLocalStorageto storeIncomingMessageheaders.src/common/transport-http.tsto wraphandleRequestandhandlePostMessageinrequestContextStorage.run()./.well-known/oauth-protected-resourcemetadata endpoint.WWW-Authenticateheader to401initialization failures.OAUTH_AUTHORIZATION_SERVER_URLconfig variable.BugsnagClientto use a dynamicapiKeyresolver function instead of a hardcoded string.ReflectClient,ZephyrClient,SwaggerClient,PactflowClient,QmetryClient, andCollaboratorClientto extract tokens viagetRequestHeader().ConfigurationSchemain all clients to markapi_key/token/username/login_ticketas.optional().isConfigured()logic across all clients to ensure they mount when static credentials are omitted.Testing
npm run build,npm run format,npm run lint, andnpm run testpass successfully.clientRegistryeven when no authentication environment variables are supplied at startup.How to test with local development