@@ -43,6 +43,22 @@ def tool_func(arg: int) -> str:
4343 params = find_dependency_parameters (tool_func )
4444 assert params == {}
4545
46+ def test_depends_repr (self ):
47+ def get_dep () -> str :
48+ return "dep"
49+
50+ dep = Depends (get_dep )
51+ assert repr (dep ) == "Depends(get_dep)"
52+ assert str (dep ) == "Depends(get_dep)"
53+
54+ def test_find_dependency_parameters_signature_error (self ):
55+ # Test that signature errors are handled gracefully
56+ class BadFunction :
57+ """A function that will raise an error when getting signature."""
58+
59+ params = find_dependency_parameters (BadFunction )
60+ assert params == {}
61+
4662
4763class TestDependencyResolver :
4864 @pytest .mark .anyio
@@ -152,3 +168,30 @@ async def get_db(config: dict[str, str] = Depends(get_config)) -> str:
152168
153169 result = await resolver .resolve ("db" , dep )
154170 assert result == "test_async"
171+
172+ @pytest .mark .anyio
173+ async def test_resolve_dependency_not_in_signature (self ):
174+ """Test handling when dependency name is in kwarg_names but not in signature."""
175+
176+ def get_value () -> str :
177+ return "test"
178+
179+ def other_func () -> str :
180+ return "other"
181+
182+ # Create a tool with dependencies
183+ from mcp .server .mcpserver .tools .base import Tool
184+
185+ async def tool_func (value : str = Depends (get_value )) -> str :
186+ return value
187+
188+ tool = Tool .from_function (tool_func )
189+
190+ # Manually add a dependency that doesn't exist in signature
191+ tool .dependency_kwarg_names .append ("nonexistent" )
192+
193+ resolver = DependencyResolver ()
194+ # This should handle the missing dependency gracefully
195+ # (in practice this shouldn't happen, but we need to test the branch)
196+ deps = find_dependency_parameters (tool_func )
197+ assert "nonexistent" not in deps
0 commit comments