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
10 changes: 8 additions & 2 deletions src/mcp/client/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,10 @@ async def _exchange_token(self, auth_code: str, code_verifier: str) -> httpx.Req
token_data["client_secret"] = self.context.client_info.client_secret

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"},
)

async def _handle_token_response(self, response: httpx.Response) -> None:
Expand Down Expand Up @@ -478,7 +481,10 @@ async def _refresh_token(self) -> httpx.Request:
refresh_data["client_secret"] = self.context.client_info.client_secret

return httpx.Request(
"POST", token_url, data=refresh_data, headers={"Content-Type": "application/x-www-form-urlencoded"}
"POST",
token_url,
data=refresh_data,
headers={"Content-Type": "application/x-www-form-urlencoded", "Accept": "application/json"},
)

async def _handle_refresh_response(self, response: httpx.Response) -> bool:
Expand Down
2 changes: 2 additions & 0 deletions tests/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ async def test_token_exchange_request(self, oauth_provider: OAuthClientProvider)
assert request.method == "POST"
assert str(request.url) == "https://api.example.com/token"
assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"
assert request.headers["Accept"] == "application/json"

# Check form data
content = request.content.decode()
Expand All @@ -552,6 +553,7 @@ async def test_refresh_token_request(self, oauth_provider: OAuthClientProvider,
assert request.method == "POST"
assert str(request.url) == "https://api.example.com/token"
assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"
assert request.headers["Accept"] == "application/json"

# Check form data
content = request.content.decode()
Expand Down