onshape-mcp
onshape-mcp
MCP 服务器,通过 Claude Code 驱动 OnShape CAD:参数化建模(草图、拉伸、旋转、圆角、阵列)、FeatureScript 查询,以及 STL 导出/验证——均通过 OnShape REST API 完成。
一次性配置
uv sync --no-editable
uv run --no-editable onshape-mcp setup # writes ~/.config/onshape-mcp/.env (chmod 600); no-op if it exists
uv run --no-editable onshape-mcp doctor # auth smoke test against the live API (4 calls)为什么处处使用
--no-editable? macOS 会异步地将.venv下的文件标记为hidden标志,而 Python ≥3.13.8 会跳过隐藏的.pth文件——因此,可编辑安装在同步后的几分钟内会静默地停止导入。非可编辑安装不使用.pth,所以不受影响。
Related MCP server: SolidWorks MCP Server
凭据
API 密钥来自 https://dev-portal.onshape.com/keys(一个访问密钥与一个机密密钥配对)。凭据只存放在 ~/.config/onshape-mcp/.env 中,由 onshape-mcp setup 创建,权限为 600(仅属主可读/写)——绝不放在项目文件夹中,绝不提交,绝不打印。变量名参见 .env.example;如果环境变量和文件同时存在,则进程环境变量(ONSHAPE_ACCESS_KEY / ONSHAPE_SECRET_KEY)优先于文件。
按项目注册
如果你希望该服务器可用的 CAD 项目文件夹中(将 /path/to/onshape-mcp 替换为你克隆此仓库的位置):
/path/to/onshape-mcp/install.sh或等效地:
claude mcp add --scope project onshape -- \
uv run --quiet --no-editable --project /path/to/onshape-mcp onshape-mcp也可以手动在项目的 .mcp.json 中注册:
{
"mcpServers": {
"onshape": {
"command": "uv",
"args": ["run", "--quiet", "--no-editable", "--project", "/path/to/onshape-mcp", "onshape-mcp"]
}
}
}(--project,不是 --directory:服务器会解析此仓库的 venv,但保留调用方的当前工作目录。文件路径工具参数应始终使用绝对路径。)
项目级服务器在首次交互式会话中会显示 "Pending approval"——按提示批准即可。
用法速查表(供使用工具的 LLM 参考)
典型构建流程
create_document (parentId = folder id) -> documentId, workspaceId, partStudioElementId
import_cad (ABSOLUTE path to .zip/STEP) -> foreign CAD into an existing workspace [async, +quota]
set_variable (optional, e.g. wall_thk) -> use "#wall_thk" in later expressions
create_sketch (plane {"default":"TOP"}) -> featureId [one closed profile per sketch]
extrude (sketchFeatureId, NEW, depth) -> base solid
create_sketch + extrude REMOVE THROUGH_ALL [holes: skip native hole feature]
find_entities (EDGE, radiusBetween) -> transient ids for fillet/chamfer
fillet_or_chamfer (entityIds) -> check featureStatus == OK after EVERY feature
pattern / revolve / boolean_parts as needed
export_stl (ABSOLUTE path) -> compare_stl(candidate, reference) [mesh: 3D-print, verify]
export_step (ABSOLUTE path) -> editable STEP B-rep solid [CAD/prototyping; async, +quota]铁律
瞬态 ID 会在任何修改之后失效。 始终在最终的这些 ID 的工具调用之前先调用
find_entities。特征 ID(来自 create_sketch/extrude/...)是稳定的——在可接受的地方优先使用它们(拉伸区域、阵列源、布尔实体)。单位:工具参数和输出默认为英寸(使用
units参数更改)。尺寸字符串原样传递:"1.53 in"、"25 mm"、"#wall_thk * 2"。角度使用度。eval_featurescript的原始结果是米/弧度。featureStatus 是实体生成反馈循环:
OK即可继续;ERROR表示特征已添加但失败——通过update_feature或delete_feature修复参数并重试。每次建模调用后均检查它。extrude REMOVE 会从 studio 中的全部实体(defaultScope)中减去, 除非是你有意而为,否则每个 studio 保持一个实体。
每个草图只保留一个闭合轮廓,这样拉伸区域的选择就不会有歧义。
文件路径必须是绝对路径(服务器的当前工作目录不是项目的)。
要节约:每年约 2,500 次 API 调用。不要轮询,不要无谓地重复列取;
analyze_stl/compare_stl不消耗调用。
配额警告
OnShape EDU/免费账户有年度 API 配额(约 2,500 次调用/用户/年);配额用完会返回 402,退避无法解决。该服务器在 ~/.config/onshape-mcp/call_log 中维护一个持久的调用计数器,并将累计总数记录到 stderr。在 OnShape 中,可在 My Account → Developer 下监控使用情况。
开发
uv run --no-editable pytest # offline tests (no API calls, no credentials needed)
uv run --no-editable onshape-mcp doctor许可证
MIT —— 参见 LICENSE。
This server cannot be deployed
Maintenance
Related MCP Connectors
CAD in ChatGPT and Claude: editable parts, STEP/STL/drawings, in-chat 3D, automatic checks.
Parametric 3D CAD for AI agents: build print-ready parts, check them, export STL, 3MF or STEP.
Work with your DealSharp negotiation projects, documents and tools from Claude.
Connect Claude to your Platform7n workspaces: chat, links, work and decks. One-click OAuth.
Related MCP Servers
- FlicenseBqualityAmaintenanceEnables programmatic CAD modeling with Onshape's REST API, offering 45 tools for parametric sketches, feature management, assemblies, analysis, variables, and exports.48162-
- FlicenseNot gradedqualityDmaintenanceEnables Claude to create and manipulate SolidWorks CAD models through natural language commands, automating part creation, sketching, and extrusion.10-
- AlicenseBqualityCmaintenanceEnables OpenAI Codex to drive real Onshape parametric CAD via 69 tools for documents, sketches, features, assemblies, parametric updates, FeatureScript, vision, and export.69MIT
- AlicenseAqualityBmaintenanceEnables AI assistants to drive Onshape CAD with 87 tools for documents, part studios, sketching, solid features, assemblies, drawings, measurement, and export, including zero-configuration browser sign-in.93707 npm5MIT