Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/mcp/client/auth/extensions/client_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,13 @@ async def _perform_authorization(self) -> httpx.Request:

async def _exchange_token_client_credentials(self) -> httpx.Request:
"""Build token exchange request for client_credentials grant."""

if not self.context.client_info or not self.context.client_info.client_id:
raise OAuthTokenError("No client info available") # pragma: no cover

token_data: dict[str, Any] = {
"grant_type": "client_credentials",
"client_id": self.context.client_info.client_id,
}

headers: dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded"}
Expand Down
6 changes: 6 additions & 0 deletions tests/client/auth/extensions/test_client_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,9 @@ async def test_exchange_token_client_credentials(self, mock_storage: MockTokenSt
)
provider.context.protocol_version = "2025-06-18"

# Initialize the provider first
await provider._initialize()

request = await provider._perform_authorization()

assert request.method == "POST"
Expand All @@ -269,6 +272,9 @@ async def test_exchange_token_without_scopes(self, mock_storage: MockTokenStorag
)
provider.context.protocol_version = "2024-11-05" # Old version - no resource param

# Initialize the provider first
await provider._initialize()

request = await provider._perform_authorization()

content = urllib.parse.unquote_plus(request.content.decode())
Expand Down