Skip to main content
Glama
SethGame

FlexSim MCP Server

by SethGame

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
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • 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)
  • 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())
  • 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)
  • 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
  • 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}"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/SethGame/mcp_flexsim'

If you have feedback or need assistance with the MCP directory API, please join our Discord server