flexsim_get_statistics
Retrieve simulation statistics and performance metrics from FlexSim models to analyze manufacturing and warehouse digital twin results.
Instructions
Get simulation statistics and performance metrics.
Tool call template
This tool declares no required parameters. Add optional parameters from the input schema as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {},
"name": "flexsim_get_statistics"
}
}Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- mcp_server/flexsim_mcp.py:486-504 (handler)The main implementation of flexsim_get_statistics tool. It retrieves simulation performance metrics including current time, run speed, number of objects, and events processed by evaluating a FlexScript against the FlexSim controller.
@mcp.tool() async def flexsim_get_statistics() -> str: """Get simulation statistics and performance metrics.""" try: controller = await get_controller() stats_script = """ { "time": getmodeltime(), "run_speed": get(runspeed()), "objects": Model.subnodes.length, "events": geteventsprocessed() } """ result = controller.evaluate(stats_script) return f"Statistics:\n```json\n{result}\n```" except Exception as e: return format_error(e) - mcp_server/flexsim_mcp.py:486-487 (registration)The tool is registered with the MCP server using the @mcp.tool() decorator, which automatically makes it available to MCP clients.
@mcp.tool() async def flexsim_get_statistics() -> str: - mcp_server/flexsim_mcp.py:129-140 (helper)Helper function format_error() used by flexsim_get_statistics to provide user-friendly error messages when exceptions occur.
def format_error(e: Exception) -> str: """Format exception as user-friendly error message.""" msg = str(e) if "not found" in msg.lower(): return f"Not found: {msg}" elif "syntax" in msg.lower(): return f"FlexScript syntax error: {msg}" elif "license" in msg.lower(): return f"License error: {msg}" elif "permission" in msg.lower(): return f"Permission denied: {msg}" return f"Error: {msg}" - mcp_server/flexsim_mcp.py:147-155 (helper)Helper function get_controller() used by flexsim_get_statistics to obtain or create the FlexSim controller instance with async locking for thread safety.
async def get_controller(): """Get or create the FlexSim controller instance.""" global _controller async with _controller_lock: if _controller is None: _controller = await launch_flexsim() return _controller