Skip to content

Commit 74518fb

Browse files
committed
Add docs
1 parent c9255f4 commit 74518fb

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

docs/patterns/cli.mdx

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,11 @@ This command runs the server directly in your current Python environment. You ar
5353
#### Server Specification
5454
<VersionBadge version="2.3.5" />
5555

56-
The server can be specified in three ways:
56+
The server can be specified in four ways:
5757
1. `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
5858
2. `server.py:custom_name` - imports and uses the specified server object
5959
3. `http://server-url/path` or `https://server-url/path` - connects to a remote server and creates a proxy
60+
4. `mcp.json` - runs servers defined in a standard MCP configuration file
6061

6162
<Tip>
6263
When using `fastmcp run` with a local file, it **ignores** the `if __name__ == "__main__"` block entirely. Instead, it finds your server object and calls its `run()` method directly with the transport options you specify. This means you can use `fastmcp run` to override the transport specified in your code.
@@ -98,6 +99,44 @@ fastmcp run https://example.com/mcp-server
9899
fastmcp run https://example.com/mcp-server --log-level DEBUG
99100
```
100101

102+
#### Running MCP Configuration Files
103+
104+
FastMCP can run servers defined in standard MCP configuration files (typically named `mcp.json`). When you run an mcp.json file, FastMCP creates a proxy server that runs all the servers referenced in the configuration.
105+
106+
**Example mcp.json:**
107+
```json
108+
{
109+
"mcpServers": {
110+
"fetch": {
111+
"command": "uvx",
112+
"args": [
113+
"mcp-server-fetch"
114+
]
115+
},
116+
"filesystem": {
117+
"command": "npx",
118+
"args": [
119+
"-y",
120+
"@modelcontextprotocol/server-filesystem",
121+
"/Users/username/Documents"
122+
]
123+
}
124+
}
125+
}
126+
```
127+
128+
**Run the configuration:**
129+
```bash
130+
# Run with default stdio transport
131+
fastmcp run mcp.json
132+
133+
# Run with HTTP transport on custom port
134+
fastmcp run mcp.json --transport http --port 8080
135+
136+
# Run with SSE transport
137+
fastmcp run mcp.json --transport sse
138+
```
139+
101140
### `dev`
102141

103142
Run a MCP server with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) for testing.

src/fastmcp/mcp_config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def from_file(cls, file_path: Path) -> Self:
270270
if content := file_path.read_text().strip():
271271
return cls.model_validate_json(content)
272272

273-
return cls(mcpServers={})
273+
raise ValueError(f"No MCP servers defined in the config: {file_path}")
274274

275275

276276
class CanonicalMCPConfig(MCPConfig):

0 commit comments

Comments
 (0)