|
3 | 3 | MCPHub.nvim like other MCP clients uses a JSON configuration file to manage MCP servers. This `config` file is located at `~/.config/mcphub/servers.json` by default and supports real-time updates across all Neovim instances. You can set `config` option to a custom location. |
4 | 4 |
|
5 | 5 | > [!NOTE] |
6 | | -> You can use a single config file for any MCP client like VSCode, Cursor, Cline, Zed etc as long as the config file follows the below structure. With MCPHub.nvim, `config` file can be safely added to source control as it allows some special placeholder values in the `env` and `headers` fields on MCP Servers. |
| 6 | +> You can use a single config file for any MCP client like VSCode, Cursor, Cline, Zed etc as long as the config file follows the below structure. With MCPHub.nvim, `config` file can be safely added to source control as it supports **universal `${}` placeholder syntax** for environment variables and command execution across all configuration fields. |
7 | 7 |
|
8 | 8 | ## Manage Servers |
9 | 9 |
|
@@ -53,34 +53,50 @@ The `config` file should have a `mcpServers` key. This contains `stdio` and `rem |
53 | 53 | { |
54 | 54 | "mcpServers": { |
55 | 55 | "local-server": { |
56 | | - "command": "uvx", |
57 | | - "args": ["mcp-server-fetch"] |
| 56 | + "command": "${MCP_BINARY_PATH}/server", |
| 57 | + "args": [ |
| 58 | + "--token", "${API_TOKEN}", |
| 59 | + "--secret", "${cmd: op read op://vault/secret}" |
| 60 | + ], |
| 61 | + "env": { |
| 62 | + "API_TOKEN": "${cmd: aws ssm get-parameter --name /app/token --query Parameter.Value --output text}", |
| 63 | + "DB_URL": "postgresql://user:${DB_PASSWORD}@localhost/myapp", |
| 64 | + "DB_PASSWORD": "password123", |
| 65 | + "FALLBACK_VAR": null |
| 66 | + } |
58 | 67 | } |
59 | 68 | } |
60 | 69 | } |
61 | 70 | ``` |
62 | 71 |
|
63 | 72 | ##### Required fields: |
64 | | -- `command`: The executable to start the server |
| 73 | +- `command`: The executable to start the server (supports `${VARIABLE}` and `${cmd: command}`) |
65 | 74 |
|
66 | 75 | ##### Optional fields: |
67 | | -- `args`: Array of command arguments |
68 | | -- `env`: Optional environment variables |
| 76 | +- `args`: Array of command arguments (supports `${VARIABLE}` and `${cmd: command}` placeholders) |
| 77 | +- `env`: Environment variables with placeholder resolution and system fallback |
69 | 78 | - `dev`: Development mode configuration for auto-restart on file changes |
70 | 79 | - `name`: Display name that will be shown in the UI |
71 | 80 | - `description`: Short description about the server (useful when the server is disabled and `auto_toggle_mcp_servers` is `true`) |
72 | 81 |
|
73 | | -##### `env` Special Values |
| 82 | +##### Universal `${}` Placeholder Syntax |
| 83 | + |
| 84 | +**All fields** support the universal placeholder syntax: |
| 85 | +- **`${ENV_VAR}`** - Resolves environment variables |
| 86 | +- **`${cmd: command args}`** - Executes commands and uses output |
| 87 | +- **`null` or `""`** - Falls back to `process.env` |
74 | 88 |
|
75 | | -The `env` field supports several special values. Given `API_KEY=secret` in the environment: |
| 89 | +Given `API_KEY=secret` in the environment: |
76 | 90 |
|
77 | 91 | | Example | Becomes | Description | |
78 | 92 | |-------|---------|-------------| |
79 | 93 | | `"API_KEY": ""` | `"API_KEY": "secret"` | Empty string falls back to `process.env.API_KEY` | |
80 | | -| `"API_KEY": null` | `"SERVER_URL": "secret"` | `null` falls back to `process.env.API_KEY` | |
81 | | -| `"AUTH": "Bearer ${API_KEY}"` | `"AUTH": "Bearer secret"` | `${}` Placeholder values are also replaced | |
82 | | -| `"TOKEN": "$: cmd:op read op://example/token"` | `"TOKEN": "secret"` | Values starting with `$: ` will be executed as shell command | |
83 | | -| `"HOME": "/home/ubuntu"` | `"HOME": "/home/ubuntu"` | Used as-is | |
| 94 | +| `"API_KEY": null` | `"API_KEY": "secret"` | `null` falls back to `process.env.API_KEY` | |
| 95 | +| `"AUTH": "Bearer ${API_KEY}"` | `"AUTH": "Bearer secret"` | `${}` Placeholder values are replaced | |
| 96 | +| `"TOKEN": "${cmd: op read op://vault/token}"` | `"TOKEN": "secret"` | Commands are executed and output used | |
| 97 | +| `"HOME": "/home/ubuntu"` | `"HOME": "/home/ubuntu"` | Used as-is | |
| 98 | + |
| 99 | +> ⚠️ **Legacy Syntax**: `$VAR` (args) and `$: command` (env) are deprecated but still supported with warnings. Use `${VAR}` and `${cmd: command}` instead. |
84 | 100 |
|
85 | 101 | ##### `dev` Development Mode |
86 | 102 |
|
@@ -136,30 +152,25 @@ MCPHub supports both `streamable-http` and `sse` remote servers. |
136 | 152 | { |
137 | 153 | "mcpServers": { |
138 | 154 | "remote-server": { |
139 | | - "url": "https://api.example.com/mcp", |
| 155 | + "url": "https://${PRIVATE_DOMAIN}/mcp", |
140 | 156 | "headers": { |
141 | | - "Authorization": "Bearer ${API_KEY}" |
| 157 | + "Authorization": "Bearer ${cmd: op read op://vault/api/token}", |
| 158 | + "X-Custom-Header": "${CUSTOM_VALUE}" |
142 | 159 | } |
143 | 160 | } |
144 | 161 | } |
145 | 162 | } |
146 | 163 | ``` |
147 | 164 |
|
148 | 165 | ##### Required fields: |
149 | | -- `url`: Remote server endpoint |
| 166 | +- `url`: Remote server endpoint (supports `${VARIABLE}` and `${cmd: command}` placeholders) |
150 | 167 |
|
151 | 168 | ##### Optional fields: |
152 | | -- `headers`: Optional authentication headers |
| 169 | +- `headers`: Authentication headers (supports `${VARIABLE}` and `${cmd: command}` placeholders) |
153 | 170 | - `name`: Display name that will be shown in the UI |
154 | 171 | - `description`: Short description about the server (useful when the server is disabled and `auto_toggle_mcp_servers` is `true`) |
155 | 172 |
|
156 | | -##### `headers` Special Values |
157 | | - |
158 | | -The `headers` field supports `${...}` Placeholder values. Given `API_KEY=secret` in the environment: |
159 | | - |
160 | | -| Example | Becomes | Description | |
161 | | -|-------|-------------|---------| |
162 | | -| `"Authorization": "Bearer ${API_KEY}"` |`"AUTH": "Bearer secret"` | `${}` Placeholder values are replaced | |
| 173 | +> **Note**: Remote servers use the same universal `${}` placeholder syntax as local servers. See the Universal Placeholder Syntax section above for full details. |
163 | 174 |
|
164 | 175 | ## MCPHub Specific Fields |
165 | 176 |
|
|
0 commit comments