local-mcp-public-facade.integration.test.ts 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import { describe, expect, it } from "vitest";
  2. import { LocalMcpPublicFacade } from "../../../src/service/mcp/tools/public-facade.js";
  3. describe("LocalMcpPublicFacade", () => {
  4. it("filters by name and serializes only the public status projection", async () => {
  5. const facade = new LocalMcpPublicFacade({
  6. inspectProjectMcp: async () => ({
  7. path: "/repo/.mcp.json",
  8. digest: "test",
  9. servers: [],
  10. }),
  11. getSessionMcpServers: () => undefined,
  12. configureSessionServers: async () => undefined,
  13. clearSessionServers: async () => undefined,
  14. listBuiltinPublicServerCapabilities: async () => [],
  15. listPublicServerStatuses: async () => [
  16. {
  17. name: "Search Tools",
  18. enabled: true,
  19. transport: "stdio",
  20. description: "Search automation",
  21. status: "available" as const,
  22. available: true,
  23. },
  24. {
  25. name: "database",
  26. enabled: true,
  27. transport: "http",
  28. status: "error" as const,
  29. available: false,
  30. error:
  31. "MCP server connection failed. Retry or check its configuration.",
  32. },
  33. ],
  34. });
  35. const result = await facade.listLocalMcpServers({ keyword: "SEARCH" });
  36. expect(result.servers).toEqual([
  37. {
  38. name: "Search Tools",
  39. enabled: true,
  40. transport: "stdio",
  41. description: "Search automation",
  42. configJson: '{"status":"available","available":true}',
  43. },
  44. ]);
  45. expect(JSON.stringify(result)).not.toMatch(
  46. /command|url|env|header|token|credential/iu,
  47. );
  48. });
  49. it("returns a source-aware capability catalog and filters Builtin tools without exposing config", async () => {
  50. const facade = new LocalMcpPublicFacade({
  51. inspectProjectMcp: async () => ({
  52. path: "/repo/.mcp.json",
  53. digest: "test",
  54. servers: [],
  55. }),
  56. getSessionMcpServers: () => undefined,
  57. configureSessionServers: async () => undefined,
  58. clearSessionServers: async () => undefined,
  59. listPublicServerStatuses: async () => [
  60. {
  61. name: "database",
  62. enabled: true,
  63. transport: "stdio",
  64. status: "available" as const,
  65. available: true,
  66. },
  67. ],
  68. listBuiltinPublicServerCapabilities: async () => [
  69. {
  70. name: "matrix",
  71. sourceKind: "builtin" as const,
  72. managed: true,
  73. enabled: false,
  74. transport: "stdio" as const,
  75. description: "Built-in Matrix tools",
  76. status: "unavailable" as const,
  77. available: false,
  78. error: "Built-in MCP server is not active in this Runtime.",
  79. tools: [
  80. { name: "web_search", description: "Search the web" },
  81. { name: "image_synthesize", description: "Create an image" },
  82. ],
  83. },
  84. ],
  85. });
  86. const result = await facade.listMcpCapabilities({ keyword: "image" });
  87. expect(result.servers).toEqual([
  88. {
  89. name: "matrix",
  90. sourceKind: "builtin",
  91. managed: true,
  92. enabled: false,
  93. transport: "stdio",
  94. description: "Built-in Matrix tools",
  95. status: "unavailable",
  96. available: false,
  97. error: "Built-in MCP server is not active in this Runtime.",
  98. tools: [{ name: "image_synthesize", description: "Create an image" }],
  99. },
  100. ]);
  101. expect(JSON.stringify(result)).not.toMatch(
  102. /command|url|env|header|token|credential/iu,
  103. );
  104. });
  105. });