Skip to content

Commit 68410ba

Browse files
committed
fix: forward original tool name to remote MCP servers
When tool-name-prefix is enabled, the gateway prefixes tool names (e.g., 'new_page' becomes 'server__new_page'). However, when forwarding the call to the remote server, the prefixed name was being sent instead of the original name. The remote server doesn't know about gateway prefixes and fails with 'tool not found'. This fix: 1. Adds originalToolName parameter to mcpServerToolHandler 2. Passes the original tool.Name when creating handlers 3. Uses originalToolName when calling the remote server Tested with custom MCP servers using explicit prefix configuration.
1 parent 94b4ea8 commit 68410ba

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

pkg/gateway/capabilitites.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ func (g *Gateway) listCapabilities(ctx context.Context, serverNames []string, cl
159159
capabilities.Tools = append(capabilities.Tools, ToolRegistration{
160160
ServerName: serverConfig.Name,
161161
Tool: &prefixedTool,
162-
Handler: g.mcpServerToolHandler(serverConfig.Name, g.mcpServer, tool.Annotations),
162+
Handler: g.mcpServerToolHandler(serverConfig.Name, g.mcpServer, tool.Annotations, tool.Name),
163163
})
164164
}
165165
}

pkg/gateway/handlers.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func (g *Gateway) mcpToolHandler(tool catalog.Tool) mcp.ToolHandler {
5757
}
5858
}
5959

60-
func (g *Gateway) mcpServerToolHandler(serverName string, server *mcp.Server, annotations *mcp.ToolAnnotations) mcp.ToolHandler {
60+
func (g *Gateway) mcpServerToolHandler(serverName string, server *mcp.Server, annotations *mcp.ToolAnnotations, originalToolName string) mcp.ToolHandler {
6161
return func(ctx context.Context, req *mcp.CallToolRequest) (*mcp.CallToolResult, error) {
6262
// Look up server configuration
6363
serverConfig, _, ok := g.configuration.Find(serverName)
@@ -128,7 +128,7 @@ func (g *Gateway) mcpServerToolHandler(serverName string, server *mcp.Server, an
128128
}
129129
params := &mcp.CallToolParams{
130130
Meta: req.Params.Meta,
131-
Name: req.Params.Name,
131+
Name: originalToolName,
132132
Arguments: args,
133133
}
134134

0 commit comments

Comments
 (0)