Skip to content

Commit 7c83beb

Browse files
committed
fix: request json token responses
1 parent 161834d commit 7c83beb

2 files changed

Lines changed: 10 additions & 2 deletions

File tree

src/mcp/client/auth/oauth2.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,10 @@ async def _exchange_token_authorization_code(
402402
token_data["resource"] = self.context.get_resource_url() # RFC 8707
403403

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

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

449452
# Prepare authentication based on preferred method
450-
headers = {"Content-Type": "application/x-www-form-urlencoded"}
453+
headers = {
454+
"Accept": "application/json",
455+
"Content-Type": "application/x-www-form-urlencoded",
456+
}
451457
refresh_data, headers = self.context.prepare_token_auth(refresh_data, headers)
452458

453459
return httpx.Request("POST", token_url, data=refresh_data, headers=headers)

tests/client/test_auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -596,6 +596,7 @@ async def test_token_exchange_request_authorization_code(self, oauth_provider: O
596596

597597
assert request.method == "POST"
598598
assert str(request.url) == "https://api.example.com/token"
599+
assert request.headers["Accept"] == "application/json"
599600
assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"
600601

601602
# Check form data
@@ -622,6 +623,7 @@ async def test_refresh_token_request(self, oauth_provider: OAuthClientProvider,
622623

623624
assert request.method == "POST"
624625
assert str(request.url) == "https://api.example.com/token"
626+
assert request.headers["Accept"] == "application/json"
625627
assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"
626628

627629
# Check form data

0 commit comments

Comments
 (0)