Skip to main content
Glama
onshape-mcp

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]

铁律

  1. 瞬态 ID 会在任何修改之后失效。 始终在最终的这些 ID 的工具调用之前先调用 find_entities。特征 ID(来自 create_sketch/extrude/...)是稳定的——在可接受的地方优先使用它们(拉伸区域、阵列源、布尔实体)。

  2. 单位:工具参数和输出默认为英寸(使用 units 参数更改)。尺寸字符串原样传递:"1.53 in"、"25 mm"、"#wall_thk * 2"。角度使用度。eval_featurescript 的原始结果是米/弧度。

  3. featureStatus 是实体生成反馈循环:OK 即可继续;ERROR 表示特征已添加但失败——通过 update_feature 或 delete_feature 修复参数并重试。每次建模调用后均检查它。

  4. extrude REMOVE 会从 studio 中的全部实体(defaultScope)中减去, 除非是你有意而为,否则每个 studio 保持一个实体。

  5. 每个草图只保留一个闭合轮廓,这样拉伸区域的选择就不会有歧义。

  6. 文件路径必须是绝对路径(服务器的当前工作目录不是项目的)。

  7. 要节约:每年约 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。

Related MCP Connectors

Related MCP Servers

  • F
    license
    B
    quality
    A
    maintenance
    Enables programmatic CAD modeling with Onshape's REST API, offering 45 tools for parametric sketches, feature management, assemblies, analysis, variables, and exports.
    48
    162
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Enables Claude to create and manipulate SolidWorks CAD models through natural language commands, automating part creation, sketching, and extrusion.
    10
    -
  • A
    license
    B
    quality
    C
    maintenance
    Enables OpenAI Codex to drive real Onshape parametric CAD via 69 tools for documents, sketches, features, assemblies, parametric updates, FeatureScript, vision, and export.
    69
    MIT
  • A
    license
    A
    quality
    B
    maintenance
    Enables 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.
    93
    707 npm
    5
    MIT