Skip to content

Pass httpx auth through ClientSessionGroup HTTP parameters - #3840

Open
mateolafalce wants to merge 2 commits into
modelcontextprotocol:mainfrom
mateolafalce:feat/session-group-http-auth
Open

mateolafalce wants to merge 2 commits into
modelcontextprotocol:mainfrom
mateolafalce:feat/session-group-http-auth

Conversation

@mateolafalce

Copy link
Copy Markdown

Fixes #1723

Summary

ClientSessionGroup could not carry an httpx2.Auth. Callers had to put a bearer token in headers, so an OAuthClientProvider (discovery, refresh) could not run from a session group.

SseServerParameters and StreamableHttpParameters now take an optional auth. connect_to_server passes it to sse_client and create_mcp_http_client. auth is omitted from model_dump(), model_dump_json(), and repr(): the handler can hold a credential, and it is not JSON.

Behavior

  • auth defaults to None. Stdio is unchanged.
  • One auth instance per server. Two servers that share one OAuthClientProvider share its tokens and its refresh cycle.
  • headers= is still sent. A header other than Authorization arrives as set. If the handler sets Authorization, that value is what the server sees. OAuthClientProvider sets it once it has an access token.
  • The docs example defines its own bearer handler, so copying it runs. OAuthClientProvider drops into the same auth= slot. Building one is covered in the OAuth clients page.

Tests

In-process streamable HTTP and legacy SSE: the server sees the handler's bearer token. Two servers in one group see two different tokens. A manual Authorization header does not survive a handler that sets its own, and X-Trace-Id does. Dumps do not contain the token.

uv run --frozen pytest tests/client/test_session_group.py tests/docs_src/test_session_groups.py

Pyright on the touched files reports 0 errors.

Disclosure: an AI assistant drafted this change at my request.

This branch is independent of #2065 and #3516, which are still open. It is based on current main (so max_sse_event_size is unchanged) and covers the open review notes on #3516: the docs example runs, and the test states which Authorization value the server sees.

SseServerParameters and StreamableHttpParameters can carry an
httpx2.Auth, and connect_to_server forwards it to the HTTP client.
That is what OAuthClientProvider needs. The handler is left out of
serialization.

Co-authored-by: Michael <[email protected]>

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed across 7 files

Tip: cubic used a learning from your PR history. Let your coding agent read cubic learnings directly with the cubic MCP.

Re-trigger cubic

Comment thread docs/client/session-groups.md Resolved
The coverage gate counts tests. The auth handler repr was never called,
and the in-process ASGI helpers had branches no HTTP request reaches.

Co-authored-by: Michael <[email protected]>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

auth specification in ClientSessionGroup

1 participant