openvsp.modify
Apply scripted parameter edits to an OpenVSP model, adjusting geometry with set commands and returning the generated script path.
Instructions
Apply scripted parameter edits to an OpenVSP model without running VSPAero. Use set_commands to adjust geometry; returns the generated script path.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| request | Yes |
Implementation Reference
- src/openvsp_mcp/tool.py:29-37 (handler)MCP handler function for openvsp.modify tool, registered with @app.tool and delegates to execute_openvsp with run_vspaero=False.@app.tool( name="openvsp.modify", description=( "Apply scripted parameter edits to an OpenVSP model without running VSPAero. " "Use set_commands to adjust geometry; returns the generated script path."), meta={"version": "0.1.0", "categories": ["geometry"]}, ) def modify(request: OpenVSPRequest) -> OpenVSPResponse: return execute_openvsp(request.model_copy(update={"run_vspaero": False}))
- src/openvsp_mcp/core.py:29-70 (helper)Core execution logic for OpenVSP modifications and optional VSPAero run, invoked by the tool handler.def execute_openvsp(request: OpenVSPRequest) -> OpenVSPResponse: """Run OpenVSP (and optionally VSPAero) using the provided request.""" with tempfile.TemporaryDirectory(prefix="openvsp_mcp_") as tmpdir: workdir = Path(tmpdir) script_path = _write_script(request, workdir) try: result = subprocess.run( [OPENVSP_BIN, "-script", str(script_path)], check=False, capture_output=True, ) except FileNotFoundError as exc: # pragma: no cover raise RuntimeError("OpenVSP binary not found") from exc if result.returncode not in _OK_EXIT_CODES: message = result.stderr.decode("utf-8", errors="ignore").strip() if not message: message = result.stdout.decode("utf-8", errors="ignore").strip() or "OpenVSP script execution failed" raise RuntimeError(message) vspaero_output: str | None = None if request.run_vspaero: try: aero = subprocess.run( [VSPAERO_BIN, request.geometry_file, request.case_name], check=False, capture_output=True, ) except FileNotFoundError as exc: # pragma: no cover raise RuntimeError("VSPAero binary not found") from exc if aero.returncode != 0: message = aero.stderr.decode("utf-8", errors="ignore").strip() if not message: message = aero.stdout.decode("utf-8", errors="ignore").strip() or "VSPAero execution failed" raise RuntimeError(message) vspaero_output = str(Path(request.case_name).with_suffix(".adb")) return OpenVSPResponse(script_path=str(script_path), result_path=vspaero_output)
- src/openvsp_mcp/models.py:18-25 (schema)Pydantic input model (OpenVSPRequest) defining parameters for openvsp.modify tool calls.class OpenVSPRequest(BaseModel): """Parameters controlling geometry edits and optional VSPAero run.""" geometry_file: str = Field(..., description="Path to the .vsp3 file") set_commands: list[VSPCommand] = Field(default_factory=list, description="Commands to run") run_vspaero: bool = Field(True, description="Execute VSPAero after editing geometry") case_name: str = Field("case", description="Base name for generated results")
- src/openvsp_mcp/models.py:35-43 (schema)Pydantic output model (OpenVSPResponse) for openvsp.modify tool responses.class OpenVSPResponse(BaseModel): """Response object capturing generated paths.""" script_path: str = Field(..., description="Absolute path to the temporary script file") result_path: str | None = Field( None, description="Path to the generated VSPAero .adb file (if run_vspaero=True)", )
- src/openvsp_mcp/core.py:79-103 (helper)Generates the OpenVSP script file from set_commands and model path, used in execute_openvsp.def _write_script(request: OpenVSPRequest, working_dir: Path) -> Path: script_path = working_dir / "automation.vspscript" commands: Iterable[VSPCommand] = request.set_commands or [] script_lines = [ "// Auto-generated by openvsp-mcp", "void main() {", " ClearVSPModel();", f" ReadVSPFile(\"{request.geometry_file}\");", ] for command in commands: script_lines.append(f" {_ensure_statement(command.command)}") script_lines.extend( [ " Update();", f" SetVSP3FileName(\"{request.geometry_file}\");", f" WriteVSPFile(\"{request.geometry_file}\", SET_ALL);", "}", ] ) script_path.write_text("\n".join(script_lines) + "\n", encoding="utf-8") return script_path