Skip to content

Conversation

@Kludex
Copy link
Member

@Kludex Kludex commented Feb 3, 2026

Summary

Following the refactoring in #1987 that split RequestContext between server and client, this PR introduces a dedicated ClientRequestContext type alias to improve the developer experience for client-side callback handlers.

Key changes:

  • Added ClientRequestContext type alias in mcp.client.context for cleaner client-side handler signatures
  • Made the internal RequestContext private by moving it to mcp.shared._context
  • Exported ClientRequestContext from mcp.client for convenient access
  • Updated all examples, documentation, and tests to use the new patterns

Before:

from mcp.shared.context import RequestContext
from mcp.client.session import ClientSession

async def handle_sampling(
    context: RequestContext[ClientSession],
    params: CreateMessageRequestParams
) -> CreateMessageResult:
    ...

After:

from mcp.client.context import ClientRequestContext

async def handle_sampling(
    context: ClientRequestContext,
    params: CreateMessageRequestParams
) -> CreateMessageResult:
    ...

Test plan

  • All existing tests pass
  • Ruff linting passes
  • Pyright type checking passes
  • Pre-commit hooks pass

@claude
Copy link

claude bot commented Feb 3, 2026

Code review

No issues found. Checked for bugs and CLAUDE.md compliance.

@Kludex Kludex force-pushed the feat/client-request-context branch from e5b3317 to 96149ca Compare February 3, 2026 15:03
Introduce a dedicated `ClientRequestContext` type alias in
`mcp.client.context` to provide a cleaner API for client-side callback
handlers (sampling, elicitation, list_roots).

This improves the developer experience by:
- Providing a concrete type instead of requiring `RequestContext[ClientSession]`
- Making the internal `RequestContext` private by moving it to `_context.py`
- Exporting `ClientRequestContext` from `mcp.client` for easy access

All examples and conformance tests have been updated to use
`ClientRequestContext` instead of the internal `RequestContext` type.

The migration guide has been updated to reflect these changes.
@Kludex Kludex force-pushed the feat/client-request-context branch from 96149ca to 609585a Compare February 3, 2026 15:06
@Kludex Kludex requested a review from maxisbey February 3, 2026 15:11
@Kludex Kludex merged commit 4fc49c6 into main Feb 3, 2026
30 checks passed
@Kludex Kludex deleted the feat/client-request-context branch February 3, 2026 16:37
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.

3 participants