Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 2 additions & 0 deletions src/mcp/client/auth/oauth2.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,8 @@ def prepare_token_auth(
if headers is None:
headers = {} # pragma: no cover

headers.setdefault("Accept", "application/json")

if not self.client_info:
return data, headers # pragma: no cover

Expand Down
4 changes: 4 additions & 0 deletions tests/client/test_auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,7 @@ async def test_token_exchange_request_authorization_code(self, oauth_provider: O
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 @@ -623,6 +624,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 Expand Up @@ -655,6 +657,7 @@ async def test_basic_auth_token_exchange(self, oauth_provider: OAuthClientProvid
request = await oauth_provider._exchange_token_authorization_code("test_auth_code", "test_verifier")

# Should use basic auth (registered method)
assert request.headers["Accept"] == "application/json"
assert "Authorization" in request.headers
assert request.headers["Authorization"].startswith("Basic ")

Expand Down Expand Up @@ -700,6 +703,7 @@ async def test_basic_auth_refresh_token(self, oauth_provider: OAuthClientProvide

request = await oauth_provider._refresh_token()

assert request.headers["Accept"] == "application/json"
assert "Authorization" in request.headers
assert request.headers["Authorization"].startswith("Basic ")

Expand Down
Loading