Skip to content

MCP tool name parsing breaks when server name contains underscores #2744

@lioryx

Description

@lioryx

Summary

McpPool::parse_prefixed_name in crates/tui/src/mcp.rs uses split_once('_')
to decompose mcp_{server}_{tool} names. When a server name itself contains
underscores — e.g. my_db — the parser splits at the wrong boundary, routing
the call to a non-existent server.

Steps to reproduce

  1. Configure two MCP servers in ~/.codewhale/mcp.json:
{
  "servers": {
    "db":      { "command": "npx", "args": ["-y", "mcp-db-server"] },
    "my_db":   { "command": "npx", "args": ["-y", "mcp-db-server"] }
  }
}
  1. Start codewhale and invoke the tools:
    • mcp_db_execute_sql → works correctly (server=db, tool=execute_sql)
    • mcp_my_db_execute_sql → fails with "MCP server 'my' not available"

Expected behavior

mcp_my_db_execute_sql should route to server my_db, tool execute_sql.

Actual behavior

parse_prefixed_name strips mcp_ then calls split_once('_'), yielding:

Tool name Server (parsed) Tool (parsed) Correct?
mcp_db_execute_sql db execute_sql
mcp_my_db_execute_sql my db_execute_sql

The first _ inside the server name is mistaken for the server/tool delimiter.

Root cause

In crates/tui/src/mcp.rs, line 2248:

let Some((server, tool)) = rest.split_once('_') else { ... };

The naming convention mcp_{server}_{tool} uses a single underscore _ as
both the delimiter and a legal character in sanitized server names. There
is no way for split_once to distinguish the two.

Impact

  • Any MCP server whose name contains _ (e.g. my_db, prod_pg, data_warehouse)
    produces tools that cannot be called.
  • This is a silent failure: the error says "server not available", not "name
    parsed incorrectly".
  • The sibling crates/mcp/src/lib.rs does not have this bug — it uses
    mcp__{server}__{tool} with double-underscore delimiters and
    splitn(2, "__"), which handles embedded underscores correctly.

Affected files

  • crates/tui/src/mcp.rsall_tools (line 2096), parse_prefixed_name
    (line 2243), all_resources, all_resource_templates
  • crates/tui/src/core/engine/dispatch.rsmcp_tool_is_read_only,
    mcp_tool_is_parallel_safe
  • crates/tui/src/core/engine/turn_loop.rs — MCP tool identification

Related

  • crates/mcp/src/lib.rs uses qualify_tool_name / parse_qualified_tool_name
    with mcp__server__tool double-underscore format — no bug there.

Environment

  • OS: Windows 11
  • codewhale version: codewhale 0.8.53 (8dff2f7)
  • Install method: release binary
  • Model/provider: deepseek-v4-pro / deepseek
  • Terminal app: Windows Terminal
  • Shell: PowerShell

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    Status
    Done

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions