Skip to content

Commit 5dd062d

Browse files
authored
Remove Context.client_id (#3167)
1 parent 0cb920f commit 5dd062d

2 files changed

Lines changed: 21 additions & 11 deletions

File tree

docs/migration.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,27 @@ await ctx.log(level="info", data="hello")
916916

917917
Positional calls (`await ctx.info("hello")`) are unaffected.
918918

919+
### `Context.client_id` removed
920+
921+
`Context.client_id` has been removed. It never returned an authenticated client identity: it echoed a non-standard `client_id` key from the request's `_meta`, which nothing in the SDK or the MCP spec populates, so it was `None` unless a caller injected `meta={"client_id": ...}` by hand. The name also collided with the OAuth `client_id`, which is what callers usually mean by "the client".
922+
923+
If you were reading a custom `_meta` key, read it from the meta dict directly. If you want the authenticated OAuth client, use the access token:
924+
925+
```python
926+
# Before (v1)
927+
client_id = ctx.client_id
928+
929+
# After (v2) — the raw _meta key, if you were setting it yourself
930+
meta = ctx.request_context.meta
931+
client_id = meta.get("client_id") if meta else None
932+
933+
# After (v2) — the authenticated OAuth client (usually what you want)
934+
from mcp.server.auth.middleware.auth_context import get_access_token
935+
936+
token = get_access_token()
937+
client_id = token.client_id if token else None
938+
```
939+
919940
### `ProgressContext` and `progress()` context manager removed
920941

921942
The `mcp.shared.progress` module (`ProgressContext`, `Progress`, and the `progress()` context manager) has been removed. This module had no real-world adoption — all users send progress notifications via `Context.report_progress()` or `session.send_progress_notification()` directly.

src/mcp/server/mcpserver/context.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,6 @@ async def my_tool(x: int, ctx: Context) -> str:
5454
5555
# Get request info
5656
request_id = ctx.request_id
57-
client_id = ctx.client_id
5857
5958
return str(x)
6059
```
@@ -275,16 +274,6 @@ async def log(
275274
related_request_id=self.request_id,
276275
)
277276

278-
# TODO(maxisbey): see if this is needed otherwise remove
279-
@property
280-
def client_id(self) -> str | None:
281-
"""Get the client ID if available.
282-
283-
Note: this reads from the MCP request's `_meta` params, not the OAuth
284-
bearer token. For that, use `get_access_token().client_id`.
285-
"""
286-
return self.request_context.meta.get("client_id") if self.request_context.meta else None # pragma: no cover
287-
288277
@property
289278
def headers(self) -> Mapping[str, str] | None:
290279
"""Request headers carried by this message, when the transport has them.

0 commit comments

Comments
 (0)