Skip to content

Commit 3e02734

Browse files
myk1ytZoo (VP)taltas
authored
fix(mcp): parse tool names with double underscores in server names (Zoo-Code-Org#1737)
* fix(mcp): parse tool names with double underscores in server names normalizeMcpToolName split on every __ or --, but sanitizeMcpName only collapses --, so a legal server name like my__server produced a tool name whose parse misidentified the server and broke all native MCP tool calls for that server. Prefer the canonical -- separator when present, since a raw -- can only be a separator while __ may be part of a legal name. * test(mcp): pin unsupported mixed-separator tool name behavior --------- Co-authored-by: Zoo (VP) <[email protected]> Co-authored-by: T <[email protected]>
1 parent a1cc065 commit 3e02734

2 files changed

Lines changed: 39 additions & 3 deletions

File tree

‎src/utils/__tests__/mcp-name.spec.ts‎

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,13 @@ describe("mcp-name utilities", () => {
239239
})
240240
})
241241

242+
it("should handle server names containing double underscores", () => {
243+
expect(parseMcpToolName("mcp--my__server--do_thing")).toEqual({
244+
serverName: "my__server",
245+
toolName: "do_thing",
246+
})
247+
})
248+
242249
it("should handle tool names with hyphens", () => {
243250
expect(parseMcpToolName("mcp--onellm--atlassian-jira_search")).toEqual({
244251
serverName: "onellm",
@@ -250,6 +257,13 @@ describe("mcp-name utilities", () => {
250257
expect(parseMcpToolName("mcp--")).toBeNull()
251258
expect(parseMcpToolName("mcp--server")).toBeNull()
252259
})
260+
261+
it("should return null for names with mixed separators", () => {
262+
// normalizeMcpToolName picks a single separator for the whole split,
263+
// so mixed-separator names are left unnormalized and cannot be parsed
264+
expect(parseMcpToolName("mcp__server--tool")).toBeNull()
265+
expect(parseMcpToolName("mcp--server__tool")).toBeNull()
266+
})
253267
})
254268

255269
describe("normalizeMcpToolName", () => {
@@ -278,6 +292,17 @@ describe("mcp-name utilities", () => {
278292
// Normalized: mcp--server--get_user_profile
279293
expect(normalizeMcpToolName("mcp__server__get_user_profile")).toBe("mcp--server--get_user_profile")
280294
})
295+
296+
it("should preserve double underscores in server names", () => {
297+
expect(normalizeMcpToolName("mcp--my__server--do_thing")).toBe("mcp--my__server--do_thing")
298+
})
299+
300+
it("should return names with mixed separators unchanged (unsupported)", () => {
301+
// A single separator style is chosen for the entire split, so names
302+
// mixing "--" and "__" separators cannot be normalized
303+
expect(normalizeMcpToolName("mcp__server--tool")).toBe("mcp__server--tool")
304+
expect(normalizeMcpToolName("mcp--server__tool")).toBe("mcp--server__tool")
305+
})
281306
})
282307

283308
describe("roundtrip behavior", () => {
@@ -338,6 +363,17 @@ describe("mcp-name utilities", () => {
338363
toolName: "get-user-profile",
339364
})
340365
})
366+
367+
it("should roundtrip server names containing double underscores", () => {
368+
const toolName = buildMcpToolName("my__server", "do_thing")
369+
expect(toolName).toBe("mcp--my__server--do_thing")
370+
371+
const parsed = parseMcpToolName(toolName)
372+
expect(parsed).toEqual({
373+
serverName: "my__server",
374+
toolName: "do_thing",
375+
})
376+
})
341377
})
342378

343379
describe("model compatibility - full flow", () => {

‎src/utils/mcp-name.ts‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@ export function normalizeMcpToolName(toolName: string): string {
5050
// Find the pattern: mcp{sep}server{sep}tool where sep is -- or __
5151
// We need to convert the separators while preserving the rest
5252

53-
// First, try to parse assuming all separators are underscores
54-
// Pattern: mcp__server__tool or mcp__server__tool_with_underscores
55-
const parts = toolName.split(/__|--/)
53+
// Prefer the canonical separator when present: a raw "--" can only be a
54+
// separator, while "__" may be part of a legal server or tool name
55+
const parts = toolName.includes(MCP_TOOL_SEPARATOR) ? toolName.split(MCP_TOOL_SEPARATOR) : toolName.split("__")
5656

5757
if (parts.length >= 3 && parts[0].toLowerCase() === "mcp") {
5858
// Reconstruct with proper -- separators

0 commit comments

Comments
 (0)