Skip to main content
Glama
SethGame

FlexSim MCP Server

by SethGame

flexsim_evaluate

Execute FlexScript code to analyze and manipulate FlexSim simulation models, enabling digital twin analysis, parameter studies, and real-time model control.

Instructions

Execute FlexScript code.

Args:
    script: FlexScript code to evaluate

Examples:
    script='Model.find("Queue1").subnodes.length'  # Get queue content
    script='getmodeltime()'  # Get simulation time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
paramsYes

Implementation Reference

  • Main handler function for flexsim_evaluate tool. Decorated with @mcp.tool() which also serves as registration. Executes FlexScript code using the FlexSim controller's evaluate method and returns results with error handling.
    @mcp.tool()
    async def flexsim_evaluate(params: EvaluateScriptInput) -> str:
        """Execute FlexScript code.
    
        Args:
            script: FlexScript code to evaluate
    
        Examples:
            script='Model.find("Queue1").subnodes.length'  # Get queue content
            script='getmodeltime()'  # Get simulation time
        """
        try:
            controller = await get_controller()
            result = controller.evaluate(params.script)
    
            return f"Result: {result}"
        except Exception as e:
            return f"Script error: {format_error(e)}"
  • Input schema for the flexsim_evaluate tool using Pydantic BaseModel. Defines the script parameter with validation (required, min_length=1, max_length=10000).
    class EvaluateScriptInput(BaseModel):
        """Input for evaluating FlexScript."""
        script: str = Field(..., min_length=1, max_length=10000)
  • Helper function that formats exceptions into user-friendly error messages. Used by flexsim_evaluate to provide clear error feedback for script execution failures.
    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}"
  • Helper function that manages the FlexSim controller singleton instance. Used by flexsim_evaluate to get or create the controller for executing FlexScript commands.
    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

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