get_metrics
Retrieve comprehensive metrics and analytics from a completed simulation, including travel statistics, emissions data, and traffic flow information.
Instructions
Retrieves comprehensive metrics and analytics data from a completed simulation, including travel statistics, emissions data, and traffic flow information.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| simulation_id | Yes | ||
| ctx | No |
Implementation Reference
- src/fujitsu_sdt_mcp/server.py:488-502 (handler)MCP tool handler for get_metrics. Decorated with @mcp.tool(), this is the main entry point that retrieves comprehensive metrics and analytics data from a completed simulation, including travel statistics, emissions data, and traffic flow information.
@mcp.tool() async def get_metrics(simulation_id: str, ctx: Optional[Context] = None) -> Dict[str, Any]: """Retrieves comprehensive metrics and analytics data from a completed simulation, including travel statistics, emissions data, and traffic flow information.""" try: if not simulation_id: return format_api_error(400, "simulationId required") async with await get_http_client() as client: api_client = FujitsuSocialDigitalTwinClient(client) result = await api_client.get_metrics(simulation_id) return result except Exception as e: logger.error(f"Metrics retrieval error: {e}") return format_api_error(500, str(e)) - src/fujitsu_sdt_mcp/server.py:488-488 (registration)Registration of get_metrics as an MCP tool via @mcp.tool() decorator on line 488.
@mcp.tool() - src/fujitsu_sdt_mcp/server.py:109-119 (handler)FujitsuSocialDigitalTwinClient.get_metrics() - API client method that calls GET /api/metrics/{simulation_id} to fetch metrics data from the backend API.
async def get_metrics(self, simulation_id: str) -> Dict[str, Any]: try: response = await self.client.get(f"/api/metrics/{simulation_id}") response.raise_for_status() return format_simulation_result(response.json()) except httpx.HTTPStatusError as e: logger.error(f"Metrics retrieval error: {e}") return format_api_error(e.response.status_code, str(e)) except Exception as e: logger.error(f"Unexpected error retrieving metrics: {e}") return format_api_error(500, str(e)) - Function signature showing input parameter (simulation_id: str) and return type (Dict[str, Any]). The docstring describes the tool's purpose.
@mcp.tool() async def get_metrics(simulation_id: str, ctx: Optional[Context] = None) -> Dict[str, Any]: - analyze_traffic_simulation tool uses get_metrics internally to fetch metrics data for analysis.
@mcp.tool() async def analyze_traffic_simulation(simulation_id: str, region: str = "unknown", scenario: str = "unknown", time_range: str = "unknown", ctx: Optional[Context] = None) -> Dict[str, Any]: """Conducts comprehensive analysis on simulation results, providing insights on traffic patterns, bottlenecks, and optimization opportunities for the specified parameters.""" try: if not simulation_id: return format_api_error(400, "simulationId required") async with await get_http_client() as client: api_client = FujitsuSocialDigitalTwinClient(client) metrics_result = await api_client.get_metrics(simulation_id) - compare_scenarios tool uses get_metrics internally twice to fetch metrics for two scenarios being compared.
@mcp.tool() async def compare_scenarios(simulation_id1: str, simulation_id2: str, scenario1_name: str = "Scenario 1", scenario2_name: str = "Scenario 2", ctx: Optional[Context] = None) -> Dict[str, Any]: """Performs detailed comparative analysis between two simulation scenarios, highlighting differences in traffic flow, emissions, travel times, and other key metrics.""" try: if not simulation_id1 or not simulation_id2: return format_api_error(400, "Two simulation IDs required") async with await get_http_client() as client: api_client = FujitsuSocialDigitalTwinClient(client) metrics_result1 = await api_client.get_metrics(simulation_id1) metrics_result2 = await api_client.get_metrics(simulation_id2)