Jeremiah Lowin commited on
Commit
d5fbe48
·
unverified ·
2 Parent(s): 1e7e9a65402d03

Merge pull request #218 from jlowin/kwargs

Browse files
src/fastmcp/server/server.py CHANGED
@@ -7,6 +7,7 @@ from contextlib import (
7
  AsyncExitStack,
8
  asynccontextmanager,
9
  )
 
10
  from typing import TYPE_CHECKING, Any, Generic, Literal
11
 
12
  import anyio
@@ -259,7 +260,8 @@ class FastMCP(Generic[LifespanResultT]):
259
  transport: Transport protocol to use ("stdio" or "sse")
260
  """
261
  logger.info(f'Starting server "{self.name}"...')
262
- anyio.run(self.run_async, transport, **transport_kwargs)
 
263
 
264
  def _setup_handlers(self) -> None:
265
  """Set up core MCP protocol handlers."""
 
7
  AsyncExitStack,
8
  asynccontextmanager,
9
  )
10
+ from functools import partial
11
  from typing import TYPE_CHECKING, Any, Generic, Literal
12
 
13
  import anyio
 
260
  transport: Transport protocol to use ("stdio" or "sse")
261
  """
262
  logger.info(f'Starting server "{self.name}"...')
263
+
264
+ anyio.run(partial(self.run_async, transport, **transport_kwargs))
265
 
266
  def _setup_handlers(self) -> None:
267
  """Set up core MCP protocol handlers."""
tests/cli/test_run.py CHANGED
@@ -1,11 +1,4 @@
1
- from pathlib import Path
2
- from unittest.mock import Mock, patch
3
-
4
  import pytest
5
- from typer.testing import CliRunner
6
-
7
- from fastmcp import FastMCP
8
- from fastmcp.cli.cli import app
9
 
10
 
11
  @pytest.fixture
@@ -27,51 +20,3 @@ if __name__ == "__main__":
27
  """
28
  )
29
  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
 
 
 
 
1
  import pytest
 
 
 
 
2
 
3
 
4
  @pytest.fixture
 
20
  """
21
  )
22
  return server_path