Elffuss BraidHub

kikocis/continue public

9c134d8c1202 · 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 prompts: [],
9 tools: [],
10 resources: [],
11 resourceTemplates: [],
12 status: "connected",
13 id: "",
14 transport: {
15 type: "sse",
16 url: "",
17 },
18 isProtectedResource: false,
19});
20
21const createMCPTool = (name: string): MCPTool => ({
22 name,
23 inputSchema: {
24 type: "object",
25 },
26});
27
28test("getMCPToolName - adds server prefix to tool name when not present", () => {
29 const server = createMcpServer("Github");
30 const tool = createMCPTool("create_pull_request");
31
32 const result = getMCPToolName(server, tool);
33 expect(result).toBe("github_create_pull_request");
34});
35
36test("getMCPToolName - preserves tool name when it already starts with server prefix", () => {
37 const server = createMcpServer("Github");
38 const tool = createMCPTool("github_create_pull_request");
39
40 const result = getMCPToolName(server, tool);
41 expect(result).toBe("github_create_pull_request");
42});
43
44test("getMCPToolName - handles server names with spaces", () => {
45 const server = createMcpServer("Azure DevOps");
46 const tool = createMCPTool("create_pipeline");
47
48 const result = getMCPToolName(server, tool);
49 expect(result).toBe("azure_devops_create_pipeline");
50});
51
52test("getMCPToolName - handles mixed case in server names", () => {
53 const server = createMcpServer("GitLab");
54 const tool = createMCPTool("create_merge_request");
55
56 const result = getMCPToolName(server, tool);
57 expect(result).toBe("gitlab_create_merge_request");
58});
59
60test("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
70test("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
80test("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
90test("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
100test("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});