Skip to content

Commit 3d70055

Browse files
committed
fix: Add accept json headers for token request
1 parent c44e68f commit 3d70055

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/mcp/client/auth.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,13 @@ async def _exchange_token(self, auth_code: str, code_verifier: str) -> httpx.Req
424424
token_data["client_secret"] = self.context.client_info.client_secret
425425

426426
return httpx.Request(
427-
"POST", token_url, data=token_data, headers={"Content-Type": "application/x-www-form-urlencoded"}
427+
"POST",
428+
token_url,
429+
data=token_data,
430+
headers={
431+
"Content-Type": "application/x-www-form-urlencoded",
432+
"Accept": "application/json",
433+
},
428434
)
429435

430436
async def _handle_token_response(self, response: httpx.Response) -> None:
@@ -478,7 +484,13 @@ async def _refresh_token(self) -> httpx.Request:
478484
refresh_data["client_secret"] = self.context.client_info.client_secret
479485

480486
return httpx.Request(
481-
"POST", token_url, data=refresh_data, headers={"Content-Type": "application/x-www-form-urlencoded"}
487+
"POST",
488+
token_url,
489+
data=refresh_data,
490+
headers={
491+
"Content-Type": "application/x-www-form-urlencoded",
492+
"Accept": "application/json"
493+
},
482494
)
483495

484496
async def _handle_refresh_response(self, response: httpx.Response) -> bool:

tests/client/test_auth.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -527,6 +527,7 @@ async def test_token_exchange_request(self, oauth_provider: OAuthClientProvider)
527527
assert request.method == "POST"
528528
assert str(request.url) == "https://api.example.com/token"
529529
assert request.headers["Content-Type"] == "application/x-www-form-urlencoded"
530+
assert request.headers["Accept"] == "application/json"
530531

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

556558
# Check form data
557559
content = request.content.decode()

0 commit comments

Comments
 (0)