create_model
Create a new system dynamics model by specifying simulation time range, step size, integration method, and time units.
Instructions
Create a new Stella model with specified time settings
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | Model name | |
| start | No | Simulation start time | |
| stop | No | Simulation stop time | |
| dt | No | Time step | |
| method | No | Integration method (Euler or RK4) | Euler |
| time_units | No | Time units | Years |
Implementation Reference
- stella_mcp/server.py:227-237 (handler)The handler function for the 'create_model' tool. It creates a new StellaModel instance with the given name and simulation settings (start, stop, dt, method, time_units), stores it in the global _current_model variable, and returns a confirmation message.
if name == "create_model": _current_model = StellaModel(name=arguments["name"]) _current_model.sim_specs.start = arguments.get("start", 0) _current_model.sim_specs.stop = arguments.get("stop", 100) _current_model.sim_specs.dt = arguments.get("dt", 0.25) _current_model.sim_specs.method = arguments.get("method", "Euler") _current_model.sim_specs.time_units = arguments.get("time_units", "Years") return [TextContent( type="text", text=f"Created model '{arguments['name']}' with time range {_current_model.sim_specs.start}-{_current_model.sim_specs.stop}, dt={_current_model.sim_specs.dt}" )] - stella_mcp/server.py:94-107 (schema)The tool registration with input schema for 'create_model'. Defines the input parameters: name (required), start, stop, dt, method, and time_units (all with defaults).
name="create_model", description="Create a new Stella model with specified time settings", inputSchema={ "type": "object", "properties": { "name": {"type": "string", "description": "Model name"}, "start": {"type": "number", "description": "Simulation start time", "default": 0}, "stop": {"type": "number", "description": "Simulation stop time", "default": 100}, "dt": {"type": "number", "description": "Time step", "default": 0.25}, "method": {"type": "string", "description": "Integration method (Euler or RK4)", "default": "Euler"}, "time_units": {"type": "string", "description": "Time units", "default": "Years"}, }, "required": ["name"], }, - stella_mcp/xmile.py:114-125 (helper)The StellaModel class that is instantiated by the create_model handler. The __init__ method creates a new model with given name, generates a UUID, initializes empty collections for stocks/flows/auxs/connectors, and creates default SimSpecs.
class StellaModel: """Represents a complete Stella system dynamics model.""" def __init__(self, name: str = "Untitled"): self.name = name self.uuid = str(uuid.uuid4()) self.sim_specs = SimSpecs() self.stocks: dict[str, Stock] = {} self.flows: dict[str, Flow] = {} self.auxs: dict[str, Aux] = {} self.connectors: list[Connector] = [] self._connector_uid = 0 - stella_mcp/xmile.py:104-112 (helper)The SimSpecs dataclass used to store simulation settings (start, stop, dt, method, time_units) that are set by the create_model handler.
@dataclass class SimSpecs: """Simulation specifications.""" start: float = 0 stop: float = 100 dt: float = 0.25 method: str = "Euler" time_units: str = "Years" - stella_mcp/server.py:50-218 (registration)The list_tools function that registers 'create_model' (and all other tools) with the MCP server via the @server.list_tools() decorator.
@server.list_tools() async def list_tools() -> list[Tool]: """List available tools.""" graphical_function_schema = { "type": "object", "description": "Graphical function (lookup table) definition", "properties": { "ypts": { "type": "array", "items": {"type": "number"}, "description": "Y values for the lookup table", }, "xscale": { "type": "object", "description": "X scale when x points are evenly spaced", "properties": { "min": {"type": "number"}, "max": {"type": "number"}, }, "required": ["min", "max"], }, "xpts": { "type": "array", "items": {"type": "number"}, "description": "Explicit X values (same length as ypts)", }, "yscale": { "type": "object", "description": "Optional Y scale for display", "properties": { "min": {"type": "number"}, "max": {"type": "number"}, }, "required": ["min", "max"], }, "type": { "type": "string", "description": "Graphical function type (e.g., continuous or discrete)", }, }, "required": ["ypts"], } return [ Tool( name="create_model", description="Create a new Stella model with specified time settings", inputSchema={ "type": "object", "properties": { "name": {"type": "string", "description": "Model name"}, "start": {"type": "number", "description": "Simulation start time", "default": 0}, "stop": {"type": "number", "description": "Simulation stop time", "default": 100}, "dt": {"type": "number", "description": "Time step", "default": 0.25}, "method": {"type": "string", "description": "Integration method (Euler or RK4)", "default": "Euler"}, "time_units": {"type": "string", "description": "Time units", "default": "Years"}, }, "required": ["name"], }, ), Tool( name="add_stock", description="Add a stock (reservoir) to the current model", inputSchema={ "type": "object", "properties": { "name": {"type": "string", "description": "Stock name"}, "initial_value": {"type": "string", "description": "Initial value (number or equation)"}, "units": {"type": "string", "description": "Units", "default": ""}, "non_negative": {"type": "boolean", "description": "Prevent negative values", "default": True}, "x": {"type": "number", "description": "X position (optional, auto-positioned if not specified)"}, "y": {"type": "number", "description": "Y position (optional, auto-positioned if not specified)"}, }, "required": ["name", "initial_value"], }, ), Tool( name="add_flow", description="Add a flow between stocks in the current model", inputSchema={ "type": "object", "properties": { "name": {"type": "string", "description": "Flow name"}, "equation": {"type": "string", "description": "Flow rate equation"}, "units": {"type": "string", "description": "Units", "default": ""}, "from_stock": {"type": "string", "description": "Source stock (null for external source)"}, "to_stock": {"type": "string", "description": "Destination stock (null for external sink)"}, "non_negative": {"type": "boolean", "description": "Prevent negative values", "default": True}, "x": {"type": "number", "description": "X position (optional, auto-positioned if not specified)"}, "y": {"type": "number", "description": "Y position (optional, auto-positioned if not specified)"}, "graphical_function": graphical_function_schema, }, "required": ["name", "equation"], }, ), Tool( name="add_aux", description="Add an auxiliary variable (parameter or intermediate calculation) to the current model", inputSchema={ "type": "object", "properties": { "name": {"type": "string", "description": "Variable name"}, "equation": {"type": "string", "description": "Equation or constant value"}, "units": {"type": "string", "description": "Units", "default": ""}, "x": {"type": "number", "description": "X position (optional, auto-positioned if not specified)"}, "y": {"type": "number", "description": "Y position (optional, auto-positioned if not specified)"}, "graphical_function": graphical_function_schema, }, "required": ["name", "equation"], }, ), Tool( name="add_connector", description="Add a connector (dependency arrow) between variables", inputSchema={ "type": "object", "properties": { "from_var": {"type": "string", "description": "Source variable name"}, "to_var": {"type": "string", "description": "Target variable name (the one using from_var)"}, }, "required": ["from_var", "to_var"], }, ), Tool( name="save_model", description="Save the current model to a .stmx file", inputSchema={ "type": "object", "properties": { "filepath": {"type": "string", "description": "Output file path (.stmx)"}, }, "required": ["filepath"], }, ), Tool( name="read_model", description="Read an existing .stmx file and load it as the current model", inputSchema={ "type": "object", "properties": { "filepath": {"type": "string", "description": "Path to .stmx file"}, }, "required": ["filepath"], }, ), Tool( name="validate_model", description="Validate the current model for errors and warnings", inputSchema={ "type": "object", "properties": {}, }, ), Tool( name="list_variables", description="List all variables (stocks, flows, auxiliaries) in the current model", inputSchema={ "type": "object", "properties": {}, }, ), Tool( name="get_model_xml", description="Get the XMILE XML representation of the current model (for preview)", inputSchema={ "type": "object", "properties": {}, }, ), ]