From 74518fb7b26263b14ab8d61563fb7d1ddd8f39b4 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 19 Jul 2025 21:15:38 -0400 Subject: [PATCH] Add docs --- docs/patterns/cli.mdx | 41 ++++++++++++++++++++++++++++++++++++++- src/fastmcp/mcp_config.py | 2 +- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/docs/patterns/cli.mdx b/docs/patterns/cli.mdx index dce1b5b32..0f8bfdb99 100644 --- a/docs/patterns/cli.mdx +++ b/docs/patterns/cli.mdx @@ -53,10 +53,11 @@ This command runs the server directly in your current Python environment. You ar #### Server Specification -The server can be specified in three ways: +The server can be specified in four ways: 1. `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found. 2. `server.py:custom_name` - imports and uses the specified server object 3. `http://server-url/path` or `https://server-url/path` - connects to a remote server and creates a proxy +4. `mcp.json` - runs servers defined in a standard MCP configuration file 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 fastmcp run https://example.com/mcp-server --log-level DEBUG ``` +#### Running MCP Configuration Files + +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. + +**Example mcp.json:** +```json +{ + "mcpServers": { + "fetch": { + "command": "uvx", + "args": [ + "mcp-server-fetch" + ] + }, + "filesystem": { + "command": "npx", + "args": [ + "-y", + "@modelcontextprotocol/server-filesystem", + "/Users/username/Documents" + ] + } + } +} +``` + +**Run the configuration:** +```bash +# Run with default stdio transport +fastmcp run mcp.json + +# Run with HTTP transport on custom port +fastmcp run mcp.json --transport http --port 8080 + +# Run with SSE transport +fastmcp run mcp.json --transport sse +``` + ### `dev` Run a MCP server with the [MCP Inspector](https://github.com/modelcontextprotocol/inspector) for testing. diff --git a/src/fastmcp/mcp_config.py b/src/fastmcp/mcp_config.py index 8d5576ec5..e6758e0c7 100644 --- a/src/fastmcp/mcp_config.py +++ b/src/fastmcp/mcp_config.py @@ -270,7 +270,7 @@ class MCPConfig(BaseModel): if content := file_path.read_text().strip(): return cls.model_validate_json(content) - return cls(mcpServers={}) + raise ValueError(f"No MCP servers defined in the config: {file_path}") class CanonicalMCPConfig(MCPConfig):