Skip to content
Open
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
Prev Previous commit
Next Next commit
docs: wrap session group auth example in async function
  • Loading branch information
Rashmi
Rashmi committed Sep 17, 2026
commit c4d7ef22d91318120873aacb3bca2531c1def186
32 changes: 17 additions & 15 deletions docs/client/session-groups.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,21 +78,23 @@ When connecting to HTTP servers using `StreamableHttpParameters` or `SseServerPa
from mcp.client.auth import OAuthClientProvider
from mcp.client.session_group import ClientSessionGroup, StreamableHttpParameters

server_auth = OAuthClientProvider(
server_url="https://api.example.com",
client_metadata=client_metadata,
storage=token_storage,
redirect_handler=redirect_handler,
callback_handler=callback_handler,
)

server_params = StreamableHttpParameters(
url="https://api.example.com/mcp",
auth=server_auth,
)

async with ClientSessionGroup() as group:
await group.connect_to_server(server_params)

async def main() -> None:
Comment thread
cubic-dev-ai[bot] marked this conversation as resolved.
server_auth = OAuthClientProvider(
server_url="https://api.example.com",
client_metadata=client_metadata,
storage=token_storage,
redirect_handler=redirect_handler,
callback_handler=callback_handler,
)

server_params = StreamableHttpParameters(
url="https://api.example.com/mcp",
auth=server_auth,
)

async with ClientSessionGroup() as group:
await group.connect_to_server(server_params)
```

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=`.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: When the same auth object is assigned to two parameter instances, ClientSessionGroup shares its mutable OAuth context and tokens. Tell users to construct a distinct auth instance per server before claiming these lifecycles are independent.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At docs/client/session-groups.md, line 98:

<comment>When the same auth object is assigned to two parameter instances, `ClientSessionGroup` shares its mutable OAuth context and tokens. Tell users to construct a distinct auth instance per server before claiming these lifecycles are independent.</comment>

<file context>
@@ -70,6 +70,33 @@ If you already hold a connected `ClientSession` (`Client.session` is one), hand
+    await group.connect_to_server(server_params)
+```
+
+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=`.
+
 ## Recap
</file context>
Suggested change
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=`.
Because `auth` is configured per `ServerParameters` instance, give each server a distinct auth instance to maintain independent authentication context, scopes, and token-refresh lifecycle. Custom headers can still be supplied alongside `auth` via `headers=`.

Expand Down
Loading