SolidWorks MCP
Connects to SolidWorks 2022 over COM to run, test, and auto-fix VBA macros, returning structured diagnostics for iterative correction by Claude.
README
SolidWorks MCP — run, test & auto-fix VBA macros
An MCP server that connects to a running SolidWorks 2022 over COM (pywin32),
runs your VBA macros (or inline VBA), inspects the resulting model, and returns
structured diagnostics so Claude can fix errors and re-run until the model
builds clean. It also ships an API-documentation pipeline that renders the
JavaScript-only help.solidworks.com/2022 pages headlessly and extracts the
method/enum facts that keep generated code correct.
Built to pair with the solidworks-vba skill: the skill writes verified-style
macros; this server runs, tests and repairs them.
How it works
Claude (+ solidworks-vba skill)
│ writes / fixes VBA
▼
run_and_verify ──► COM worker thread (STA) ──► SolidWorks 2022
│ │
│ ◄── verdict: ran? rebuild errors? ◄───────┘
▼ errored features? VBA error?
if not success: read errors, regenerate, call again (Claude-driven loop)
- Inline VBA is written to a temporary
.swband executed withRunMacro2(SolidWorks compiles.swbtext on the fly — no.swpauthoring, no VBA trust-access setting needed). - All COM access runs on one STA worker thread (COM objects are apartment-bound).
- Generated/automated macros use a silent log (
SWMCP_Log) instead ofMsgBox, and a dialog watchdog auto-dismisses stray modal dialogs so a macro can never deadlock the server. - The server never edits your VBA. It returns rich errors; Claude fixes them.
Requirements
- Windows + SolidWorks 2022 (COM ProgID
SldWorks.Application). - Python 3.10+.
- A default part/assembly/drawing template configured in SolidWorks (Tools ▸ Options ▸ Default Templates) — macros abort cleanly if none is set.
Install
pip install -e .
python -m playwright install chromium # one-time, for the docs pipeline
Register with Claude Code
Already registered at user scope during setup:
claude mcp add solidworks -s user -- C:/Python313/python.exe -m sw_mcp.server
Or, for a project-scoped, shareable config, drop a .mcp.json in the project
root (see install/register-mcp.md). Confirm with
claude mcp list (look for solidworks: ... ✓ Connected).
Tools
Connection — sw_status
Execute & verify
run_macro(path, module, procedure)— run an existing.swp/.swb.run_vba(code, procedure, module)— run an inline VBA string.run_and_verify(code | macro_path, …)— run → rebuild → scan → one verdict. The auto-fix-loop primitive.
Diagnostics — rebuild_model, get_build_errors, get_feature_tree,
get_mass_properties, get_bounding_box, capture_screenshot
Documents — new_document, open_model, save_model, close_model,
export_file (STEP/IGES/STL/X_T/PDF/PNG by extension)
Feature generators (verified-style VBA, each built → run → rebuilt → error-scanned):
create_extrusion, create_cylinder, create_fillet, create_chamfer,
create_shell, create_draft, create_rib (L-bracket + gusset),
create_revolve (tube), create_sweep (swept groove), create_loft (lofted cut),
create_hole_wizard (metric counterbore), create_thread (real cut thread),
create_spring (helix + sweep), create_linear_pattern, create_mirror,
create_circular_pattern, create_assembly (2 components fully mated).
Surface modeling: create_surface_extrude, create_surface_planar,
create_surface_revolve, create_surface_thicken (surface→solid).
Sheet metal: create_sheet_base_flange (flat plate), create_sheet_lbracket
(bent, real bend). Extend by adding builders to feature_tools.py (see below).
Pattern variants not yet given a one-call tool (curve/sketch/table/fill), sheet-metal
edge flange/hem/miter, and any other feature are fully buildable via run_vba + the
solidworks-vba skill + the auto-fix loop.
Self-improving knowledge base — learn_rule, list_rules. Every fixed error
becomes a persistent rule (resources/knowledge/rules.json, human-readable
LESSONS.md). On failure, run_and_verify returns suggested_fixes matched from
past rules, so the same mistake is never solved twice.
API docs — docs_lookup_method(interface, method),
docs_lookup_enum(enum_name), docs_get(url). Read the remarks field — it
holds the selection-mark/precondition details that separate working from
crashing code.
The auto-fix loop
- Claude writes a macro (via the
solidworks-vbaskill) and callsrun_and_verify. - The verdict comes back:
{success, ran, run_error, log[], log_errors[], errors[], errored_features[], suppressed_features[], feature_count}. - If
success == false, Claude readslog_errors/errors(and looks up the exact API viadocs_lookup_method), regenerates the corrected VBA, and callsrun_and_verifyagain — untilsuccess == true.
Writing more feature generators
Generators emit VBA in the verified solidworks-vba style and run through
run_and_verify. Two non-negotiable rules for inline .swb code (learned
the hard way — see src/sw_mcp/vba/helpers.vba):
- Never test an API boolean with bitwise
If Not x. In an on-the-fly.swb, APIVARIANT_BOOLreturns arrive as+1, and VBA'sNotis bitwise (Not 1 = -2, truthy). Always writeIf x = False Then. Object checks (Is Nothing) are fine. Create*Rectanglereturns a Variant array, not an object. Capture withDim v As Variant: v = ...and checkIsArray(v)— neverSet seg = …(raises run-time error 424).
Add a build_<feature>() to feature_tools.py (reuse assemble_part_macro)
and a thin @mcp.tool() wrapper in server.py.
Diagnostic scripts
scripts/ contains the standalone spikes used to validate each layer
(spike_connect, spike_runmacro, spike_build, spike_autofix, …). They are
handy for debugging the COM link without going through the MCP transport.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。