Spaces:
Running
Running
zzstoatzz commited on
Commit ·
9d2dc87
1
Parent(s): 6a43ff3
cleaner
Browse files- docs/deployment/running-server.mdx +3 -5
- src/fastmcp/cli/cli.py +6 -10
- tests/cli/test_cli.py +2 -3
docs/deployment/running-server.mdx
CHANGED
|
@@ -63,13 +63,11 @@ See the [CLI documentation](/patterns/cli) for detailed information about all av
|
|
| 63 |
|
| 64 |
### Passing Arguments to Servers
|
| 65 |
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
When servers accept command line arguments (using argparse, click, or other libraries), you can pass them using the `--server-arg` option:
|
| 69 |
|
| 70 |
```bash
|
| 71 |
-
fastmcp run config_server.py --
|
| 72 |
-
fastmcp run database_server.py --
|
| 73 |
```
|
| 74 |
|
| 75 |
This is useful for servers that need configuration files, database paths, API keys, or other runtime options.
|
|
|
|
| 63 |
|
| 64 |
### Passing Arguments to Servers
|
| 65 |
|
| 66 |
+
When servers accept command line arguments (using argparse, click, or other libraries), you can pass them after `--`:
|
|
|
|
|
|
|
| 67 |
|
| 68 |
```bash
|
| 69 |
+
fastmcp run config_server.py -- --config config.json
|
| 70 |
+
fastmcp run database_server.py -- --database-path /tmp/db.sqlite --debug
|
| 71 |
```
|
| 72 |
|
| 73 |
This is useful for servers that need configuration files, database paths, API keys, or other runtime options.
|
src/fastmcp/cli/cli.py
CHANGED
|
@@ -219,8 +219,9 @@ def dev(
|
|
| 219 |
sys.exit(1)
|
| 220 |
|
| 221 |
|
| 222 |
-
@app.command()
|
| 223 |
def run(
|
|
|
|
| 224 |
server_spec: str = typer.Argument(
|
| 225 |
...,
|
| 226 |
help="Python file, object specification (file:obj), or URL",
|
|
@@ -256,13 +257,6 @@ def run(
|
|
| 256 |
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
|
| 257 |
),
|
| 258 |
] = None,
|
| 259 |
-
server_args: Annotated[
|
| 260 |
-
list[str],
|
| 261 |
-
typer.Option(
|
| 262 |
-
"--server-arg",
|
| 263 |
-
help="Additional arguments to pass to the server",
|
| 264 |
-
),
|
| 265 |
-
] = [],
|
| 266 |
) -> None:
|
| 267 |
"""Run a MCP server or connect to a remote one.
|
| 268 |
|
|
@@ -274,9 +268,11 @@ def run(
|
|
| 274 |
Note: This command runs the server directly. You are responsible for ensuring
|
| 275 |
all dependencies are available.
|
| 276 |
|
| 277 |
-
Server arguments can be passed
|
| 278 |
-
fastmcp run server.py --
|
| 279 |
"""
|
|
|
|
|
|
|
| 280 |
logger.debug(
|
| 281 |
"Running server or client",
|
| 282 |
extra={
|
|
|
|
| 219 |
sys.exit(1)
|
| 220 |
|
| 221 |
|
| 222 |
+
@app.command(context_settings={"allow_extra_args": True})
|
| 223 |
def run(
|
| 224 |
+
ctx: typer.Context,
|
| 225 |
server_spec: str = typer.Argument(
|
| 226 |
...,
|
| 227 |
help="Python file, object specification (file:obj), or URL",
|
|
|
|
| 257 |
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
|
| 258 |
),
|
| 259 |
] = None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 260 |
) -> None:
|
| 261 |
"""Run a MCP server or connect to a remote one.
|
| 262 |
|
|
|
|
| 268 |
Note: This command runs the server directly. You are responsible for ensuring
|
| 269 |
all dependencies are available.
|
| 270 |
|
| 271 |
+
Server arguments can be passed after -- :
|
| 272 |
+
fastmcp run server.py -- --config config.json --debug
|
| 273 |
"""
|
| 274 |
+
server_args = ctx.args # extra args after --
|
| 275 |
+
|
| 276 |
logger.debug(
|
| 277 |
"Running server or client",
|
| 278 |
extra={
|
tests/cli/test_cli.py
CHANGED
|
@@ -411,7 +411,7 @@ class TestRunCommand:
|
|
| 411 |
)
|
| 412 |
|
| 413 |
def test_run_command_with_server_args(self, temp_python_file):
|
| 414 |
-
"""Test run command with server arguments."""
|
| 415 |
with (
|
| 416 |
patch("fastmcp.cli.run.run_command") as mock_run_command,
|
| 417 |
):
|
|
@@ -420,9 +420,8 @@ class TestRunCommand:
|
|
| 420 |
[
|
| 421 |
"run",
|
| 422 |
str(temp_python_file),
|
| 423 |
-
"--
|
| 424 |
"--config",
|
| 425 |
-
"--server-arg",
|
| 426 |
"config.json",
|
| 427 |
],
|
| 428 |
)
|
|
|
|
| 411 |
)
|
| 412 |
|
| 413 |
def test_run_command_with_server_args(self, temp_python_file):
|
| 414 |
+
"""Test run command with server arguments using -- pattern."""
|
| 415 |
with (
|
| 416 |
patch("fastmcp.cli.run.run_command") as mock_run_command,
|
| 417 |
):
|
|
|
|
| 420 |
[
|
| 421 |
"run",
|
| 422 |
str(temp_python_file),
|
| 423 |
+
"--",
|
| 424 |
"--config",
|
|
|
|
| 425 |
"config.json",
|
| 426 |
],
|
| 427 |
)
|