Skip to content

Commit 0c15d60

Browse files
authored
Merge pull request #218 from jlowin/kwargs
Pass kwargs correctly
2 parents a2c1e14 + bfda92e commit 0c15d60

File tree

2 files changed

+3
-56
lines changed

2 files changed

+3
-56
lines changed

Diff for: src/fastmcp/server/server.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
AsyncExitStack,
88
asynccontextmanager,
99
)
10+
from functools import partial
1011
from typing import TYPE_CHECKING, Any, Generic, Literal
1112

1213
import anyio
@@ -259,7 +260,8 @@ def run(
259260
transport: Transport protocol to use ("stdio" or "sse")
260261
"""
261262
logger.info(f'Starting server "{self.name}"...')
262-
anyio.run(self.run_async, transport, **transport_kwargs)
263+
264+
anyio.run(partial(self.run_async, transport, **transport_kwargs))
263265

264266
def _setup_handlers(self) -> None:
265267
"""Set up core MCP protocol handlers."""

Diff for: tests/cli/test_run.py

-55
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,4 @@
1-
from pathlib import Path
2-
from unittest.mock import Mock, patch
3-
41
import pytest
5-
from typer.testing import CliRunner
6-
7-
from fastmcp import FastMCP
8-
from fastmcp.cli.cli import app
92

103

114
@pytest.fixture
@@ -27,51 +20,3 @@ def hello(name: str) -> str:
2720
"""
2821
)
2922
return server_path
30-
31-
32-
def test_cli_run_transport_kwargs():
33-
"""Test that transport_kwargs are correctly passed from CLI to server.run()"""
34-
runner = CliRunner()
35-
36-
# Need to mock both the file parsing and the server import
37-
with (
38-
patch("fastmcp.cli.cli._parse_file_path") as mock_parse_file_path,
39-
patch("fastmcp.cli.cli._import_server") as mock_import_server,
40-
):
41-
# Make _parse_file_path return a fake path and server object
42-
mock_parse_file_path.return_value = (Path("fake_server.py"), "mcp")
43-
44-
# Create a mock server with a mock run method
45-
mock_server = FastMCP(name="MockServer")
46-
mock_server.run = Mock()
47-
48-
# Make _import_server return our mock server
49-
mock_import_server.return_value = mock_server
50-
51-
# Run the CLI command with transport_kwargs
52-
result = runner.invoke(
53-
app,
54-
[
55-
"run",
56-
"fake_server.py",
57-
"--transport",
58-
"sse",
59-
"--host",
60-
"127.0.0.1",
61-
"--port",
62-
"9000",
63-
"--log-level",
64-
"DEBUG",
65-
],
66-
)
67-
68-
# Check that the run method was called with the correct kwargs
69-
mock_server.run.assert_called_once_with(
70-
transport="sse",
71-
host="127.0.0.1",
72-
port=9000,
73-
log_level="DEBUG",
74-
)
75-
76-
# Check CLI command succeeded
77-
assert result.exit_code == 0

0 commit comments

Comments
 (0)