Is your feature request related to a problem? Please describe.
The current mcp integration appears to expose a single fixed MCP server instance behind one endpoint.
This makes a few use cases difficult or impossible to support cleanly:
- exposing different tool lists on different MCP routes, for example:
/mcp/a -> tool set A
/mcp/b -> tool set B
/mcp/:tenant -> tenant-specific tool set
- using official go-sdk server hooks / middleware / options from the go-zero wrapper
- leveraging official go-sdk runtime registry capabilities such as
AddTool, RemoveTools, and the corresponding tools/list_changed flow in a straightforward way
From reading the current implementation, the HTTP handler callback always returns the same underlying SDK server instance, so request/path-based MCP server selection is not currently supported by the wrapper.
Describe the solution you'd like
I would like to propose an opt-in, backward-compatible extension for the mcp package.
A possible direction:
-
Keep current behavior unchanged by default
NewMcpServer(c) should continue to work exactly as it does today
-
Expose the underlying official SDK server
- for example via
Server() or Unwrap()
- this would allow users to directly use official go-sdk capabilities such as:
- runtime
AddTool
RemoveTools
- prompts/resources registration
- receiving/sending middleware
- server options / hooks
-
Add an optional request-based server selector (or MCP mux)
- for example, an option that allows selecting the target
*sdkmcp.Server from *http.Request
- this would make it possible to support route-based MCP server collections, such as:
- one go-zero REST server
- multiple MCP endpoints
- each endpoint mapped to a different MCP server instance
-
Prefer hooks/options over breaking API changes
- if hooks/options are added, they should be opt-in only
- existing users should not need to change any code
This would make the wrapper more flexible while preserving compatibility.
Describe alternatives you've considered
-
Running a separate MCP server for each scenario
- this can work as a workaround, but it increases operational complexity
- depending on deployment style, it may require additional processes, separate endpoints, or extra routing/port management
- it is not ideal when the goal is to expose multiple MCP server variants from a single go-zero service in a structured way
-
Wrapping every official SDK API individually
- possible, but likely harder to maintain over time as the upstream SDK evolves
-
Intercepting tools/list in a single fixed server
- possible in theory, but less clean than request-based server selection
- the core requirement here seems to be routing / server selection rather than only middleware interception
-
Using only one MCP server and registering everything up front
- this works for simple cases, but does not help when different routes or tenants need different tool sets
Additional context
This request is mainly about enabling advanced MCP integration in a backward-compatible way, especially:
- official SDK hooks / middleware exposure
- runtime tool registry changes (
AddTool / RemoveTools)
- route-based MCP server selection / MCP server collection
If this direction sounds acceptable to maintainers, I’d be happy to prepare a PR following the preferred API shape and compatibility requirements.
Is your feature request related to a problem? Please describe.
The current
mcpintegration appears to expose a single fixed MCP server instance behind one endpoint.This makes a few use cases difficult or impossible to support cleanly:
/mcp/a-> tool set A/mcp/b-> tool set B/mcp/:tenant-> tenant-specific tool setAddTool,RemoveTools, and the correspondingtools/list_changedflow in a straightforward wayFrom reading the current implementation, the HTTP handler callback always returns the same underlying SDK server instance, so request/path-based MCP server selection is not currently supported by the wrapper.
Describe the solution you'd like
I would like to propose an opt-in, backward-compatible extension for the
mcppackage.A possible direction:
Keep current behavior unchanged by default
NewMcpServer(c)should continue to work exactly as it does todayExpose the underlying official SDK server
Server()orUnwrap()AddToolRemoveToolsAdd an optional request-based server selector (or MCP mux)
*sdkmcp.Serverfrom*http.RequestPrefer hooks/options over breaking API changes
This would make the wrapper more flexible while preserving compatibility.
Describe alternatives you've considered
Running a separate MCP server for each scenario
Wrapping every official SDK API individually
Intercepting
tools/listin a single fixed serverUsing only one MCP server and registering everything up front
Additional context
This request is mainly about enabling advanced MCP integration in a backward-compatible way, especially:
AddTool/RemoveTools)If this direction sounds acceptable to maintainers, I’d be happy to prepare a PR following the preferred API shape and compatibility requirements.