Skip to content

Commit eec3c2b

Browse files
committed
Documentation tweaks
1 parent fbfa594 commit eec3c2b

File tree

1 file changed

+92
-34
lines changed

1 file changed

+92
-34
lines changed

docs/client-configuration.md

Lines changed: 92 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,39 @@
11
# MCP Client Configuration (NEW)
22

3-
This guide covers how to configure MCP servers for client applications,
4-
such as Claude Desktop, Cursor, and VS Code.
3+
This guide, for client application developers, covers a new API for client
4+
configuration. Client applications can use this API to get info about configured
5+
MCP servers from configuration files in a variety of formats and with some
6+
useful, built-in features.
7+
8+
## Loading Configuration Files
9+
10+
```python
11+
from mcp.client.config.mcp_servers_config import MCPServersConfig
12+
13+
# Load JSON
14+
config = MCPServersConfig.from_file("~/.cursor/mcp.json")
15+
config = MCPServersConfig.from_file("~/Library/Application\ Support/Claude/claude_desktop_config.json")
16+
17+
# Load YAML (auto-detected by extension)
18+
config = MCPServersConfig.from_file("~/.cursor/mcp.yaml") # Not yet support in Cursor but maybe soon...?!
19+
config = MCPServersConfig.from_file("~/Library/Application\ Support/Claude/claude_desktop_config.yaml") # Maybe someday...?!
20+
21+
# Load with input substitution
22+
config = MCPServersConfig.from_file(
23+
".vscode/mcp.json",
24+
inputs={"api-key": "secret"}
25+
)
26+
27+
mcp_server = config.servers["time"]
28+
print(mcp_server.command)
29+
print(mcp_server.args)
30+
print(mcp_server.env)
31+
print(mcp_server.headers)
32+
print(mcp_server.inputs)
33+
print(mcp_server.isActive)
34+
print(mcp_server.effective_command)
35+
print(mcp_server.effective_args)
36+
```
537

638
## Configuration File Formats
739

@@ -27,9 +59,10 @@ MCP supports multiple configuration file formats for maximum flexibility.
2759
This is a typical JSON configuration file for an MCP server in that it has
2860
`command` and `args` (as a list) fields.
2961

30-
Also supported is to specify the entire command in the `command` field (easier
31-
to write and read). In this case, the library will automatically split the
32-
command into `command` and `args` fields internally.
62+
Users can also specify the entire command in the `command` field, which
63+
makes it easier to read and write. Internally, the library splits the command
64+
into `command` and `args` fields, so the result is a nicer user experience and
65+
no application code needs to change.
3366

3467
```json
3568
{
@@ -50,7 +83,8 @@ and YAML.
5083

5184
### JSON with Comments (JSONC)
5285

53-
For better maintainability, MCP supports JSON files with `//` comments:
86+
The API supports JSON files with `//` comments (JSONC), which is very commonly
87+
used in the VS Code ecosystem:
5488

5589
```jsonc
5690
{
@@ -70,7 +104,9 @@ For better maintainability, MCP supports JSON files with `//` comments:
70104

71105
### YAML Configuration
72106

73-
YAML configuration files are supported for improved readability:
107+
The API supports YAML configuration files, which offer improved readability,
108+
comments, and the ability to completely sidestep issues with commas, that are
109+
common when working with JSON.
74110

75111
```yaml
76112
mcpServers:
@@ -107,7 +143,8 @@ mcpServers:
107143

108144
### Streamable HTTP Servers
109145

110-
Servers with a `url` field (without SSE keywords) are detected as `streamable_http` type:
146+
Servers with a `url` field (without SSE keywords) are detected as
147+
`streamable_http` type:
111148

112149
```yaml
113150
mcpServers:
@@ -118,7 +155,8 @@ mcpServers:
118155

119156
### SSE Servers
120157

121-
Servers with a `url` field containing "sse" in the URL, name, or description are detected as `sse` type:
158+
Servers with a `url` field containing "sse" in the URL, name, or description are
159+
detected as `sse` type:
122160

123161
```yaml
124162
mcpServers:
@@ -137,7 +175,35 @@ mcpServers:
137175
MCP supports dynamic configuration using input variables, which is a feature
138176
that VS Code supports. This works in both JSON and YAML configurations.
139177

140-
### Defining Inputs
178+
### Declaring Inputs (JSON)
179+
180+
```json
181+
{
182+
"inputs": [
183+
{
184+
"id": "api-key",
185+
"type": "promptString",
186+
"description": "Your API key",
187+
"password": true
188+
},
189+
{
190+
"id": "server-host",
191+
"type": "promptString",
192+
"description": "Server hostname"
193+
}
194+
],
195+
"servers": {
196+
"dynamic-server": {
197+
"url": "https://${input:server-host}/mcp",
198+
"headers": {
199+
"Authorization": "Bearer ${input:api-key}"
200+
}
201+
}
202+
}
203+
}
204+
```
205+
206+
### Declaring Inputs (YAML)
141207

142208
```yaml
143209
inputs:
@@ -149,13 +215,27 @@ inputs:
149215
type: promptString
150216
description: "Server hostname"
151217

152-
mcpServers:
218+
servers:
153219
dynamic-server:
154220
url: https://${input:server-host}/mcp
155221
headers:
156222
Authorization: Bearer ${input:api-key}
157223
```
158224
225+
### Getting DeclaredInputs
226+
227+
The application can use the `inputs` field to get the declared inputs and
228+
prompt the user for the values or otherwise allow them to be specified.
229+
230+
The application gets the declared inputs by doing:
231+
232+
```python
233+
config = MCPServersConfig.from_file(".vscode/mcp.json")
234+
for input in config.inputs:
235+
# Prompt the user for the value
236+
...
237+
```
238+
159239
### Using Inputs
160240

161241
When loading the configuration, provide input values:
@@ -192,7 +272,7 @@ if missing_inputs:
192272

193273
### Server Configuration Base Fields
194274

195-
All server types support these common fields:
275+
All server types support these common optionalfields:
196276

197277
- `name` (string, optional): Display name for the server
198278
- `description` (string, optional): Server description
@@ -254,28 +334,6 @@ servers:
254334
command: python -m server
255335
```
256336

257-
## Loading Configuration Files
258-
259-
```python
260-
from mcp.client.config.mcp_servers_config import MCPServersConfig
261-
from pathlib import Path
262-
263-
# Load JSON
264-
config = MCPServersConfig.from_file("config.json")
265-
266-
# Load YAML (auto-detected by extension)
267-
config = MCPServersConfig.from_file("config.yaml")
268-
269-
# Force YAML parsing
270-
config = MCPServersConfig.from_file("config.json", use_pyyaml=True)
271-
272-
# Load with input substitution
273-
config = MCPServersConfig.from_file(
274-
"config.yaml",
275-
inputs={"api-key": "secret"}
276-
)
277-
```
278-
279337
## Error Handling
280338

281339
### Missing YAML Dependency

0 commit comments

Comments
 (0)