Title: Public API for runtime handler registration/deregistration on low-level Server · Issue #2135 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: Public API for runtime handler registration/deregistration on low-level Server · Issue #2135 · modelcontextprotocol/python-sdk
X Title: Public API for runtime handler registration/deregistration on low-level Server · Issue #2135 · modelcontextprotocol/python-sdk
Description: Summary The low-level Server class has a private _add_request_handler() method but no public API for adding or removing request/notification handlers at runtime. The only supported way to register handlers is via on_* constructor kwargs,...
Open Graph Description: Summary The low-level Server class has a private _add_request_handler() method but no public API for adding or removing request/notification handlers at runtime. The only supported way to register ...
X Description: Summary The low-level Server class has a private _add_request_handler() method but no public API for adding or removing request/notification handlers at runtime. The only supported way to register ...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/2135
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Public API for runtime handler registration/deregistration on low-level Server","articleBody":"## Summary\n\nThe low-level `Server` class has a private `_add_request_handler()` method but no public API for adding or removing request/notification handlers at runtime. The only supported way to register handlers is via `on_*` constructor kwargs, which means all handlers must be known at construction time.\n\nThis is limiting for frameworks and advanced use cases that need to:\n- Register handlers for protocol extensions or custom methods after server construction\n- Remove or replace handlers dynamically (e.g., feature flags, hot-reloading, test fixtures)\n- Register notification handlers post-construction (currently no mutation API at all for `_notification_handlers`)\n\n### Current state\n\n- [`_add_request_handler()`](https://github.com/modelcontextprotocol/python-sdk/blob/0fe16dd5fddf/src/mcp/server/lowlevel/server.py#L237-L243) exists but is private. It silently replaces existing handlers.\n- [`_has_handler()`](https://github.com/modelcontextprotocol/python-sdk/blob/0fe16dd5fddf/src/mcp/server/lowlevel/server.py#L245-L247) is also private.\n- There is no remove/deregister method for either request or notification handlers.\n- `MCPServer.completion()` already uses `_add_request_handler()` with a `pyright: ignore[reportPrivateUsage]` suppression and a TODO acknowledging this needs a better pattern.\n\n### Proposal\n\nMake handler registration/deregistration a first-class public API on the low-level `Server`:\n\n```python\nserver.add_request_handler(method: str, handler: Callable) -\u003e None\nserver.remove_request_handler(method: str) -\u003e None\nserver.add_notification_handler(method: str, handler: Callable) -\u003e None\nserver.remove_notification_handler(method: str) -\u003e None\nserver.has_handler(method: str) -\u003e bool\n```\n\n### Related issues\n\n- #2105 — Custom method handlers on MCPServer (higher-level, different scope)\n- #1701 — Public API audit\n- #1233 — Middleware support (may interact with handler registration)\n\n\u003csub\u003e[AI Disclaimer](https://gist.github.com/maxisbey/6123d132484e4c533eab519a2800693d)\u003c/sub\u003e","author":{"url":"https://github.com/maxisbey","@type":"Person","name":"maxisbey"},"datePublished":"2026-02-24T13:50:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/2135/python-sdk/issues/2135"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8f6f0106-517a-012b-d4b6-19cfc9739f58 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | CF14:173810:AA98B9:E0F2A6:6A5B000E |
| html-safe-nonce | 43cd00274a4fb48bebd41ccbd62c436777353baf2bbfaed0cb2725862109e556 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDRjE0OjE3MzgxMDpBQTk4Qjk6RTBGMkE2OjZBNUIwMDBFIiwidmlzaXRvcl9pZCI6IjIxODM2NjY2OTYyNTg3ODExOTgiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 7745bbdd7c4ca61a0d1aa4f4929f90e80cd92f6cd347bfc386b61517632199dd |
| hovercard-subject-tag | issue:3983843473 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/2135/issue_layout |
| twitter:image | https://opengraph.githubassets.com/7c8ecd0d66244b997bfb7c5cb959831711a9c1773b8d22729eea287ccbf1b16d/modelcontextprotocol/python-sdk/issues/2135 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/7c8ecd0d66244b997bfb7c5cb959831711a9c1773b8d22729eea287ccbf1b16d/modelcontextprotocol/python-sdk/issues/2135 |
| og:image:alt | Summary The low-level Server class has a private _add_request_handler() method but no public API for adding or removing request/notification handlers at runtime. The only supported way to register ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | maxisbey |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width