onshape-mcp

onshape-mcp

Enables Claude Code to drive OnShape CAD through the REST API for parametric modeling, FeatureScript queries, and STL export/verification.

Category
访问服务器

README

onshape-mcp

MCP server that drives OnShape CAD from Claude Code: parametric modeling (sketches, extrudes, revolves, fillets, patterns), FeatureScript queries, and STL export/verification — via the OnShape REST API.

One-time setup

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)

Why --no-editable everywhere? macOS asynchronously marks files under .venv with the hidden flag here, and Python ≥3.13.8 skips hidden .pth files — editable installs silently stop importing minutes after a sync. Non-editable installs don't use .pth and are immune.

Credentials

API keys come from https://dev-portal.onshape.com/keys (an access key + secret key pair). Credentials live ONLY in ~/.config/onshape-mcp/.env, created by onshape-mcp setup with permissions 600 (owner read/write only) — never in project folders, never committed, never printed. See .env.example for the variable names; the process environment (ONSHAPE_ACCESS_KEY / ONSHAPE_SECRET_KEY) takes precedence over the file if both exist.

Per-project registration

From the CAD project folder where you want the server available (replace /path/to/onshape-mcp with wherever you cloned this repo):

/path/to/onshape-mcp/install.sh

or equivalently:

claude mcp add --scope project onshape -- \
  uv run --quiet --no-editable --project /path/to/onshape-mcp onshape-mcp

Or register it by hand in the project's .mcp.json:

{
  "mcpServers": {
    "onshape": {
      "command": "uv",
      "args": ["run", "--quiet", "--no-editable", "--project", "/path/to/onshape-mcp", "onshape-mcp"]
    }
  }
}

(--project, not --directory: the server resolves this repo's venv but keeps the caller's cwd. File-path tool params should be absolute paths regardless.) Project-scoped servers show "Pending approval" on the first interactive session — approve when prompted.

Usage cheatsheet (for the LLM driving the tools)

Typical build flow

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]

Iron rules

  1. Transient IDs go stale after ANY mutation. Always call find_entities immediately before the tool call that consumes the ids. Feature IDs (from create_sketch/extrude/...) are stable — prefer them where accepted (extrude regions, pattern seeds, boolean bodies).
  2. Units: tool params and outputs are inches by default (units param to change). Dimension strings pass through: "1.53 in", "25 mm", "#wall_thk * 2". Angles are degrees. eval_featurescript raw results are METERS/radians.
  3. featureStatus is the regen feedback loop: OK proceed; ERROR means the feature was added but failed — fix parameters via update_feature or delete_feature and retry. Check it after every modeling call.
  4. extrude REMOVE subtracts from ALL solids in the studio (defaultScope). Keep one part per studio unless you intend that.
  5. One closed profile per sketch keeps extrude region selection unambiguous.
  6. File paths must be ABSOLUTE (the server's cwd is not the project's).
  7. Be frugal: ~2,500 API calls/YEAR. Don't poll, don't re-list needlessly; analyze_stl/compare_stl cost zero calls.

Quota warning

OnShape EDU/Free accounts have an annual API quota (~2,500 calls/user/year); exhaustion returns 402 and no backoff fixes it. This server keeps a persistent call counter at ~/.config/onshape-mcp/call_log and logs a running total to stderr. Monitor usage in OnShape under My Account → Developer.

Development

uv run --no-editable pytest          # offline tests (no API calls, no credentials needed)
uv run --no-editable onshape-mcp doctor

License

MIT — see LICENSE.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选