| 1 | import { |
| 2 | AssistantUnrolledNonNullable, |
| 3 | validateConfigYaml, |
| 4 | } from "@continuedev/config-yaml"; |
| 5 | import { describe, expect, it } from "vitest"; |
| 6 | |
| 7 | describe("MCP Server cwd configuration", () => { |
| 8 | describe("YAML schema validation", () => { |
| 9 | it("should accept valid MCP server with cwd", () => { |
| 10 | const config: AssistantUnrolledNonNullable = { |
| 11 | name: "test-agent", |
| 12 | version: "1.0.0", |
| 13 | mcpServers: [ |
| 14 | { |
| 15 | name: "test-server", |
| 16 | command: "node", |
| 17 | args: ["server.js"], |
| 18 | env: { NODE_ENV: "production" }, |
| 19 | cwd: "/path/to/project", |
| 20 | connectionTimeout: 5000, |
| 21 | }, |
| 22 | ], |
| 23 | }; |
| 24 | |
| 25 | const errors = validateConfigYaml(config); |
| 26 | expect(errors).toHaveLength(0); |
| 27 | }); |
| 28 | |
| 29 | it("should accept MCP server without cwd", () => { |
| 30 | const config: AssistantUnrolledNonNullable = { |
| 31 | name: "test-agent", |
| 32 | version: "1.0.0", |
| 33 | mcpServers: [ |
| 34 | { |
| 35 | name: "test-server", |
| 36 | command: "python", |
| 37 | args: ["-m", "server"], |
| 38 | }, |
| 39 | ], |
| 40 | }; |
| 41 | |
| 42 | const errors = validateConfigYaml(config); |
| 43 | expect(errors).toHaveLength(0); |
| 44 | }); |
| 45 | |
| 46 | it("should accept relative paths in cwd", () => { |
| 47 | const config: AssistantUnrolledNonNullable = { |
| 48 | name: "test-agent", |
| 49 | version: "1.0.0", |
| 50 | mcpServers: [ |
| 51 | { |
| 52 | name: "test-server", |
| 53 | command: "cargo", |
| 54 | args: ["run"], |
| 55 | cwd: "./rust-project", |
| 56 | }, |
| 57 | ], |
| 58 | }; |
| 59 | |
| 60 | const errors = validateConfigYaml(config); |
| 61 | expect(errors).toHaveLength(0); |
| 62 | }); |
| 63 | |
| 64 | it("should accept empty string cwd", () => { |
| 65 | const config: AssistantUnrolledNonNullable = { |
| 66 | name: "test-agent", |
| 67 | version: "1.0.0", |
| 68 | mcpServers: [ |
| 69 | { |
| 70 | name: "test-server", |
| 71 | command: "deno", |
| 72 | args: ["run", "server.ts"], |
| 73 | cwd: "", |
| 74 | }, |
| 75 | ], |
| 76 | }; |
| 77 | |
| 78 | const errors = validateConfigYaml(config); |
| 79 | expect(errors).toHaveLength(0); |
| 80 | }); |
| 81 | }); |
| 82 | |
| 83 | describe("MCP server configuration examples", () => { |
| 84 | it("should support common MCP server patterns with cwd", () => { |
| 85 | const configs = [ |
| 86 | { |
| 87 | name: "Local project MCP server", |
| 88 | server: { |
| 89 | name: "project-mcp", |
| 90 | command: "npm", |
| 91 | args: ["run", "mcp-server"], |
| 92 | cwd: "/Users/developer/my-project", |
| 93 | }, |
| 94 | }, |
| 95 | { |
| 96 | name: "Python MCP with virtual environment", |
| 97 | server: { |
| 98 | name: "python-mcp", |
| 99 | command: "python", |
| 100 | args: ["-m", "my_mcp_server"], |
| 101 | env: { PYTHONPATH: "./src" }, |
| 102 | cwd: "/home/user/python-project", |
| 103 | }, |
| 104 | }, |
| 105 | { |
| 106 | name: "Relative path MCP server", |
| 107 | server: { |
| 108 | name: "relative-mcp", |
| 109 | command: "node", |
| 110 | args: ["index.js"], |
| 111 | cwd: "../mcp-servers/filesystem", |
| 112 | }, |
| 113 | }, |
| 114 | ]; |
| 115 | |
| 116 | configs.forEach(({ name, server }) => { |
| 117 | const config: AssistantUnrolledNonNullable = { |
| 118 | name: "test-agent", |
| 119 | version: "1.0.0", |
| 120 | mcpServers: [server], |
| 121 | }; |
| 122 | |
| 123 | const errors = validateConfigYaml(config); |
| 124 | expect(errors).toHaveLength(0); |
| 125 | }); |
| 126 | }); |
| 127 | }); |
| 128 | }); |