Skip to content

Commit ee4b0b3

Browse files
Merge pull request #7468 from continuedev/dallin/sanitize-mcp-names
fix: HOTFIX sanitize mcp names
2 parents 97a0a9f + ded800b commit ee4b0b3

File tree

2 files changed

+58
-2
lines changed

2 files changed

+58
-2
lines changed

core/tools/mcpToolName.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
import { MCPServerStatus, MCPTool } from "..";
2-
32
export function getMCPToolName(server: MCPServerStatus, tool: MCPTool) {
4-
const serverPrefix = server.name.split(" ").join("_").toLowerCase();
3+
// Replace any sequence of non-alphanumeric characters with a single underscore
4+
const serverPrefix = server.name
5+
.toLowerCase()
6+
.replace(/[^a-z0-9]+/g, "_")
7+
.replace(/^_+|_+$/g, "") // Remove leading/trailing underscores
8+
.replace(/_+/g, "_"); // Replace multiple sequential underscores with single underscore
9+
510
if (tool.name.startsWith(serverPrefix)) {
611
return tool.name;
712
}

core/tools/mcpToolName.vitest.ts

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,3 +56,54 @@ test("getMCPToolName - handles mixed case in server names", () => {
5656
const result = getMCPToolName(server, tool);
5757
expect(result).toBe("gitlab_create_merge_request");
5858
});
59+
60+
test("getMCPToolName - handles server names with special characters (parentheses)", () => {
61+
const server = createMcpServer("Linear MCP (SSE)");
62+
const tool = createMCPTool("create_issue");
63+
64+
const result = getMCPToolName(server, tool);
65+
// Should only contain alphanumeric characters and underscores
66+
expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
67+
expect(result).toBe("linear_mcp_sse_create_issue");
68+
});
69+
70+
test("getMCPToolName - handles server names with dots and other special characters", () => {
71+
const server = createMcpServer("My.Server@Test!");
72+
const tool = createMCPTool("test_action");
73+
74+
const result = getMCPToolName(server, tool);
75+
// Should only contain alphanumeric characters and underscores
76+
expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
77+
expect(result).toBe("my_server_test_test_action");
78+
});
79+
80+
test("getMCPToolName - handles server names with multiple consecutive special characters", () => {
81+
const server = createMcpServer("Server@@##Name");
82+
const tool = createMCPTool("action");
83+
84+
const result = getMCPToolName(server, tool);
85+
// Should only contain alphanumeric characters and underscores (no hyphens or multiple underscores)
86+
expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
87+
expect(result).toBe("server_name_action");
88+
});
89+
90+
test("getMCPToolName - handles server names with hyphens", () => {
91+
const server = createMcpServer("My-Server-Name");
92+
const tool = createMCPTool("test_action");
93+
94+
const result = getMCPToolName(server, tool);
95+
// Should only contain alphanumeric characters and underscores
96+
expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
97+
expect(result).toBe("my_server_name_test_action");
98+
});
99+
100+
test("getMCPToolName - handles multiple consecutive underscores in server name", () => {
101+
const server = createMcpServer("Linear__MCP");
102+
const tool = createMCPTool("create_issue");
103+
104+
const result = getMCPToolName(server, tool);
105+
// Should only contain alphanumeric characters and single underscores
106+
expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
107+
expect(result).not.toMatch(/__/);
108+
expect(result).toBe("linear_mcp_create_issue");
109+
});

0 commit comments

Comments
 (0)