Remove Context.client_id

Merged
MA
4mo ago
+21-11

Removes the Context.client_id property. 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 people usually mean by "the client" — see #373 for the recurring confusion.

Motivation and Context

A leftover from the original FastMCP integration. It carried a # pragma: no cover because it had never been exercised, and a TODO to see if it was needed. It isn't: the meta path is reachable via ctx.request_context.meta.get("client_id"), and the authenticated client is get_access_token().client_id.

How Has This Been Tested?

Existing suite; the removed line was the only untested one in the property. docs/migration.md gains a section with both replacements.

Breaking Changes

Yes — ctx.client_id now raises AttributeError. Migration entry added under the MCPServer Context section:

  • raw _meta key: meta = ctx.request_context.meta; meta.get("client_id") if meta else None
  • authenticated OAuth client: get_access_token().client_id

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

AI Disclaimer