mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-26 23:44:17 +02:00
cleaner
This commit is contained in:
parent
33304cbb18
commit
789d856a53
3 changed files with 11 additions and 18 deletions
|
|
@ -63,13 +63,11 @@ See the [CLI documentation](/patterns/cli) for detailed information about all av
|
|||
|
||||
### Passing Arguments to Servers
|
||||
|
||||
<VersionBadge version="2.6.2" />
|
||||
|
||||
When servers accept command line arguments (using argparse, click, or other libraries), you can pass them using the `--server-arg` option:
|
||||
When servers accept command line arguments (using argparse, click, or other libraries), you can pass them after `--`:
|
||||
|
||||
```bash
|
||||
fastmcp run config_server.py --server-arg="--config" --server-arg="config.json"
|
||||
fastmcp run database_server.py --server-arg="--database-path" --server-arg="/tmp/db.sqlite"
|
||||
fastmcp run config_server.py -- --config config.json
|
||||
fastmcp run database_server.py -- --database-path /tmp/db.sqlite --debug
|
||||
```
|
||||
|
||||
This is useful for servers that need configuration files, database paths, API keys, or other runtime options.
|
||||
|
|
|
|||
|
|
@ -219,8 +219,9 @@ def dev(
|
|||
sys.exit(1)
|
||||
|
||||
|
||||
@app.command()
|
||||
@app.command(context_settings={"allow_extra_args": True})
|
||||
def run(
|
||||
ctx: typer.Context,
|
||||
server_spec: str = typer.Argument(
|
||||
...,
|
||||
help="Python file, object specification (file:obj), or URL",
|
||||
|
|
@ -256,13 +257,6 @@ def run(
|
|||
help="Log level (DEBUG, INFO, WARNING, ERROR, CRITICAL)",
|
||||
),
|
||||
] = None,
|
||||
server_args: Annotated[
|
||||
list[str],
|
||||
typer.Option(
|
||||
"--server-arg",
|
||||
help="Additional arguments to pass to the server",
|
||||
),
|
||||
] = [],
|
||||
) -> None:
|
||||
"""Run a MCP server or connect to a remote one.
|
||||
|
||||
|
|
@ -274,9 +268,11 @@ def run(
|
|||
Note: This command runs the server directly. You are responsible for ensuring
|
||||
all dependencies are available.
|
||||
|
||||
Server arguments can be passed using --server-arg:
|
||||
fastmcp run server.py --server-arg="--config" --server-arg="config.json"
|
||||
Server arguments can be passed after -- :
|
||||
fastmcp run server.py -- --config config.json --debug
|
||||
"""
|
||||
server_args = ctx.args # extra args after --
|
||||
|
||||
logger.debug(
|
||||
"Running server or client",
|
||||
extra={
|
||||
|
|
|
|||
|
|
@ -411,7 +411,7 @@ class TestRunCommand:
|
|||
)
|
||||
|
||||
def test_run_command_with_server_args(self, temp_python_file):
|
||||
"""Test run command with server arguments."""
|
||||
"""Test run command with server arguments using -- pattern."""
|
||||
with (
|
||||
patch("fastmcp.cli.run.run_command") as mock_run_command,
|
||||
):
|
||||
|
|
@ -420,9 +420,8 @@ class TestRunCommand:
|
|||
[
|
||||
"run",
|
||||
str(temp_python_file),
|
||||
"--server-arg",
|
||||
"--",
|
||||
"--config",
|
||||
"--server-arg",
|
||||
"config.json",
|
||||
],
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue