Conversation
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.
Fixes #522
Motivation and Context
MCP's authorization model currently needs users to authorize through the standard OAuth 2.0 authorization code flow. This works great for scenarios where a person is involved, but it doesn't cover many machine-to-machine use cases, like CI/CD pipelines, backend services, and automated agents, where there's no user available to approve a browser-based consent screen.
SEP-1046 addresses this issue by adding the OAuth 2.0 Client Credentials grant (RFC 6749 Section 4.4) as an optional extension to MCP authorization. This PR implements that specification in the Rust SDK, offering two authentication methods:
client_secretfor simple shared-secret setups andprivate_key_jwt(RFC 7523) for asymmetric key-based authentication, which avoids sending secrets over the wire.The implementation fully relies on the existing
authmodule infrastructure. Metadata discovery, credential storage, token refresh,AuthClient, andAuthorizedHttpClientall function as they did before. The new code just adds an alternative way to get the initial access token without needing interactive authorization.How Has This Been Tested?
Along with the unit tests, there's an integration test that sets up a mock OAuth server using axum. This server provides the standard well-known metadata endpoints and a token endpoint. We cover three scenarios: a successful client_secret exchange that verifies the returned token, a request with an invalid secret that checks for an error, and a request with an unknown client ID that also confirms failure.
Breaking Changes
None. This is a purely additive change. All new types and methods are behind the existing
authfeature flag.Types of changes
Checklist
Additional context