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
9 changes: 6 additions & 3 deletions src/mcp/client/auth/extensions/client_credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ async def _exchange_token_client_credentials(self) -> httpx.Request:
"grant_type": "client_credentials",
}

headers: dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded"}
headers: dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}

# Use standard auth methods (client_secret_basic, client_secret_post, none)
token_data, headers = self.context.prepare_token_auth(token_data, headers)
Expand Down Expand Up @@ -320,7 +320,7 @@ async def _exchange_token_client_credentials(self) -> httpx.Request:
"grant_type": "client_credentials",
}

headers: dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded"}
headers: dict[str, str] = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}

# Add JWT client authentication (RFC 7523 Section 2.2)
await self._add_client_authentication_jwt(token_data=token_data)
Expand Down Expand Up @@ -481,5 +481,8 @@ async def _exchange_token_jwt_bearer(self) -> httpx.Request:

token_url = self._get_token_endpoint()
return httpx.Request(
"POST", token_url, data=token_data, headers={"Content-Type": "application/x-www-form-urlencoded"}
"POST",
token_url,
data=token_data,
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
)
4 changes: 2 additions & 2 deletions src/mcp/client/auth/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ async def _exchange_token_authorization_code(
token_data["resource"] = self.context.get_resource_url() # RFC 8707

# Prepare authentication based on preferred method
headers = {"Content-Type": "application/x-www-form-urlencoded"}
headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}
token_data, headers = self.context.prepare_token_auth(token_data, headers)

return httpx.Request("POST", token_url, data=token_data, headers=headers)
Expand Down Expand Up @@ -447,7 +447,7 @@ async def _refresh_token(self) -> httpx.Request:
refresh_data["resource"] = self.context.get_resource_url() # RFC 8707

# Prepare authentication based on preferred method
headers = {"Content-Type": "application/x-www-form-urlencoded"}
headers = {"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"}
refresh_data, headers = self.context.prepare_token_auth(refresh_data, headers)

return httpx.Request("POST", token_url, data=refresh_data, headers=headers)
Expand Down
Loading