set_parameters
Set multiple global parameters on a shared server-side model in COMSOL Multiphysics for collaborative modeling.
Instructions
Set multiple global parameters on the selected server-side model.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| parameters_json | Yes |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| result | Yes |
Implementation Reference
- comsol_mcp/mcp_server.py:710-731 (handler)Definition of the 'set_parameters' MCP tool. Decorated with @mcp.tool(), it takes a JSON string of parameters, parses them, and sets each on the COMSOL model via model.java.param().set(name, expression). Returns updated parameters and count.
@mcp.tool() def set_parameters(parameters_json: str) -> str: """Set multiple global parameters on the selected server-side model.""" def _impl() -> dict[str, Any]: model = _require_model() parsed = json.loads(parameters_json) if not isinstance(parsed, list): raise ValueError("parameters_json must be a JSON array.") updated = [] for item in parsed: if not isinstance(item, dict): raise ValueError("Each parameter entry must be an object.") name = str(item.get("name", "")).strip() expression = str(item.get("expression", "")).strip() if not name: raise ValueError("Parameter name is required.") model.java.param().set(name, expression) updated.append({"name": name, "expression": expression}) return {"updated": updated, "count": len(updated)} return _run_tool("set_parameters", _impl) - comsol_mcp/mcp_server.py:731-731 (registration)Registration call: return _run_tool('set_parameters', _impl) — triggers the tool via the runtime lock and error handling framework.
return _run_tool("set_parameters", _impl) - comsol_mcp/mcp_server.py:494-503 (helper)_run_tool helper — wraps the tool callback with logging, a runtime lock, error handling, and result formatting.
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-492 (helper)_tool_result helper — formats the tool result JSON payload with success, data, error, server status, and appends to operations log.
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)