Skip to content

Conversation

@null-runner
Copy link

Problem

When tool-name-prefix is enabled (or when using explicit prefix in server config), the gateway correctly prefixes tool names for the client (e.g., new_pageserver__new_page).

However, when forwarding the tools/call request to the remote MCP 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".

Root Cause

In handlers.go, the mcpServerToolHandler was using req.Params.Name (the prefixed name from the client request) when calling client.Session().CallTool():

params := &mcp.CallToolParams{
    Name: req.Params.Name,  // Bug: sends "server__new_page" to server that only knows "new_page"
    ...
}

Solution

Pass the original tool name (without prefix) to the handler and use it when forwarding to the remote server:

  1. Add originalToolName parameter to mcpServerToolHandler
  2. Pass tool.Name (original name) when creating the handler in listCapabilities
  3. Use originalToolName instead of req.Params.Name when calling the remote server

Testing

Tested with Chrome DevTools MCP server using custom prefix configuration:

  • Before fix: chromedev__new_page → "Tool new_page not found"
  • After fix: chromedev__new_page → works correctly

Related

This fix is complementary to #263 which changes the prefix separator from : to __. Without this fix, the tool-name-prefix feature doesn't work regardless of which separator is used.

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.
@null-runner
Copy link
Author

Closing for further testing before resubmitting.

@null-runner null-runner closed this Dec 4, 2025
@null-runner null-runner reopened this Dec 4, 2025
null-runner added a commit to null-runner/mcp-gateway that referenced this pull request Dec 4, 2025
The mcp-add command was incorrectly skipping tool activation for Claude
clients based on the assumption that "Claude clients auto-refresh their
tool list". This assumption is incorrect.

When mcp-add is called with activate=true, tools were added to
g.toolRegistrations (accessible via mcp-exec) but NOT to g.mcpServer
(required for native MCP tool calls). This caused:

- mcp-add chromedev → success (26 tools registered)
- mcp-exec chromedev:list_pages → works (uses toolRegistrations)
- native call to chromedev:list_pages → "unknown tool" error

The fix removes the Claude client exclusion, allowing updateServerCapabilities()
to call g.mcpServer.AddTool() for all clients.

Related to docker#278 (tool-name-prefix dispatch fix)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
null-runner added a commit to null-runner/mcp-gateway that referenced this pull request Dec 6, 2025
The mcp-add command was incorrectly skipping tool activation for Claude
clients based on the assumption that "Claude clients auto-refresh their
tool list". This assumption is incorrect.

When mcp-add is called with activate=true, tools were added to
g.toolRegistrations (accessible via mcp-exec) but NOT to g.mcpServer
(required for native MCP tool calls). This caused:

- mcp-add chromedev → success (26 tools registered)
- mcp-exec chromedev:list_pages → works (uses toolRegistrations)
- native call to chromedev:list_pages → "unknown tool" error

The fix removes the Claude client exclusion, allowing updateServerCapabilities()
to call g.mcpServer.AddTool() for all clients.

Related to docker#278 (tool-name-prefix dispatch fix)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant