Skip to content

Commit 3f676c6

Browse files
committed
feat: support cwd field for stdio servers (fixes #189)
1 parent 15d4901 commit 3f676c6

5 files changed

Lines changed: 53 additions & 4 deletions

File tree

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [5.11.1] - 2025-07-08
9+
10+
### Added
11+
12+
- **`cwd` field support for stdio servers**:
13+
- Added `cwd` field to `MCPServerConfig` type definition
14+
- Added validation for `cwd` field in server configuration
15+
- Updated documentation with examples and use cases
816

917
## [5.11.0] - 2025-06-26
1018

doc/mcp/servers_json.md

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ The `config` file should have a `mcpServers` key. This contains `stdio` and `rem
6363
"DB_URL": "postgresql://user:${DB_PASSWORD}@localhost/myapp",
6464
"DB_PASSWORD": "password123",
6565
"FALLBACK_VAR": null
66-
}
66+
},
67+
"cwd": "/home/ubuntu/server-dir/"
6768
}
6869
}
6970
}
@@ -75,6 +76,7 @@ The `config` file should have a `mcpServers` key. This contains `stdio` and `rem
7576
##### Optional fields:
7677
- `args`: Array of command arguments (supports `${VARIABLE}` and `${cmd: command}` placeholders)
7778
- `env`: Environment variables with placeholder resolution and system fallback
79+
- `cwd`: The current working directory for the MCP server process (supports `${VARIABLE}` and `${cmd: command}` placeholders)
7880
- `dev`: Development mode configuration for auto-restart on file changes
7981
- `name`: Display name that will be shown in the UI
8082
- `description`: Short description about the server (useful when the server is disabled and `auto_toggle_mcp_servers` is `true`)
@@ -98,6 +100,33 @@ Given `API_KEY=secret` in the environment:
98100

99101
> ⚠️ **Legacy Syntax**: `$VAR` (args) and `$: command` (env) are deprecated but still supported with warnings. Use `${VAR}` and `${cmd: command}` instead.
100102
103+
104+
#### `cwd` Example:
105+
106+
The `cwd` field is particularly useful when your MCP server needs to run in a specific directory context. Here's a practical example:
107+
108+
```json
109+
{
110+
"mcpServers": {
111+
"project-server": {
112+
"command": "npm",
113+
"args": ["start"],
114+
"cwd": "/home/ubuntu/my-mcp-project/",
115+
"env": {
116+
"NODE_ENV": "development"
117+
}
118+
}
119+
}
120+
}
121+
```
122+
123+
**Use cases for `cwd`:**
124+
- When the MCP server needs to access relative files in its project directory
125+
- When using npm/yarn scripts that depend on being in the project root
126+
127+
> **Note**: The top-level `cwd` field sets the working directory for the server process itself, while `dev.cwd` (used in development mode) sets the directory for file watching. These serve different purposes and can be used together.
128+
129+
101130
##### `dev` Development Mode
102131

103132
The `dev` field enables automatic server restarts when files change during development:

lua/mcphub/types.lua

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
---@field command? string
3535
---@field args? table
3636
---@field env? table<string,string>
37+
---@field cwd? string
3738
---@field headers? table<string,string>
3839
---@field url? string
3940

lua/mcphub/utils/validation.lua

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,17 @@ function M.validate_server_config(name, config)
151151
),
152152
}
153153
end
154+
155+
if config.cwd and (type(config.cwd) ~= "string" or config.cwd == "") then
156+
return {
157+
ok = false,
158+
error = Error(
159+
"VALIDATION",
160+
Error.Types.SETUP.INVALID_CONFIG,
161+
string.format("Server '%s' has invalid cwd: must be a non-empty string", name)
162+
),
163+
}
164+
end
154165
elseif has_sse then
155166
-- Validate SSE config
156167
if type(config.url) ~= "string" or config.url == "" then

lua/mcphub/utils/version.lua

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
return {
2-
PLUGIN_VERSION = "5.11.0", -- Current plugin version
2+
PLUGIN_VERSION = "5.11.1", -- Current plugin version
33
REQUIRED_NODE_VERSION = { -- Required mcp-hub version
44
major = 3,
55
minor = 7,
6-
patch = 0,
7-
string = "3.7.0",
6+
patch = 2,
7+
string = "3.7.2",
88
},
99
}

0 commit comments

Comments
 (0)