| 1 | import { expect, test } from "vitest"; |
| 2 | import { MCPServerStatus, MCPTool } from ".."; |
| 3 | import { getMCPToolName } from "./mcpToolName"; |
| 4 | |
| 5 | const 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 | |
| 21 | const createMCPTool = (name: string): MCPTool => ({ |
| 22 | name, |
| 23 | inputSchema: { |
| 24 | type: "object", |
| 25 | }, |
| 26 | }); |
| 27 | |
| 28 | test("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 | |
| 36 | test("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 | |
| 44 | test("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 | |
| 52 | test("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 | }); |