Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
67965fd
1
Parent(s): b90e63c
Add docs
Browse files- docs/patterns/cli.mdx +40 -1
- src/fastmcp/mcp_config.py +1 -1
docs/patterns/cli.mdx
CHANGED
|
@@ -53,10 +53,11 @@ This command runs the server directly in your current Python environment. You ar
|
|
| 53 |
#### Server Specification
|
| 54 |
<VersionBadge version="2.3.5" />
|
| 55 |
|
| 56 |
-
The server can be specified in
|
| 57 |
1. `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
|
| 58 |
2. `server.py:custom_name` - imports and uses the specified server object
|
| 59 |
3. `http://server-url/path` or `https://server-url/path` - connects to a remote server and creates a proxy
|
|
|
|
| 60 |
|
| 61 |
<Tip>
|
| 62 |
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
|
|
| 98 |
fastmcp run https://example.com/mcp-server --log-level DEBUG
|
| 99 |
```
|
| 100 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 101 |
### `dev`
|
| 102 |
|
| 103 |
Run a MCP server with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) for testing.
|
|
|
|
| 53 |
#### Server Specification
|
| 54 |
<VersionBadge version="2.3.5" />
|
| 55 |
|
| 56 |
+
The server can be specified in four ways:
|
| 57 |
1. `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
|
| 58 |
2. `server.py:custom_name` - imports and uses the specified server object
|
| 59 |
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
|
| 61 |
|
| 62 |
<Tip>
|
| 63 |
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.
|
|
|
|
| 99 |
fastmcp run https://example.com/mcp-server --log-level DEBUG
|
| 100 |
```
|
| 101 |
|
| 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 |
+
|
| 140 |
### `dev`
|
| 141 |
|
| 142 |
Run a MCP server with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) for testing.
|
src/fastmcp/mcp_config.py
CHANGED
|
@@ -270,7 +270,7 @@ class MCPConfig(BaseModel):
|
|
| 270 |
if content := file_path.read_text().strip():
|
| 271 |
return cls.model_validate_json(content)
|
| 272 |
|
| 273 |
-
|
| 274 |
|
| 275 |
|
| 276 |
class CanonicalMCPConfig(MCPConfig):
|
|
|
|
| 270 |
if content := file_path.read_text().strip():
|
| 271 |
return cls.model_validate_json(content)
|
| 272 |
|
| 273 |
+
raise ValueError(f"No MCP servers defined in the config: {file_path}")
|
| 274 |
|
| 275 |
|
| 276 |
class CanonicalMCPConfig(MCPConfig):
|