You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 865d13d
Browse filesBrowse the repository at this point in the historyBrowse files
Rashmi
committed
feat(client): support HTTP auth in ClientSessionGroup
Copy file name to clipboardExpand all lines: docs/client/session-groups.md
+27Lines changed: 27 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -70,6 +70,33 @@ If you already hold a connected `ClientSession` (`Client.session` is one), hand
70
70
71
71
`ClientSessionGroup` is built on `ClientSession`, not on `Client`. Each `connect_to_server` runs the classic `initialize` handshake. It never sends the `server/discover` probe described in **[Protocol versions](../protocol-versions.md)**. Every MCP server understands that handshake, so this costs you compatibility with nothing; it only means a group takes the older, slower path to a server that could do better.
72
72
73
+
## Authentication
74
+
75
+
When connecting to HTTP servers using `StreamableHttpParameters` or `SseServerParameters`, you can configure an authentication provider (such as an OAuth 2.0 `OAuthClientProvider` or custom `httpx2.Auth` handler) via the `auth=` parameter:
76
+
77
+
```python
78
+
from mcp.client.auth import OAuthClientProvider
79
+
from mcp.client.session_group import ClientSessionGroup, StreamableHttpParameters
80
+
81
+
server_auth = OAuthClientProvider(
82
+
server_url="https://api.example.com",
83
+
client_metadata=client_metadata,
84
+
storage=token_storage,
85
+
redirect_handler=redirect_handler,
86
+
callback_handler=callback_handler,
87
+
)
88
+
89
+
server_params = StreamableHttpParameters(
90
+
url="https://api.example.com/mcp",
91
+
auth=server_auth,
92
+
)
93
+
94
+
asyncwith ClientSessionGroup() as group:
95
+
await group.connect_to_server(server_params)
96
+
```
97
+
98
+
Because `auth` is configured per `ServerParameters` instance, each server in the session group maintains independent authentication context, scopes, and token-refresh lifecycle. Custom headers can still be supplied alongside `auth` via `headers=`.
99
+
73
100
## Recap
74
101
75
102
*`ClientSessionGroup` holds many server connections and merges their tools, resources, and prompts into one `dict` each.
0 commit comments