flexsim_open_model
Open FlexSim simulation model files to analyze manufacturing and warehouse digital twins, run parameter studies, and manipulate models in real-time.
Instructions
Open a FlexSim model file.
Args:
model_path: Path to .fsm or .fsx file
Example:
model_path="C:/Models/warehouse.fsm"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| params | Yes |
Implementation Reference
- mcp_server/flexsim_mcp.py:223-243 (handler)Main handler function for flexsim_open_model tool. Uses @mcp.tool() decorator, gets FlexSim controller, opens the model file asynchronously, and returns formatted result with model name and time.@mcp.tool() async def flexsim_open_model(params: OpenModelInput) -> str: """Open a FlexSim model file. Args: model_path: Path to .fsm or .fsx file Example: model_path="C:/Models/warehouse.fsm" """ try: controller = await get_controller() loop = asyncio.get_event_loop() await loop.run_in_executor(None, controller.open, params.model_path) model_name = Path(params.model_path).stem time = controller.time() return f"✓ Opened: {model_name}\nTime: {format_time(time)}" except Exception as e: return format_error(e)
- mcp_server/flexsim_mcp.py:67-79 (schema)Input validation schema for flexsim_open_model. Uses Pydantic BaseModel to validate model_path is a non-empty string with .fsm or .fsx extension and that the file exists.class OpenModelInput(BaseModel): """Input for opening a model.""" model_path: str = Field(..., min_length=1) @field_validator("model_path") @classmethod def validate_path(cls, v: str) -> str: path = Path(v) if path.suffix.lower() not in [".fsm", ".fsx"]: raise ValueError("Model must be .fsm or .fsx file") if not path.exists(): raise ValueError(f"File not found: {v}") return str(path.resolve())
- mcp_server/flexsim_mcp.py:216-217 (registration)FastMCP server instance creation where tools are registered. The flexsim_open_model handler is registered via @mcp.tool() decorator on line 223.mcp = FastMCP("flexsim_mcp", lifespan=lifespan)
- mcp_server/flexsim_mcp.py:147-154 (helper)Controller management helper that lazily initializes FlexSim controller on first use, ensuring singleton pattern with async lock protection.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
- mcp_server/flexsim_mcp.py:119-140 (helper)Utility functions used by flexsim_open_model: format_time() converts seconds to human-readable format, format_error() creates user-friendly error messages from exceptions.def format_time(seconds: float) -> str: """Format simulation time as human-readable string.""" if seconds < 60: return f"{seconds:.2f}s" elif seconds < 3600: return f"{seconds/60:.2f}m" else: return f"{seconds/3600:.2f}h" 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}"