File tree Expand file tree Collapse file tree 3 files changed +10
-17
lines changed
src/mcp/server/fastmcp/tools Expand file tree Collapse file tree 3 files changed +10
-17
lines changed Original file line number Diff line number Diff line change 66
77from pydantic import BaseModel , Field
88
9- import mcp .server .fastmcp
109from mcp .server .fastmcp .exceptions import ToolError
1110from mcp .server .fastmcp .utilities .func_metadata import FuncMetadata , func_metadata
1211
@@ -41,6 +40,8 @@ def from_function(
4140 context_kwarg : str | None = None ,
4241 ) -> Tool :
4342 """Create a Tool from a function."""
43+ from mcp .server .fastmcp import Context
44+
4445 func_name = name or fn .__name__
4546
4647 if func_name == "<lambda>" :
@@ -49,11 +50,10 @@ def from_function(
4950 func_doc = description or fn .__doc__ or ""
5051 is_async = inspect .iscoroutinefunction (fn )
5152
52- # Find context parameter if it exists
5353 if context_kwarg is None :
5454 sig = inspect .signature (fn )
5555 for param_name , param in sig .parameters .items ():
56- if param .annotation is mcp . server . fastmcp . Context :
56+ if param .annotation is Context :
5757 context_kwarg = param_name
5858 break
5959
Original file line number Diff line number Diff line change 11import json
22import subprocess
3+ from pathlib import Path
34from unittest .mock import patch
45
56import pytest
89
910
1011@pytest .fixture
11- def temp_config_dir (tmp_path ):
12+ def temp_config_dir (tmp_path : Path ):
1213 """Create a temporary Claude config directory."""
1314 config_dir = tmp_path / "Claude"
1415 config_dir .mkdir ()
1516 return config_dir
1617
1718
1819@pytest .fixture
19- def mock_config_path (temp_config_dir ):
20+ def mock_config_path (temp_config_dir : Path ):
2021 """Mock get_claude_config_path to return our temporary directory."""
2122 with patch ("mcp.cli.claude.get_claude_config_path" , return_value = temp_config_dir ):
2223 yield temp_config_dir
2324
2425
25- def test_command_execution (mock_config_path ):
26+ def test_command_execution (mock_config_path : Path ):
2627 """Test that the generated command can actually be executed."""
2728 # Setup
2829 server_name = "test_server"
2930 file_spec = "test_server.py:app"
3031
3132 # Update config
32- success = update_claude_config (
33- file_spec = file_spec ,
34- server_name = server_name ,
35- )
33+ success = update_claude_config (file_spec = file_spec , server_name = server_name )
3634 assert success
3735
3836 # Read the generated config
Original file line number Diff line number Diff line change 33
44from mcp .client .session import ClientSession
55from mcp .server .fastmcp .server import Context
6- from mcp .server .session import ServerSession
76from mcp .shared .context import RequestContext
87from mcp .shared .memory import (
98 create_connected_server_and_client_session as create_session ,
109)
11- from mcp .types import (
12- ListRootsResult ,
13- Root ,
14- TextContent ,
15- )
10+ from mcp .types import ListRootsResult , Root , TextContent
1611
1712
1813@pytest .mark .anyio
@@ -40,7 +35,7 @@ async def list_roots_callback(
4035 return callback_return
4136
4237 @server .tool ("test_list_roots" )
43- async def test_list_roots (context : Context [ ServerSession , None ] , message : str ):
38+ async def test_list_roots (context : Context , message : str ):
4439 roots = await context .session .list_roots ()
4540 assert roots == callback_return
4641 return True
You can’t perform that action at this time.
0 commit comments