Elffuss BraidHub

kikocis/continue public

3ff29c567dd0 · 3.6 KiBRawPermalink
1import { expect, test } from "vitest";
2import { MCPServerStatus, MCPTool } from "..";
3import { getMCPToolName } from "./mcpToolName";
4
5const createMcpServer = (name: string): MCPServerStatus => ({
6 name,
7 errors: [],
8 infos: [],
9 prompts: [],
10 tools: [],
11 resources: [],
12 resourceTemplates: [],
13 status: "connected",
14 id: "",
15 transport: {
16 type: "sse",
17 url: "",
18 },
19 isProtectedResource: false,
20});
21
22const createMCPTool = (name: string): MCPTool => ({
23 name,
24 inputSchema: {
25 type: "object",
26 },
27});
28
29test("getMCPToolName - adds server prefix to tool name when not present", () => {
30 const server = createMcpServer("Github");
31 const tool = createMCPTool("create_pull_request");
32
33 const result = getMCPToolName(server, tool);
34 expect(result).toBe("github_create_pull_request");
35});
36
37test("getMCPToolName - preserves tool name when it already starts with server prefix", () => {
38 const server = createMcpServer("Github");
39 const tool = createMCPTool("github_create_pull_request");
40
41 const result = getMCPToolName(server, tool);
42 expect(result).toBe("github_create_pull_request");
43});
44
45test("getMCPToolName - handles server names with spaces", () => {
46 const server = createMcpServer("Azure DevOps");
47 const tool = createMCPTool("create_pipeline");
48
49 const result = getMCPToolName(server, tool);
50 expect(result).toBe("azure_devops_create_pipeline");
51});
52
53test("getMCPToolName - handles mixed case in server names", () => {
54 const server = createMcpServer("GitLab");
55 const tool = createMCPTool("create_merge_request");
56
57 const result = getMCPToolName(server, tool);
58 expect(result).toBe("gitlab_create_merge_request");
59});
60
61test("getMCPToolName - handles server names with special characters (parentheses)", () => {
62 const server = createMcpServer("Linear MCP (SSE)");
63 const tool = createMCPTool("create_issue");
64
65 const result = getMCPToolName(server, tool);
66 // Should only contain alphanumeric characters and underscores
67 expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
68 expect(result).toBe("linear_mcp_sse_create_issue");
69});
70
71test("getMCPToolName - handles server names with dots and other special characters", () => {
72 const server = createMcpServer("My.Server@Test!");
73 const tool = createMCPTool("test_action");
74
75 const result = getMCPToolName(server, tool);
76 // Should only contain alphanumeric characters and underscores
77 expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
78 expect(result).toBe("my_server_test_test_action");
79});
80
81test("getMCPToolName - handles server names with multiple consecutive special characters", () => {
82 const server = createMcpServer("Server@@##Name");
83 const tool = createMCPTool("action");
84
85 const result = getMCPToolName(server, tool);
86 // Should only contain alphanumeric characters and underscores (no hyphens or multiple underscores)
87 expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
88 expect(result).toBe("server_name_action");
89});
90
91test("getMCPToolName - handles server names with hyphens", () => {
92 const server = createMcpServer("My-Server-Name");
93 const tool = createMCPTool("test_action");
94
95 const result = getMCPToolName(server, tool);
96 // Should only contain alphanumeric characters and underscores
97 expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
98 expect(result).toBe("my_server_name_test_action");
99});
100
101test("getMCPToolName - handles multiple consecutive underscores in server name", () => {
102 const server = createMcpServer("Linear__MCP");
103 const tool = createMCPTool("create_issue");
104
105 const result = getMCPToolName(server, tool);
106 // Should only contain alphanumeric characters and single underscores
107 expect(result).toMatch(/^[a-zA-Z0-9_]+$/);
108 expect(result).not.toMatch(/__/);
109 expect(result).toBe("linear_mcp_create_issue");
110});