Skip to content

Improve test coverage in test_tool_service #241

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
Jul 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion mcpgateway/services/gateway_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,6 @@ async def check_health_of_gateways(self, gateways: List[DbGateway]) -> bool:
# Reuse a single HTTP client for all requests
async with httpx.AsyncClient() as client:
for gateway in gateways:

logger.debug(f"Checking health of gateway: {gateway.name} ({gateway.url})")
try:
# Ensure auth_value is a dict
Expand Down
12 changes: 5 additions & 7 deletions mcpgateway/services/tool_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,8 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
raise ToolNotFoundError(f"Tool '{name}' exists but is inactive")
raise ToolNotFoundError(f"Tool not found: {name}")

is_reachable = db.execute(select(DbTool.reachable).where(slug_expr == name)).scalar_one_or_none()
# is_reachable = db.execute(select(DbTool.reachable).where(slug_expr == name)).scalar_one_or_none()
is_reachable = tool.reachable

if not is_reachable:
raise ToolNotFoundError(f"Tool '{name}' exists but is currently offline. Please verify if it is running.")
Expand Down Expand Up @@ -452,7 +453,7 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
response = await self._http_client.get(final_url, params=payload, headers=headers)
else:
response = await self._http_client.request(method, final_url, json=payload, headers=headers)
await response.raise_for_status()
response.raise_for_status()

# Handle 204 No Content responses that have no body
if response.status_code == 204:
Expand All @@ -472,10 +473,7 @@ async def invoke_tool(self, db: Session, name: str, arguments: Dict[str, Any]) -
elif tool.integration_type == "MCP":
transport = tool.request_type.lower()
gateway = db.execute(select(DbGateway).where(DbGateway.id == tool.gateway_id).where(DbGateway.enabled)).scalar_one_or_none()
if gateway.auth_type == "bearer":
headers = decode_auth(gateway.auth_value)
else:
headers = {}
headers = decode_auth(gateway.auth_value)

async def connect_to_sse_server(server_url: str) -> str:
"""
Expand Down Expand Up @@ -527,7 +525,7 @@ async def connect_to_streamablehttp_server(server_url: str) -> str:
filtered_response = extract_using_jq(content, tool.jsonpath_filter)
tool_result = ToolResult(content=filtered_response)
else:
return ToolResult(content="Invalid tool type")
return ToolResult(content=[TextContent(type="text", text="Invalid tool type")])

return tool_result
except Exception as e:
Expand Down
1 change: 1 addition & 0 deletions mcpgateway/utils/db_isready.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
await wait_for_db_ready() # asynchronous
wait_for_db_ready(sync=True) # synchronous / blocking
"""

# Future
from __future__ import annotations

Expand Down
2 changes: 2 additions & 0 deletions mcpgateway/utils/redis_isready.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import time
from typing import Any, Optional

# First-Party
# First Party imports
from mcpgateway.config import settings

Expand Down Expand Up @@ -133,6 +134,7 @@ def _probe(*_: Any) -> None:
"""
try:
# Import redis here to avoid dependency issues if not used
# Third-Party
from redis import Redis
except ImportError: # pragma: no cover - handled at runtime for the CLI
sys.stderr.write("redis library not installed - aborting (pip install redis)\n")
Expand Down
Loading
Loading