mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-23 14:04:18 +02:00
Add --python, --project, and --with-requirements options to CLI commands (#1190)
This commit is contained in:
parent
1b953820b3
commit
a65bfd10be
16 changed files with 1140 additions and 40 deletions
|
|
@ -18,8 +18,8 @@ fastmcp --help
|
|||
|
||||
| Command | Purpose | Dependency Management |
|
||||
| ------- | ------- | --------------------- |
|
||||
| `run` | Run a FastMCP server directly | Uses your current environment; you are responsible for ensuring all dependencies are available |
|
||||
| `dev` | Run a server with the MCP Inspector for testing | Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable` |
|
||||
| `run` | Run a FastMCP server directly | Default: 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 | 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 | Creates an isolated environment; dependencies must be explicitly specified with `--with` and/or `--with-editable` |
|
||||
| `inspect` | Generate a JSON report about a FastMCP server | Uses your current environment; you are responsible for ensuring all dependencies are available |
|
||||
| `version` | Display version information | N/A |
|
||||
|
|
@ -35,7 +35,7 @@ fastmcp run server.py
|
|||
```
|
||||
|
||||
<Tip>
|
||||
This command runs the server directly in your current Python environment. You are responsible for ensuring all dependencies are available.
|
||||
By default, this command runs the server directly in your current Python environment. You are responsible for ensuring all dependencies are available. When using `--python`, `--with`, `--project`, or `--with-requirements` options, it runs the server via `uv run` subprocess instead.
|
||||
</Tip>
|
||||
|
||||
#### Options
|
||||
|
|
@ -48,6 +48,10 @@ This command runs the server directly in your current Python environment. You ar
|
|||
| Path | `--path` | Path to bind to when using http transport (default: `/mcp/` or `/sse/` for SSE) |
|
||||
| Log Level | `--log-level`, `-l` | Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL) |
|
||||
| No Banner | `--no-banner` | Disable the startup banner display |
|
||||
| Python Version | `--python` | Python version to use (e.g., 3.10, 3.11) |
|
||||
| Additional Packages | `--with` | Additional packages to install (can be used multiple times) |
|
||||
| Project Directory | `--project` | Run the command within the given project directory |
|
||||
| Requirements File | `--with-requirements` | Requirements file to install dependencies from |
|
||||
|
||||
|
||||
#### Server Specification
|
||||
|
|
@ -96,6 +100,18 @@ fastmcp run https://example.com/mcp-server
|
|||
|
||||
# Connect to a remote server with specified log level
|
||||
fastmcp run https://example.com/mcp-server --log-level DEBUG
|
||||
|
||||
# Run with a specific Python version
|
||||
fastmcp run server.py --python 3.11
|
||||
|
||||
# Run with additional packages
|
||||
fastmcp run server.py --with pandas --with numpy
|
||||
|
||||
# Run within a specific project directory
|
||||
fastmcp run server.py --project /path/to/project
|
||||
|
||||
# Run with dependencies from a requirements file
|
||||
fastmcp run server.py --with-requirements requirements.txt
|
||||
```
|
||||
|
||||
### `dev`
|
||||
|
|
@ -107,7 +123,7 @@ fastmcp dev server.py
|
|||
```
|
||||
|
||||
<Tip>
|
||||
This command runs your server in an isolated environment. All dependencies must be explicitly specified using the `--with` and/or `--with-editable` options.
|
||||
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.
|
||||
</Tip>
|
||||
|
||||
<Warning>
|
||||
|
|
@ -136,12 +152,24 @@ This command does not support HTTP testing. To test a server over Streamable HTT
|
|||
| Inspector Version | `--inspector-version` | Version of the MCP Inspector to use |
|
||||
| UI Port | `--ui-port` | Port for the MCP Inspector UI |
|
||||
| Server Port | `--server-port` | Port for the MCP Inspector Proxy server |
|
||||
| Python Version | `--python` | Python version to use (e.g., 3.10, 3.11) |
|
||||
| Project Directory | `--project` | Run the command within the given project directory |
|
||||
| Requirements File | `--with-requirements` | Requirements file to install dependencies from |
|
||||
|
||||
**Example**
|
||||
**Examples**
|
||||
|
||||
```bash
|
||||
# Run dev server with editable mode and additional packages
|
||||
fastmcp dev server.py -e . --with pandas --with matplotlib
|
||||
|
||||
# Run dev server with specific Python version
|
||||
fastmcp dev server.py --python 3.11
|
||||
|
||||
# Run dev server with requirements file
|
||||
fastmcp dev server.py --with-requirements requirements.txt
|
||||
|
||||
# Run dev server within a specific project directory
|
||||
fastmcp dev server.py --project /path/to/project
|
||||
```
|
||||
|
||||
### `install`
|
||||
|
|
@ -167,6 +195,10 @@ Note that for security reasons, MCP clients usually run every server in a comple
|
|||
**`uv` must be installed and available in your system PATH**. Both Claude Desktop and Cursor run in isolated environments and need `uv` to manage dependencies. On macOS, install `uv` globally with Homebrew for Claude Desktop compatibility: `brew install uv`.
|
||||
</Warning>
|
||||
|
||||
<Note>
|
||||
**Python Version Considerations**: The install commands now support the `--python` option to specify a Python version directly. You can also use `--project` to run within a specific project directory or `--with-requirements` to install dependencies from a requirements file.
|
||||
</Note>
|
||||
|
||||
<Tip>
|
||||
**FastMCP `install` commands focus on local server files with STDIO transport.** For remote servers running with HTTP or SSE transport, use your client's native configuration - FastMCP's value is simplifying the complex local setup with dependencies and `uv` commands.
|
||||
</Tip>
|
||||
|
|
@ -187,6 +219,9 @@ The `install` command supports the same `file.py:object` notation as the `run` c
|
|||
| Additional Packages | `--with` | Additional packages to install (can be used multiple times) |
|
||||
| Environment Variables | `--env` | Environment variables in KEY=VALUE format (can be used multiple times) |
|
||||
| Environment File | `--env-file`, `-f` | Load environment variables from a .env file |
|
||||
| Python Version | `--python` | Python version to use (e.g., 3.10, 3.11) |
|
||||
| Project Directory | `--project` | Run the command within the given project directory |
|
||||
| Requirements File | `--with-requirements` | Requirements file to install dependencies from |
|
||||
|
||||
**Examples**
|
||||
|
||||
|
|
@ -209,6 +244,15 @@ fastmcp install cursor server.py --env API_KEY=secret --env DEBUG=true
|
|||
# Install with environment file
|
||||
fastmcp install cursor server.py --env-file .env
|
||||
|
||||
# Install with specific Python version
|
||||
fastmcp install claude-desktop server.py --python 3.11
|
||||
|
||||
# Install with requirements file
|
||||
fastmcp install claude-code server.py --with-requirements requirements.txt
|
||||
|
||||
# Install within a project directory
|
||||
fastmcp install cursor server.py --project /path/to/project
|
||||
|
||||
# Generate MCP JSON configuration
|
||||
fastmcp install mcp-json server.py --name "My Server" --with pandas
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue