Skip to content

Conversation

@maxisbey
Copy link
Contributor

Update all test files and example servers to use the new lowlevel Server API pattern where handlers are registered via constructor kwargs instead of decorators.

This is a follow-up to the sketch/lowlevel-server-v2-kwargs branch that converts the core server. This branch fixes all tests and examples.

Key changes:

  • Replace @server.list_tools() etc. decorators with on_list_tools=handler constructor kwargs
  • Update handler signatures to (ctx: ServerRequestContext, params: <ParamsType>)
  • Return full Result types instead of auto-wrapped values
  • Replace server.request_context property with ctx parameter
  • Update experimental task handler registration to use enable_tasks(on_*=...)
  • Remove test_func_inspection.py (corresponding module was deleted)

…args

Replace the decorator-based handler registration on the lowlevel Server with
direct on_* keyword arguments on the constructor. Handlers are raw callables
with a uniform (ctx, params) -> result signature.

- Server constructor takes on_list_tools, on_call_tool, etc.
- String-keyed dispatch instead of type-keyed
- Remove RequestT generic from Server (transport-specific, not bound at construction)
- Delete handler.py and func_inspection.py (no longer needed)
- Update ExperimentalHandlers to use callback-based registration
- Update MCPServer to pass on_* kwargs via _create_handler_kwargs()
- Update migration docs and docstrings
- Fix all migration.md examples to use ServerRequestContext instead of RequestContext
- Fix all imports to use 'from mcp.server import Server, ServerRequestContext'
- Apply ruff formatting to code examples
- Add Server constructor calls to examples that were missing them
- Re-export ServerRequestContext from mcp.server.__init__
- Add type hints to TaskResultHandler docstring example
…erver

Move handler functions from a dict-returning method to private methods
on MCPServer, passed directly to the Server constructor by name. This
eliminates the **kwargs unpacking pattern and makes the handler
registration explicit.
Allow users to override default task handlers by passing on_get_task,
on_task_result, on_list_tasks, and on_cancel_task to enable_tasks().
User-provided handlers are registered first; defaults fill in the rest.
The subscribe capability in ResourcesCapability was hardcoded to False,
even when on_subscribe_resource handler was provided. Now dynamically
checks whether a subscribe handler is registered.

Also applies ruff formatting to experimental.py.
Update all test files and example servers to use the new lowlevel
Server API pattern where handlers are registered via constructor
kwargs (on_list_tools, on_call_tool, etc.) instead of decorators.

Key changes:
- Replace @server.list_tools() etc. with on_list_tools=handler kwargs
- Update handler signatures to (ctx: ServerRequestContext, params)
- Return full Result types instead of auto-wrapped values
- Replace server.request_context with ctx parameter
- Replace server.request_handlers[Type] with server._request_handlers
- Update experimental task handler registration to use enable_tasks()
- Remove test_func_inspection.py (module was deleted in PR)
- Fix test_run_task_flow.py, test_elicitation_scenarios.py, test_tasks.py
- Fix test_ws.py (WebSocket server tests)
- Fix all remaining example servers (simple-tool, simple-prompt,
  simple-resource, simple-pagination, simple-streamablehttp,
  simple-streamablehttp-stateless, sse-polling-demo)
@maxisbey maxisbey force-pushed the sketch/lowlevel-server-v2-kwargs branch from e9df629 to ca8fd2e Compare February 11, 2026 15:16
Base automatically changed from sketch/lowlevel-server-v2-kwargs to main February 12, 2026 15:55
@Kludex
Copy link
Member

Kludex commented Feb 12, 2026

Can we close this?

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.

2 participants