Elffuss BraidHub

kikocis/continue public

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