Feature Request: Add ability to unregister/deregister tools at runtime in TypeScript SDK
Opened this issue · 2 comments
I'm building an MCP server in TypeScript using @modelcontextprotocol/sdk.
I can dynamically register tools using registerTool(), but there is no documented way to unregister/deregister tools at runtime.
This is problematic for scenarios where:
- Tools are user/session-specific and need to be removed when a user disconnects.
- Tools are loaded from a database and must be refreshed dynamically.
- We want to implement plugin-like behavior with hot-swapping tools.
A method like unregisterTool(name: string) that removes a previously registered tool from the server's active registry.
- Maintaining my own registry and filtering calls manually, but this feels like duplicating what the SDK should already manage.
- Restarting the server when tool sets change (not ideal for production).
Additional context
This feature would allow more flexible, real-time management of tools in MCP servers.
Is this something planned, or would you accept a PR implementing it?
typescript-sdk/src/server/mcp.ts
Line 1180 in 3bc2235
typescript-sdk/src/server/mcp.ts
Line 789 in 3bc2235
Looks like you can maintain your own list of tool instances from registerTool and remove it directly.
e.g.
const tool = server.registerTool(...)
// Later on
tool.remove()This is also shown here: https://github.com/modelcontextprotocol/typescript-sdk?tab=readme-ov-file#dynamic-servers
You could alternatively construct a new "server" for each session if tool availability is unique per authentication context, and if you were doing it this way, would go direct to the request schemas and use the low level server so you can construct the list each time it is requested.
https://github.com/modelcontextprotocol/typescript-sdk?tab=readme-ov-file#low-level-server
Thanks a lot for pointing this out!
Let me try this out.
Appreciate the detailed explanation and links! 🙌