mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 14:04:18 +02:00
feat: introduce fastmcp.json configuration system (#1517)
This commit is contained in:
parent
108ad4b70d
commit
2d3d5392f1
40 changed files with 3917 additions and 108 deletions
|
|
@ -18,10 +18,10 @@ fastmcp --help
|
|||
|
||||
| Command | Purpose | Dependency Management |
|
||||
| ------- | ------- | --------------------- |
|
||||
| `run` | Run a FastMCP server directly | **Supports:** Local files, factory functions, URLs, MCP configs. **Deps:** Uses your local environment directly. With `--python`, `--with`, `--project`, or `--with-requirements`: Runs via `uv run` subprocess |
|
||||
| `dev` | Run a server with the MCP Inspector for testing | **Supports:** Local files only. **Deps:** Always runs via `uv run` subprocess (never uses your local environment); dependencies must be specified or available in a uv-managed project |
|
||||
| `install` | Install a server in MCP client applications | **Supports:** Local files only. **Deps:** Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable` |
|
||||
| `inspect` | Generate a JSON report about a FastMCP server | **Supports:** Local files only. **Deps:** Uses your current environment; you are responsible for ensuring all dependencies are available |
|
||||
| `run` | Run a FastMCP server directly | **Supports:** Local files, factory functions, URLs, fastmcp.json configs, MCP configs. **Deps:** Uses your local environment directly. With `--python`, `--with`, `--project`, or `--with-requirements`: Runs via `uv run` subprocess. With fastmcp.json: Automatically manages dependencies based on configuration |
|
||||
| `dev` | Run a server with the MCP Inspector for testing | **Supports:** Local files and fastmcp.json configs. **Deps:** Always runs via `uv run` subprocess (never uses your local environment); dependencies must be specified or available in a uv-managed project. With fastmcp.json: Uses configured dependencies |
|
||||
| `install` | Install a server in MCP client applications | **Supports:** Local files and fastmcp.json configs. **Deps:** Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable`. With fastmcp.json: Uses configured dependencies |
|
||||
| `inspect` | Generate a JSON report about a FastMCP server | **Supports:** Local files and fastmcp.json configs. **Deps:** Uses your current environment; you are responsible for ensuring all dependencies are available |
|
||||
| `version` | Display version information | N/A |
|
||||
|
||||
## `fastmcp run`
|
||||
|
|
@ -61,7 +61,8 @@ The `fastmcp run` command supports the following entrypoints:
|
|||
2. **[Explicit server object](#explicit-server-object)**: `server.py:custom_name` - imports and uses the specified server object
|
||||
3. **[Factory function](#factory-function)**: `server.py:create_server` - calls the specified function (sync or async) to create a server instance
|
||||
4. **[Remote server proxy](#remote-server-proxy)**: `https://example.com/mcp-server` - connects to a remote server and creates a **local proxy server**
|
||||
5. **MCP configuration file**: `mcp.json` - runs servers defined in a standard MCP configuration file
|
||||
5. **[FastMCP configuration file](#fastmcp-configuration)**: `fastmcp.json` - runs servers using FastMCP's declarative configuration format (auto-detects files in current directory)
|
||||
6. **MCP configuration file**: `mcp.json` - runs servers defined in a standard MCP configuration file
|
||||
|
||||
<Warning>
|
||||
Note: When using `fastmcp run` with a local file, it **completely ignores** the `if __name__ == "__main__"` block. This means:
|
||||
|
|
@ -158,6 +159,28 @@ To start a local proxy, you can use the following syntax:
|
|||
fastmcp run https://example.com/mcp
|
||||
```
|
||||
|
||||
#### FastMCP Configuration
|
||||
<VersionBadge version="2.11.4" />
|
||||
|
||||
FastMCP supports declarative configuration through `fastmcp.json` files. When you run `fastmcp run` without arguments, it automatically looks for a `fastmcp.json` file in the current directory:
|
||||
|
||||
```bash
|
||||
# Auto-detect fastmcp.json in current directory
|
||||
fastmcp run
|
||||
|
||||
# Or explicitly specify a configuration file
|
||||
fastmcp run my-config.fastmcp.json
|
||||
```
|
||||
|
||||
The configuration file handles dependencies, environment variables, and transport settings. Command-line arguments override configuration file values:
|
||||
|
||||
```bash
|
||||
# Override port from config file
|
||||
fastmcp run fastmcp.json --port 8080
|
||||
```
|
||||
|
||||
See [Server Configuration](/deployment/server-configuration) for detailed documentation on fastmcp.json.
|
||||
|
||||
#### MCP Configuration
|
||||
|
||||
FastMCP can also run servers defined in a standard MCP configuration file. This is useful when you want to run multiple servers from a single file, or when you want to use a client that doesn't support direct connections to remote servers.
|
||||
|
|
@ -179,7 +202,12 @@ fastmcp dev server.py
|
|||
```
|
||||
|
||||
<Tip>
|
||||
This command always runs your server via `uv run` subprocess (never your local environment) to work with the MCP Inspector. All dependencies must be explicitly specified using the `--with` and/or `--with-editable` options, or be available in a uv-managed project.
|
||||
This command always runs your server via `uv run` subprocess (never your local environment) to work with the MCP Inspector. Dependencies can be:
|
||||
- Specified using `--with` and/or `--with-editable` options
|
||||
- Defined in a `fastmcp.json` configuration file
|
||||
- Available in a uv-managed project
|
||||
|
||||
When using `fastmcp.json`, the dev command automatically uses the configured dependencies.
|
||||
</Tip>
|
||||
|
||||
<Warning>
|
||||
|
|
@ -214,14 +242,15 @@ This command does not support HTTP testing. To test a server over Streamable HTT
|
|||
|
||||
### Entrypoints
|
||||
|
||||
The `dev` command supports local FastMCP server files only:
|
||||
The `dev` command supports local FastMCP server files and configuration:
|
||||
|
||||
1. **Inferred server instance**: `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
|
||||
2. **Explicit server object**: `server.py:custom_name` - imports and uses the specified server object
|
||||
3. **Factory function**: `server.py:create_server` - calls the specified function (sync or async) to create a server instance
|
||||
4. **FastMCP configuration**: `fastmcp.json` - uses FastMCP's declarative configuration (auto-detects in current directory)
|
||||
|
||||
<Warning>
|
||||
The `dev` command **only supports local files** - no URLs, remote servers, or MCP configuration files.
|
||||
The `dev` command **only supports local files and fastmcp.json** - no URLs, remote servers, or standard MCP configuration files.
|
||||
</Warning>
|
||||
|
||||
**Examples**
|
||||
|
|
@ -230,6 +259,12 @@ The `dev` command **only supports local files** - no URLs, remote servers, or MC
|
|||
# Run dev server with editable mode and additional packages
|
||||
fastmcp dev server.py -e . --with pandas --with matplotlib
|
||||
|
||||
# Run dev server with fastmcp.json configuration (auto-detects)
|
||||
fastmcp dev
|
||||
|
||||
# Run dev server with explicit fastmcp.json file
|
||||
fastmcp dev dev.fastmcp.json
|
||||
|
||||
# Run dev server with specific Python version
|
||||
fastmcp dev server.py --python 3.11
|
||||
|
||||
|
|
@ -286,18 +321,19 @@ Note that for security reasons, MCP clients usually run every server in a comple
|
|||
|
||||
### Entrypoints
|
||||
|
||||
The `install` command supports local FastMCP server files only:
|
||||
The `install` command supports local FastMCP server files and configuration:
|
||||
|
||||
1. **Inferred server instance**: `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
|
||||
2. **Explicit server object**: `server.py:custom_name` - imports and uses the specified server object
|
||||
3. **Factory function**: `server.py:create_server` - calls the specified function (sync or async) to create a server instance
|
||||
4. **FastMCP configuration**: `fastmcp.json` - uses FastMCP's declarative configuration with dependencies and settings
|
||||
|
||||
<Note>
|
||||
Factory functions are particularly useful for install commands since they allow setup code to run that would otherwise be ignored when the MCP client runs your server.
|
||||
Factory functions are particularly useful for install commands since they allow setup code to run that would otherwise be ignored when the MCP client runs your server. When using fastmcp.json, dependencies are automatically handled.
|
||||
</Note>
|
||||
|
||||
<Warning>
|
||||
The `install` command **only supports local files** - no URLs, remote servers, or MCP configuration files. For remote servers, use your MCP client's native configuration.
|
||||
The `install` command **only supports local files and fastmcp.json** - no URLs, remote servers, or standard MCP configuration files. For remote servers, use your MCP client's native configuration.
|
||||
</Warning>
|
||||
|
||||
**Examples**
|
||||
|
|
@ -306,6 +342,12 @@ The `install` command **only supports local files** - no URLs, remote servers, o
|
|||
# Auto-detects server object (looks for 'mcp', 'server', or 'app')
|
||||
fastmcp install claude-desktop server.py
|
||||
|
||||
# Install with fastmcp.json configuration (auto-detects)
|
||||
fastmcp install claude-desktop
|
||||
|
||||
# Install with explicit fastmcp.json file
|
||||
fastmcp install claude-desktop my-config.fastmcp.json
|
||||
|
||||
# Uses specific server object
|
||||
fastmcp install claude-desktop server.py:my_server
|
||||
|
||||
|
|
@ -395,14 +437,15 @@ fastmcp inspect server.py
|
|||
|
||||
### Entrypoints
|
||||
|
||||
The `inspect` command supports local FastMCP server files only:
|
||||
The `inspect` command supports local FastMCP server files and configuration:
|
||||
|
||||
1. **Inferred server instance**: `server.py` - imports the module and looks for a FastMCP object named `mcp`, `server`, or `app`. Errors if no such object is found.
|
||||
2. **Explicit server object**: `server.py:custom_name` - imports and uses the specified server object
|
||||
3. **Factory function**: `server.py:create_server` - calls the specified function (sync or async) to create a server instance
|
||||
4. **FastMCP configuration**: `fastmcp.json` - inspects servers defined with FastMCP's declarative configuration
|
||||
|
||||
<Warning>
|
||||
The `inspect` command **only supports local files** - no URLs, remote servers, or MCP configuration files.
|
||||
The `inspect` command **only supports local files and fastmcp.json** - no URLs, remote servers, or standard MCP configuration files.
|
||||
</Warning>
|
||||
|
||||
**Examples**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue