Skip to content

Commit 2e4f17a

Browse files
authored
Improve test coverage in test_tool_service (#241)
* Full coverage for test_verify_credentials Signed-off-by: Madhav Kandukuri <[email protected]> * Additional test_tool_service tests Signed-off-by: Madhav Kandukuri <[email protected]> * Add MCP tool call test Signed-off-by: Madhav Kandukuri <[email protected]> * More test_tool_service tests Signed-off-by: Madhav Kandukuri <[email protected]> * Some more tests Signed-off-by: Madhav Kandukuri <[email protected]> * More test cases Signed-off-by: Madhav Kandukuri <[email protected]> * test_tool_service at 90% coverage Signed-off-by: Madhav Kandukuri <[email protected]> * More tests Signed-off-by: Madhav Kandukuri <[email protected]> * Fix some test cases Signed-off-by: Madhav Kandukuri <[email protected]> * Linting and test cases Signed-off-by: Madhav Kandukuri <[email protected]>
1 parent 710d010 commit 2e4f17a

File tree

3 files changed

+962
-12
lines changed

3 files changed

+962
-12
lines changed

mcpgateway/services/tool_service.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,8 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
413413
raise ToolNotFoundError(f"Tool '{name}' exists but is inactive")
414414
raise ToolNotFoundError(f"Tool not found: {name}")
415415

416-
is_reachable = db.execute(select(DbTool.reachable).where(slug_expr == name)).scalar_one_or_none()
416+
# is_reachable = db.execute(select(DbTool.reachable).where(slug_expr == name)).scalar_one_or_none()
417+
is_reachable = tool.reachable
417418

418419
if not is_reachable:
419420
raise ToolNotFoundError(f"Tool '{name}' exists but is currently offline. Please verify if it is running.")
@@ -472,10 +473,7 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
472473
elif tool.integration_type == "MCP":
473474
transport = tool.request_type.lower()
474475
gateway = db.execute(select(DbGateway).where(DbGateway.id == tool.gateway_id).where(DbGateway.enabled)).scalar_one_or_none()
475-
if gateway.auth_type == "bearer":
476-
headers = decode_auth(gateway.auth_value)
477-
else:
478-
headers = {}
476+
headers = decode_auth(gateway.auth_value)
479477

480478
async def connect_to_sse_server(server_url: str) -> str:
481479
"""
@@ -527,7 +525,7 @@ async def connect_to_streamablehttp_server(server_url: str) -> str:
527525
filtered_response = extract_using_jq(content, tool.jsonpath_filter)
528526
tool_result = ToolResult(content=filtered_response)
529527
else:
530-
return ToolResult(content="Invalid tool type")
528+
return ToolResult(content=[TextContent(type="text", text="Invalid tool type")])
531529

532530
return tool_result
533531
except Exception as e:

0 commit comments

Comments
 (0)