delete_feature
Remove a specific geometry feature from a server-side COMSOL model by specifying component, geometry, and tag.
Instructions
Delete a geometry feature from the selected server-side model.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| component | Yes | ||
| geometry | Yes | ||
| tag | Yes | ||
| run_geometry | No |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- comsol_mcp/mcp_server.py:846-847 (registration)The @mcp.tool() decorator registers 'delete_feature' as an MCP tool with FastMCP.
@mcp.tool() def delete_feature(component: str, geometry: str, tag: str, run_geometry: bool = False) -> str: - comsol_mcp/mcp_server.py:847-870 (handler)The 'delete_feature' function (lines 847-870) is the handler. It defines an inner _impl() that gets the current model, resolves component/geometry/feature tag, removes the feature via feature_container.remove(feature_tag), optionally runs geometry, and returns the result. The _impl is wrapped by _run_tool() for consistent error handling and logging.
def delete_feature(component: str, geometry: str, tag: str, run_geometry: bool = False) -> str: """Delete a geometry feature from the selected server-side model.""" def _impl() -> dict[str, Any]: model = _require_model() comp = component.strip() or "comp1" geom = geometry.strip() or "geom1" feature_tag = tag.strip() if not feature_tag: raise ValueError("Feature tag is required.") feature_container = model.java.component(comp).geom(geom).feature() if feature_tag not in list(feature_container.tags()): raise LookupError(f'Feature "{feature_tag}" does not exist.') feature_container.remove(feature_tag) if run_geometry: model.java.component(comp).geom(geom).run() return { "component": comp, "geometry": geom, "tag": feature_tag, "run_geometry": bool(run_geometry), } return _run_tool("delete_feature", _impl) - comsol_mcp/mcp_server.py:494-502 (helper)The _run_tool helper wraps the handler callback with logging, lock management, error handling, and result formatting 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:467-491 (helper)The _tool_result helper formats the success/failure response JSON including tool name, timestamp, server status, data, and error info.
def _tool_result(tool: str, success: bool, data: dict[str, Any] | None = None, error: str = "") -> str: global _last_command, _last_error _last_command = tool _last_error = error payload = { "success": success, "tool": tool, "timestamp": time.time(), "datetime": _now_iso(), "server": _status_payload(), "data": data or {}, "error": error, "log_path": str(SERVER_LOG), "operations_path": str(OPERATIONS_FILE), } _append_operation( { "tool": tool, "success": success, "error": error, "data": data or {}, } ) _write_status({"last_command": tool, "last_error": error}) return _json(payload) - comsol_mcp/mcp_server.py:320-330 (helper)The _require_model helper ensures a server-side model is available before the feature deletion can proceed.
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."