-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix: update tests and examples for new on_* constructor kwargs API #2034
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
maxisbey
wants to merge
22
commits into
main
Choose a base branch
from
sketch/lowlevel-server-v2-kwargs-claude
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+3,993
−3,551
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…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)
e9df629 to
ca8fd2e
Compare
Member
|
Can we close this? |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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-kwargsbranch that converts the core server. This branch fixes all tests and examples.Key changes:
@server.list_tools()etc. decorators withon_list_tools=handlerconstructor kwargs(ctx: ServerRequestContext, params: <ParamsType>)server.request_contextproperty withctxparameterenable_tasks(on_*=...)test_func_inspection.py(corresponding module was deleted)