Skip to content

retrieve_tools: annotations/call_with always defaults to call_tool_read due to tool name parsing bug #306

Closed

Description

@Mikhail164th

Bug

handleRetrieveTools in internal/server/mcp.go:851 tries to extract server name from tool name by splitting on ::

parts := strings.SplitN(result.Tool.Name, ":", 2)
if len(parts) == 2 {
    annotations := p.lookupToolAnnotations(parts[0], parts[1])

But result.Tool.Name is just the tool name (e.g. "browser_close_tab"), not "server:tool". The server name is stored separately in result.Tool.ServerName.

Since tool names don't contain :, len(parts) is always 1, so the code falls through to the else branch:

} else {
    mcpTool["call_with"] = contracts.ToolVariantRead // Default to read
}

This means call_with is always "call_tool_read" for every tool, regardless of annotations.

Verified

  • mcpproxy v0.17.5
  • Trace log confirms annotations ARE parsed from upstream ("Tool with annotations from server" for 5 tools with destructiveHint/readOnlyHint)
  • lookupToolAnnotations(serverName, toolName) works correctly when called with proper args
  • DeriveCallWith() works correctly
  • The only break is the SplitN(result.Tool.Name, ":", 2) on line 851

Fix

Replace lines 851-861:

// Before (broken):
parts := strings.SplitN(result.Tool.Name, ":", 2)
if len(parts) == 2 {
    annotations := p.lookupToolAnnotations(parts[0], parts[1])
    ...
} else {
    mcpTool["call_with"] = contracts.ToolVariantRead
}

// After (fixed):
annotations := p.lookupToolAnnotations(result.Tool.ServerName, result.Tool.Name)
if annotations != nil {
    mcpTool["annotations"] = annotations
}
mcpTool["call_with"] = contracts.DeriveCallWith(annotations)

Impact

All tools from all servers get call_with: "call_tool_read" regardless of their annotations. Destructive tools (close, delete, etc.) are not flagged as destructive in retrieve_tools response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions