mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-22 13:34:17 +02:00
Add docs
This commit is contained in:
parent
c9255f483f
commit
74518fb7b2
2 changed files with 41 additions and 2 deletions
|
|
@ -53,10 +53,11 @@ This command runs the server directly in your current Python environment. You ar
|
|||
#### Server Specification
|
||||
<VersionBadge version="2.3.5" />
|
||||
|
||||
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
|
||||
|
||||
<Tip>
|
||||
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.
|
||||
|
|
|
|||
|
|
@ -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):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue