Changesets · Branches · Tags · Compare
| Changeset | 846ead6f2eaa52bebf232fd8382b696cad07cbb3f66c18e86762e462be05baba |
|---|---|
| Author | Nate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-07 12:13 -07:00 |
| Committer | GitHub <noreply@github.com> · 2025-07-07 12:13 -07:00 |
| Parents | 6e8c481b57a5, 2897878f4b65 |
10 files changed
modified core/config/types.ts +2 −0
| @@ -1004,6 +1004,8 @@ | ||
| 1004 | 1004 | type: "stdio"; |
| 1005 | 1005 | command: string; |
| 1006 | 1006 | args: string[]; |
| 1007 | + env?: Record<string, string>; | |
| 1008 | + cwd?: string; | |
| 1007 | 1009 | } |
| 1008 | 1010 | |
| 1009 | 1011 | interface WebSocketOptions { |
modified core/config/yaml/loadYaml.ts +1 −0
| @@ -69,6 +69,7 @@ | ||
| 69 | 69 | command: server.command, |
| 70 | 70 | args: server.args ?? [], |
| 71 | 71 | env: server.env, |
| 72 | + cwd: server.cwd, | |
| 72 | 73 | } as any, // TODO: Fix the mcpServers types in config-yaml (discriminated union) |
| 73 | 74 | timeout: server.connectionTimeout, |
| 74 | 75 | }; |
added core/config/yaml/loadYaml.vitest.ts +128 −0
| @@ -0,0 +1,128 @@ | ||
| 1 | +import { describe, it, expect } from "vitest"; | |
| 2 | +import { | |
| 3 | + validateConfigYaml, | |
| 4 | + AssistantUnrolledNonNullable, | |
| 5 | +} from "@continuedev/config-yaml"; | |
| 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-assistant", | |
| 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-assistant", | |
| 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-assistant", | |
| 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-assistant", | |
| 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-assistant", | |
| 119 | + version: "1.0.0", | |
| 120 | + mcpServers: [server], | |
| 121 | + }; | |
| 122 | + | |
| 123 | + const errors = validateConfigYaml(config); | |
| 124 | + expect(errors).toHaveLength(0); | |
| 125 | + }); | |
| 126 | + }); | |
| 127 | + }); | |
| 128 | +}); |
modified core/context/mcp/MCPConnection.ts +1 −0
| @@ -329,6 +329,7 @@ | ||
| 329 | 329 | command, |
| 330 | 330 | args, |
| 331 | 331 | env, |
| 332 | + cwd: options.transport.cwd, | |
| 332 | 333 | stderr: "pipe", |
| 333 | 334 | }); |
| 334 | 335 |
modified core/context/mcp/MCPConnection.vitest.ts +22 −0
| @@ -1,6 +1,7 @@ | ||
| 1 | 1 | import { Client } from "@modelcontextprotocol/sdk/client/index.js"; |
| 2 | 2 | import { beforeEach, describe, expect, it, vi } from "vitest"; |
| 3 | 3 | import MCPConnection from "./MCPConnection"; |
| 4 | +import { StdioOptions } from "../../index.d.js"; | |
| 4 | 5 | |
| 5 | 6 | describe("MCPConnection", () => { |
| 6 | 7 | beforeEach(() => { |
| @@ -25,6 +26,27 @@ | ||
| 25 | 26 | expect(conn.status).toBe("not-connected"); |
| 26 | 27 | }); |
| 27 | 28 | |
| 29 | + it("should create instance with stdio transport including cwd", () => { | |
| 30 | + const options = { | |
| 31 | + name: "test-mcp", | |
| 32 | + id: "test-id", | |
| 33 | + transport: { | |
| 34 | + type: "stdio" as const, | |
| 35 | + command: "test-cmd", | |
| 36 | + args: ["--test"], | |
| 37 | + env: { TEST: "true" }, | |
| 38 | + cwd: "/path/to/working/directory", | |
| 39 | + }, | |
| 40 | + }; | |
| 41 | + | |
| 42 | + const conn = new MCPConnection(options); | |
| 43 | + expect(conn).toBeInstanceOf(MCPConnection); | |
| 44 | + expect(conn.status).toBe("not-connected"); | |
| 45 | + if (conn.options.transport.type === "stdio") { | |
| 46 | + expect(conn.options.transport.cwd).toBe("/path/to/working/directory"); | |
| 47 | + } | |
| 48 | + }); | |
| 49 | + | |
| 28 | 50 | it("should create instance with websocket transport", () => { |
| 29 | 51 | const options = { |
| 30 | 52 | name: "test-mcp", |
modified core/index.d.ts +1 −0
| @@ -1162,6 +1162,7 @@ | ||
| 1162 | 1162 | command: string; |
| 1163 | 1163 | args: string[]; |
| 1164 | 1164 | env?: Record<string, string>; |
| 1165 | + cwd?: string; | |
| 1165 | 1166 | requestOptions?: RequestOptions; |
| 1166 | 1167 | } |
| 1167 | 1168 |
modified docs/docs/customize/deep-dives/mcp.mdx +13 −2
| @@ -110,6 +110,7 @@ | ||
| 110 | 110 | - `type` (optional): The type of the MCP server: `sse`, `stdio`, `streamable-http` |
| 111 | 111 | - `args` (optional): Arguments to pass to the command. |
| 112 | 112 | - `env` (optional): Secrets to be injected into the command as environment variables. |
| 113 | +- `cwd` (optional): Working directory to run the command in. Can be absolute or relative path. | |
| 113 | 114 | |
| 114 | 115 | ### Transport Types |
| 115 | 116 | |
| @@ -132,12 +133,22 @@ | ||
| 132 | 133 | |
| 133 | 134 | ```yaml |
| 134 | 135 | mcpServers: |
| 135 | - - name: Name | |
| 136 | + - name: SQLite Server | |
| 136 | 137 | type: stdio |
| 137 | 138 | command: npx |
| 138 | 139 | args: |
| 139 | 140 | - "@modelcontextprotocol/server-sqlite" |
| 140 | - - "/path/to/your/database.db" | |
| 141 | + - "./database.db" | |
| 142 | + cwd: "/path/to/project" | |
| 143 | + | |
| 144 | + - name: Local Project Server | |
| 145 | + command: npm | |
| 146 | + args: | |
| 147 | + - "run" | |
| 148 | + - "mcp-server" | |
| 149 | + cwd: "./my-project" | |
| 150 | + env: | |
| 151 | + NODE_ENV: "production" | |
| 141 | 152 | ``` |
| 142 | 153 | |
| 143 | 154 | #### Streamable HTTP Transport |
modified docs/docs/customize/yaml-migration.mdx +1 −0
| @@ -288,6 +288,7 @@ | ||
| 288 | 288 | - `command` (**required**): The command used to start the server. |
| 289 | 289 | - `args`: An optional array of arguments for the command. |
| 290 | 290 | - `env`: An optional map of environment variables for the server process. |
| 291 | +- `cwd`: An optional working directory to run the command in. Can be absolute or relative path. | |
| 291 | 292 | |
| 292 | 293 | **Before** |
| 293 | 294 |
modified docs/docs/reference.mdx +5 −1
| @@ -384,6 +384,7 @@ | ||
| 384 | 384 | - `command` (**required**): The command used to start the server. |
| 385 | 385 | - `args`: An optional array of arguments for the command. |
| 386 | 386 | - `env`: An optional map of environment variables for the server process. |
| 387 | +- `cwd`: An optional working directory to run the command in. Can be absolute or relative path. | |
| 387 | 388 | - `connectionTimeout`: An optional connection timeout number to the server in milliseconds. |
| 388 | 389 | |
| 389 | 390 | **Example:** |
| @@ -395,7 +396,10 @@ | ||
| 395 | 396 | args: |
| 396 | 397 | - mcp-server-sqlite |
| 397 | 398 | - --db-path |
| 398 | - - /Users/NAME/test.db | |
| 399 | + - ./test.db | |
| 400 | + cwd: /Users/NAME/project | |
| 401 | + env: | |
| 402 | + NODE_ENV: production | |
| 399 | 403 | ``` |
| 400 | 404 | |
| 401 | 405 | ### `data` |
modified packages/config-yaml/src/schemas/index.ts +1 −0
| @@ -22,6 +22,7 @@ | ||
| 22 | 22 | faviconUrl: z.string().optional(), |
| 23 | 23 | args: z.array(z.string()).optional(), |
| 24 | 24 | env: z.record(z.string()).optional(), |
| 25 | + cwd: z.string().optional(), | |
| 25 | 26 | connectionTimeout: z.number().gt(0).optional(), |
| 26 | 27 | requestOptions: requestOptionsSchema.optional(), |
| 27 | 28 | }); |