Elffuss BraidHub

kikocis/continue public

Merge pull request #6280 from continuedev/bdougie/mcp-cwd

feat: adds cwd to the MCP yaml as an option.
Changeset846ead6f2eaa52bebf232fd8382b696cad07cbb3f66c18e86762e462be05baba
AuthorNate Sesti <33237525+sestinj@users.noreply.github.com> · 2025-07-07 12:13 -07:00
CommitterGitHub <noreply@github.com> · 2025-07-07 12:13 -07:00
Parents6e8c481b57a5, 2897878f4b65

Browse the files at this changeset

10 files changed

modified core/config/types.ts +2 −0
@@ -1004,6 +1004,8 @@
10041004 type: "stdio";
10051005 command: string;
10061006 args: string[];
1007+ env?: Record<string, string>;
1008+ cwd?: string;
10071009 }
10081010
10091011 interface WebSocketOptions {
modified core/config/yaml/loadYaml.ts +1 −0
@@ -69,6 +69,7 @@
6969 command: server.command,
7070 args: server.args ?? [],
7171 env: server.env,
72+ cwd: server.cwd,
7273 } as any, // TODO: Fix the mcpServers types in config-yaml (discriminated union)
7374 timeout: server.connectionTimeout,
7475 };
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 @@
329329 command,
330330 args,
331331 env,
332+ cwd: options.transport.cwd,
332333 stderr: "pipe",
333334 });
334335
modified core/context/mcp/MCPConnection.vitest.ts +22 −0
@@ -1,6 +1,7 @@
11 import { Client } from "@modelcontextprotocol/sdk/client/index.js";
22 import { beforeEach, describe, expect, it, vi } from "vitest";
33 import MCPConnection from "./MCPConnection";
4+import { StdioOptions } from "../../index.d.js";
45
56 describe("MCPConnection", () => {
67 beforeEach(() => {
@@ -25,6 +26,27 @@
2526 expect(conn.status).toBe("not-connected");
2627 });
2728
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+
2850 it("should create instance with websocket transport", () => {
2951 const options = {
3052 name: "test-mcp",
modified core/index.d.ts +1 −0
@@ -1162,6 +1162,7 @@
11621162 command: string;
11631163 args: string[];
11641164 env?: Record<string, string>;
1165+ cwd?: string;
11651166 requestOptions?: RequestOptions;
11661167 }
11671168
modified docs/docs/customize/deep-dives/mcp.mdx +13 −2
@@ -110,6 +110,7 @@
110110 - `type` (optional): The type of the MCP server: `sse`, `stdio`, `streamable-http`
111111 - `args` (optional): Arguments to pass to the command.
112112 - `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.
113114
114115 ### Transport Types
115116
@@ -132,12 +133,22 @@
132133
133134 ```yaml
134135 mcpServers:
135- - name: Name
136+ - name: SQLite Server
136137 type: stdio
137138 command: npx
138139 args:
139140 - "@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"
141152 ```
142153
143154 #### Streamable HTTP Transport
modified docs/docs/customize/yaml-migration.mdx +1 −0
@@ -288,6 +288,7 @@
288288 - `command` (**required**): The command used to start the server.
289289 - `args`: An optional array of arguments for the command.
290290 - `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.
291292
292293 **Before**
293294
modified docs/docs/reference.mdx +5 −1
@@ -384,6 +384,7 @@
384384 - `command` (**required**): The command used to start the server.
385385 - `args`: An optional array of arguments for the command.
386386 - `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.
387388 - `connectionTimeout`: An optional connection timeout number to the server in milliseconds.
388389
389390 **Example:**
@@ -395,7 +396,10 @@
395396 args:
396397 - mcp-server-sqlite
397398 - --db-path
398- - /Users/NAME/test.db
399+ - ./test.db
400+ cwd: /Users/NAME/project
401+ env:
402+ NODE_ENV: production
399403 ```
400404
401405 ### `data`
modified packages/config-yaml/src/schemas/index.ts +1 −0
@@ -22,6 +22,7 @@
2222 faviconUrl: z.string().optional(),
2323 args: z.array(z.string()).optional(),
2424 env: z.record(z.string()).optional(),
25+ cwd: z.string().optional(),
2526 connectionTimeout: z.number().gt(0).optional(),
2627 requestOptions: requestOptionsSchema.optional(),
2728 });