Repository: jlowin/fastmcp

Issue:
examples/config_server.py / server arguments appear broken
### Description

Passing extra arguments with argparse to a server application seem to be broken. To reproduce: 

```
git clone https://github.com/jlowin/fastmcp.git
cd fastmcp
uv sync
source .venv/bin/activate
fastmcp run examples/config_server.py -- --name MyServer --debug
```
yields
```
╭─ Error ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Unknown option: "--name".                                                                                                                                  │
╰────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
```





### Example Code

```Python
examples/config_server.py
```

### Version Information

```Text
2.10.7.dev38+99f27da
python version 3.12.11
uv version 0.8.3

Found bug while working with release version 2.10.5 and 2.10.6
```

### Additional Context

Passing no additional arguments yields
```
❯ fastmcp run examples/config_server.py                           
usage: fastmcp [-h] [--name NAME] [--debug]
fastmcp: error: unrecognized arguments: run examples/config_server.py
```


Discussion:
Closed in #1293 



Patch:
diff --git a/src/fastmcp/cli/cli.py b/src/fastmcp/cli/cli.py
index 11730d6b1..99e37107a 100644
--- a/src/fastmcp/cli/cli.py
+++ b/src/fastmcp/cli/cli.py
@@ -285,7 +285,7 @@ def dev(
 @app.command
 def run(
     server_spec: str,
-    *,
+    *server_args: str,
     transport: Annotated[
         run_module.TransportType | None,
         cyclopts.Parameter(
@@ -373,9 +373,6 @@ def run(
     Args:
         server_spec: Python file, object specification (file:obj), MCPConfig file, or URL
     """
-    # TODO: Handle server_args from extra context
-    server_args = []  # Will need to handle this with Cyclopts context
-
     logger.debug(
         "Running server or client",
         extra={
@@ -385,7 +382,7 @@ def run(
             "port": port,
             "path": path,
             "log_level": log_level,
-            "server_args": server_args,
+            "server_args": list(server_args),
         },
     )
 
@@ -424,7 +421,7 @@ def run(
                 port=port,
                 path=path,
                 log_level=log_level,
-                server_args=server_args,
+                server_args=list(server_args),
                 show_banner=not no_banner,
             )
         except Exception as e:


Test patch:
diff --git a/tests/cli/test_cli.py b/tests/cli/test_cli.py
index 13b304446..4653c189c 100644
--- a/tests/cli/test_cli.py
+++ b/tests/cli/test_cli.py
@@ -399,6 +399,79 @@ def test_run_command_transport_aliases(self):
         assert command is not None
         assert bound.arguments["transport"] == "streamable-http"
 
+    def test_run_command_parsing_with_server_args(self):
+        """Test run command parsing with server arguments after --."""
+        command, bound, _ = app.parse_args(
+            [
+                "run",
+                "server.py",
+                "--",
+                "--config",
+                "test.json",
+                "--debug",
+            ]
+        )
+
+        assert command is not None
+        assert bound.arguments["server_spec"] == "server.py"
+        # Server args after -- are captured as positional arguments in bound.args
+        assert bound.args == ("server.py", "--config", "test.json", "--debug")
+
+    def test_run_command_parsing_with_mixed_args(self):
+        """Test run command parsing with both FastMCP options and server args."""
+        command, bound, _ = app.parse_args(
+            [
+                "run",
+                "server.py",
+                "--transport",
+                "http",
+                "--port",
+                "8080",
+                "--",
+                "--server-port",
+                "9090",
+                "--debug",
+            ]
+        )
+
+        assert command is not None
+        assert bound.arguments["server_spec"] == "server.py"
+        assert bound.arguments["transport"] == "http"
+        assert bound.arguments["port"] == 8080
+        # Server args after -- are captured separately from FastMCP options
+        assert bound.args == ("server.py", "--server-port", "9090", "--debug")
+
+    def test_run_command_parsing_with_positional_server_args(self):
+        """Test run command parsing with positional server arguments."""
+        command, bound, _ = app.parse_args(
+            [
+                "run",
+                "server.py",
+                "--",
+                "arg1",
+                "arg2",
+                "--flag",
+            ]
+        )
+
+        assert command is not None
+        assert bound.arguments["server_spec"] == "server.py"
+        # Positional args and flags after -- are all captured
+        assert bound.args == ("server.py", "arg1", "arg2", "--flag")
+
+    def test_run_command_parsing_server_args_require_delimiter(self):
+        """Test that server args without -- delimiter are rejected."""
+        # Should fail because --config is not a recognized FastMCP option
+        with pytest.raises(SystemExit):
+            app.parse_args(
+                [
+                    "run",
+                    "server.py",
+                    "--config",
+                    "test.json",
+                ]
+            )
+
 
 class TestWindowsSpecific:
     """Test Windows-specific functionality."""