feat(auth): add token_endpoint_auth_method to OAuthClientConfig #648
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.
Some OAuth providers (e.g. HubSpot) require client credentials to be sent as POST body parameters (client_secret_post) instead of via HTTP Basic Auth header. The oauth2 crate defaults to BasicAuth, and rmcp had no way to honor the server's advertised auth method, causing TokenExchangeFailed errors.
Derive token_endpoint_auth_method from the server's authorization metadata (token_endpoint_auth_methods_supported) during configure_client. When the server advertises client_secret_post, the client is set to AuthType::RequestBody; otherwise it defaults to
BasicAuth. No new config fields are added — the behavior is driven entirely by server metadata.
Motivation and Context
OAuth servers advertise supported token endpoint auth methods via token_endpoint_auth_methods_supported in their authorization server metadata. rmcp was ignoring this field, always using Basic Auth. Servers like HubSpot that require client_secret_post would reject token requests.
How Has This Been Tested?
Tested with a simple MCP client connecting to HubSpot's remote MCP server (
https://mcp.hubspot.com/mcp), which requiresclient_secret_postauthentication.Breaking Changes
No breaking changes.
Types of changes
Checklist
Additional context
The TypeScript MCP SDK already implements the same
token_endpoint_auth_methods_supportedpattern:packages/core/src/shared/auth.ts— definestoken_endpoint_auth_methods_supportedinOAuthMetadataSchemapackages/client/src/client/auth.ts—selectClientAuthMethod()readstoken_endpoint_auth_methods_supportedfrom server metadata and picks betweenclient_secret_basic,client_secret_post, ornone;applyClientAuthentication()then sends credentials accordingly (Basic header vs POST body)This PR aligns the Rust SDK with the TypeScript SDK's existing behavior.