run_feature
Execute a geometry or mesh sequence on a COMSOL server-side model using collection and tag identifiers.
Instructions
Run a geometry or mesh sequence on the selected server-side model.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | ||
| tag | Yes | ||
| component | No | comp1 |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- comsol_mcp/mcp_server.py:877-892 (handler)Inner implementation function (_impl) that gets the current model, validates the collection type ('geometry' or 'mesh'), and calls .run() on the respective COMSOL Java sequence. Returns a dict with collection, component, and tag.
def _impl() -> dict[str, Any]: model = _require_model() comp = component.strip() or "comp1" seq_tag = tag.strip() kind = collection.strip().lower() if not seq_tag: raise ValueError("Feature tag is required.") if kind == "geometry": model.java.component(comp).geom(seq_tag).run() elif kind == "mesh": model.java.component(comp).mesh(seq_tag).run() else: raise ValueError('collection must be "geometry" or "mesh".') return {"collection": kind, "component": comp, "tag": seq_tag} return _run_tool("run_feature", _impl) - comsol_mcp/mcp_server.py:873-874 (registration)The @mcp.tool() decorator registers 'run_feature' as an MCP tool with parameters: collection (str), tag (str), component (str, default 'comp1').
@mcp.tool() def run_feature(collection: str, tag: str, component: str = "comp1") -> str: - comsol_mcp/mcp_server.py:874-874 (schema)Function signature defines the input schema: 'collection: str' (geometry or mesh), 'tag: str' (feature tag), 'component: str = "comp1"' (optional component tag).
def run_feature(collection: str, tag: str, component: str = "comp1") -> str: - comsol_mcp/mcp_server.py:494-502 (helper)The _run_tool helper wraps the _impl callback with logging, runtime locking, and error handling, returning a standardized JSON result via _tool_result.
def _run_tool(tool: str, callback) -> str: _setup_logging() with _runtime_lock: try: data = callback() return _tool_result(tool, True, data=data) except Exception as exc: logging.exception("Tool %s failed", tool) return _tool_result(tool, False, error=str(exc)) - comsol_mcp/mcp_server.py:320-332 (helper)The _require_model helper retrieves the current active COMSOL model or adopts one from the server, throwing an error if none is available.
def _require_model() -> Any: global _current_model _require_client() if _current_model is None: adopted = _adopt_model_by_name("") if adopted is not None: _set_current_model(adopted, origin="adopted") else: raise RuntimeError( "No current model is selected. Use model_create() or model_load(), " "or connect to a server with exactly one loaded model." ) return _current_model