|
35 | 35 | from mcp.client.streamable_http import streamablehttp_client |
36 | 36 | from sqlalchemy import and_, case, delete, desc, Float, func, not_, or_, select |
37 | 37 | from sqlalchemy.exc import IntegrityError |
38 | | -from sqlalchemy.orm import joinedload, Session |
| 38 | +from sqlalchemy.orm import joinedload, selectinload, Session |
39 | 39 |
|
40 | 40 | # First-Party |
41 | 41 | from mcpgateway.common.models import Gateway as PydanticGateway |
@@ -360,9 +360,10 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T |
360 | 360 | tool_dict = tool.__dict__.copy() |
361 | 361 | tool_dict.pop("_sa_instance_state", None) |
362 | 362 |
|
363 | | - tool_dict["execution_count"] = tool.execution_count |
364 | 363 | tool_dict["metrics"] = tool.metrics_summary if include_metrics else None |
365 | 364 |
|
| 365 | + tool_dict["execution_count"] = tool.execution_count if include_metrics else None |
| 366 | + |
366 | 367 | tool_dict["request_type"] = tool.request_type |
367 | 368 | tool_dict["annotations"] = tool.annotations or {} |
368 | 369 |
|
@@ -405,6 +406,7 @@ def _convert_tool_to_read(self, tool: DbTool, include_metrics: bool = True) -> T |
405 | 406 | tool_dict["custom_name_slug"] = getattr(tool, "custom_name_slug", "") or "" |
406 | 407 | tool_dict["tags"] = getattr(tool, "tags", []) or [] |
407 | 408 | tool_dict["team"] = getattr(tool, "team", None) |
| 409 | + |
408 | 410 | return ToolRead.model_validate(tool_dict) |
409 | 411 |
|
410 | 412 | async def _record_tool_metric(self, db: Session, tool: DbTool, start_time: float, success: bool, error_message: Optional[str]) -> None: |
@@ -848,7 +850,19 @@ async def list_server_tools( |
848 | 850 | True |
849 | 851 | """ |
850 | 852 |
|
851 | | - query = select(DbTool).options(joinedload(DbTool.gateway)).join(server_tool_association, DbTool.id == server_tool_association.c.tool_id).where(server_tool_association.c.server_id == server_id) |
| 853 | + if include_metrics: |
| 854 | + query = ( |
| 855 | + select(DbTool) |
| 856 | + .options(joinedload(DbTool.gateway)) |
| 857 | + .options(selectinload(DbTool.metrics)) |
| 858 | + .join(server_tool_association, DbTool.id == server_tool_association.c.tool_id) |
| 859 | + .where(server_tool_association.c.server_id == server_id) |
| 860 | + ) |
| 861 | + else: |
| 862 | + query = ( |
| 863 | + select(DbTool).options(joinedload(DbTool.gateway)).join(server_tool_association, DbTool.id == server_tool_association.c.tool_id).where(server_tool_association.c.server_id == server_id) |
| 864 | + ) |
| 865 | + |
852 | 866 | cursor = None # Placeholder for pagination; ignore for now |
853 | 867 | logger.debug(f"Listing server tools for server_id={server_id} with include_inactive={include_inactive}, cursor={cursor}") |
854 | 868 |
|
|
0 commit comments