|
| 1 | +import * as fs from "fs/promises"; |
| 2 | +import * as path from "path"; |
| 3 | +import { shouldRunIntegrationTests, cleanupTestEnvironment, createTestEnvironment } from "./setup"; |
| 4 | +import { createTempGitRepo, cleanupTempGitRepo, resolveOrpcClient } from "./helpers"; |
| 5 | + |
| 6 | +const describeIntegration = shouldRunIntegrationTests() ? describe : describe.skip; |
| 7 | + |
| 8 | +describeIntegration("MCP project configuration", () => { |
| 9 | + test.concurrent("add, list, and remove MCP servers", async () => { |
| 10 | + const env = await createTestEnvironment(); |
| 11 | + const repoPath = await createTempGitRepo(); |
| 12 | + const client = resolveOrpcClient(env); |
| 13 | + |
| 14 | + try { |
| 15 | + // Register project |
| 16 | + const createResult = await client.projects.create({ projectPath: repoPath }); |
| 17 | + expect(createResult.success).toBe(true); |
| 18 | + |
| 19 | + // Initially empty |
| 20 | + const initial = await client.projects.mcp.list({ projectPath: repoPath }); |
| 21 | + expect(initial).toEqual({}); |
| 22 | + |
| 23 | + // Add server |
| 24 | + const addResult = await client.projects.mcp.add({ |
| 25 | + projectPath: repoPath, |
| 26 | + name: "chrome-devtools", |
| 27 | + command: "npx chrome-devtools-mcp@latest", |
| 28 | + }); |
| 29 | + expect(addResult.success).toBe(true); |
| 30 | + |
| 31 | + // Should list the added server |
| 32 | + const listed = await client.projects.mcp.list({ projectPath: repoPath }); |
| 33 | + expect(listed).toEqual({ "chrome-devtools": "npx chrome-devtools-mcp@latest" }); |
| 34 | + |
| 35 | + // Config file should be written |
| 36 | + const configPath = path.join(repoPath, ".mux", "mcp.jsonc"); |
| 37 | + const file = await fs.readFile(configPath, "utf-8"); |
| 38 | + expect(JSON.parse(file)).toEqual({ |
| 39 | + servers: { "chrome-devtools": "npx chrome-devtools-mcp@latest" }, |
| 40 | + }); |
| 41 | + |
| 42 | + // Remove server |
| 43 | + const removeResult = await client.projects.mcp.remove({ |
| 44 | + projectPath: repoPath, |
| 45 | + name: "chrome-devtools", |
| 46 | + }); |
| 47 | + expect(removeResult.success).toBe(true); |
| 48 | + |
| 49 | + const finalList = await client.projects.mcp.list({ projectPath: repoPath }); |
| 50 | + expect(finalList).toEqual({}); |
| 51 | + } finally { |
| 52 | + await cleanupTestEnvironment(env); |
| 53 | + await cleanupTempGitRepo(repoPath); |
| 54 | + } |
| 55 | + }); |
| 56 | +}); |
0 commit comments