Skip to main content
Glama
SolidWorks MCP

SolidWorks MCP

by Sangpaa

run_python

Runs Python on the server's live SolidWorks COM connection to handle modeling work no dedicated tool covers, reusing persisted variables across calls and returning the result or a traceback.

Instructions

Run Python on the server's own SolidWorks connection, for work no tool covers.

Predefined: sw (ISldWorks), model (current/active document, IModelDoc2), mod (interfaces: wrap(obj, mod.IAssemblyDoc), mod.IComponent2, mod.IFeature, mod.IMate2, ...), wrap, session, math, np. Variables persist between calls: build a component map or face cache once and reuse it (cleared when SolidWorks was restarted). COM runs with CommandInProgress set, ~25x faster than a separate script. Returns the final expression's value (or result) and printed output; a failure returns the traceback. Nothing is rolled back. A modal dialog fails the call within seconds naming it: see answer_dialog.

The script stops with an error naming its line when it runs longer than time_limit_s, grows the server's memory by more than memory_limit_mb, or on stop_python. Bound every loop over the feature tree or sub-features: a loop that never ends holds every other tool.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "code": "<code>"
    },
    "name": "run_python"
  }
}

Input Schema

NameRequiredDescriptionDefault
codeYes
time_limit_sNo
memory_limit_mbNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv0.21.0

TDQS

A4.6/5.0
Behavior5/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations exist, so the description carries the full burden and does so thoroughly: no rollback on failure, traceback returned, modal dialogs fail the call within seconds, COM runs with CommandInProgress (~25x faster), and variables persist across calls until SolidWorks restarts. It also discloses the resource enforcement semantics (error naming the offending line on time/memory exceedance or stop_python) and the risk that an unbounded loop holds every other tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Front-loaded with purpose, then layered into predefined symbols, state persistence, performance, return values, and limits — each line carrying distinct operational information. Dense and parenthesis-heavy but no sentence is filler.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a high-autonomy arbitrary-code tool with no annotations and no output schema, it covers return semantics ('final expression's value (or `result`) and printed output'), failure mode, state lifetime, resource limits, and the global side effect on other tools. Nothing an agent needs to call it safely is missing.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

At 0% schema description coverage the description must compensate, and it explains what time_limit_s and memory_limit_mb actually do (abort with an error naming the line) rather than just naming them. It does not restate the defaults or units, and describes the predefined namespaces (sw, model, mod, wrap, session, math, np) that make the `code` parameter usable, though it never explicitly defines `code` as the script body.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Opens with a specific verb and execution context ('Run Python on the server's own SolidWorks connection') and immediately scopes it as an escape hatch 'for work no tool covers', which distinguishes it from the many add_*/add_* operation siblings.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

States the selection rule clearly (only when no dedicated tool covers the work) and routes two adjacent cases to siblings: modal dialogs go to answer_dialog, cancellation via stop_python. It does not spell out the inverse explicitly (prefer the specialized add_* tools for routine modeling), which is left implicit in 'work no tool covers'.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.