feat: RFC 7591 dynamic client registration, server session ID presevation, and OAuth timeout fix#1
Open
acziryak-everhealth wants to merge 1 commit into
Conversation
…ation, and OAuth timeout fix - Add dynamic client registration (RFC 7591) so servers with a registration_endpoint in their OAuth discovery metadata can be used without providing oauth_client_id in config - Capture Mcp-Session-Id from server response headers instead of overwriting with a client-generated UUID - Extend transport creation timeout to 120s when OAuth browser flow may be required (was 5s, insufficient for user interaction) - Store dynamically registered client_id alongside tokens in the cache for reuse on subsequent connections
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.
Why
I was trying to get Atlassian's hosted MCP server (
mcp.atlassian.com) working through dynamic-mcp, and ran into a chain of issues that all needed fixing to make it work end-to-end.Atlassian's MCP server uses OAuth with dynamic client registration (RFC 7591) — there's no static
oauth_client_idyou can just plug into the config. Tools like VS Code and opencode handle this natively, but dynamic-mcp required a pre-registeredoauth_client_idin the config, which meant you had to do the registration dance yourself externally and then somehow get the client ID into the right place. Not great.On top of that, even if you got past the OAuth hurdle, the connection would still fail because of two other issues:
initialize, the client overwrites the server-assignedMcp-Session-Idwith a random UUID — so subsequent requests liketools/listget rejected by the serverWhat Changed
1. RFC 7591 Dynamic Client Registration
If no
oauth_client_idis provided in the config, the client now checks the server's OAuth discovery metadata for aregistration_endpoint. If one exists, it dynamically registers a new client — using the actual callback server port in theredirect_urisso the redirect URI matches exactly. The registeredclient_idgets cached alongside the tokens in~/.dynamic-mcp/oauth-servers/<name>.jsonso it's reused on subsequent connections.This means the config for an OAuth-protected server can be as simple as:
{ "description": "Atlassian", "url": "https://mcp.atlassian.com/v1/mcp" }No
oauth_client_id, no external setup scripts. dynamic-mcp handles discovery, registration, browser auth, token caching, and refresh all on its own.2. Server Session ID Preservation
After
initialize, the client now captures theMcp-Session-Idheader from the server's response and uses it for subsequent requests. A client-generated UUID is only used as a fallback if the server doesn't assign one. This fixes connections to servers like Atlassian that require their own session ID to be echoed back.3. OAuth-Aware Transport Timeout
When a server might need an OAuth browser flow (has
oauth_client_idset, or has noAuthorizationheader and might trigger dynamic registration), the transport creation timeout is extended to 120 seconds. This gives the user enough time to complete the browser authorization. Non-OAuth servers still use the original 5-second timeout.Files Changed
src/auth/oauth_client.rs— Dynamic client registration,authenticate()now acceptsOption<&str>for client_id, registration uses actual callback portsrc/auth/store.rs— Addedclient_idfield toOAuthTokensfor caching the registered client IDsrc/config/schema.rs— Addedneeds_oauth()method for timeout decisionssrc/proxy/client.rs— Session ID fallback logic (only generate UUID if server didn't assign one), OAuth-aware timeoutsrc/proxy/transport.rs— CaptureMcp-Session-Idfrom response headers, OAuth flow without explicitoauth_client_id