Skip to main content
Glama
Mastercam MCP Server

Mastercam MCP Server

by FunSize77

Mastercam MCP Server

A Model Context Protocol server that lets AI agents drive Mastercam 2027: open parts, inspect geometry, build tools and toolpaths, regenerate, post G-code and produce setup sheets — in the Mastercam window in front of the user.

It is a standard MCP server, not tied to one AI vendor: it works with any MCP client (Claude Desktop, Claude Code, Cursor, VS Code, Windsurf, OpenAI Codex CLI, Gemini CLI, LM Studio, ...) and any model that can call tools, including local models (see examples/ollama_agent.py). Tested: Claude, and a 4B local Gemma model through Ollama.

Status: 1.0.2. Verified live on Mastercam 2027 Update 1 (29.1.193.0). See docs/FEATURES.md for the full feature map and roadmap (machine/control definitions, simulation, post editing, ...).

Architecture

MCP client ──stdio──> mastercam_mcp (Python, FastMCP)
                          │  JSON lines over a Windows named pipe
                          ▼
                Mastercam.exe ── McamMcp.dll (NET-Hook add-in, .NET 10)
                                  runs each command on Mastercam's UI thread
  • plugin/McamMcp — C# NET-Hook loaded by Mastercam. It serves two pipes: \\.\pipe\mastercam_mcp_<pid> (always, one per Mastercam process) and the shared \\.\pipe\mastercam_mcp (owned by the first Mastercam to start; the others take it over when it exits). A dialog watcher answers Mastercam message boxes that appear during a command (so a "Toolpath regeneration failed" box never hangs the agent) and returns their text to the client.

  • mastercam_mcp — the Python MCP server: tool definitions, path policy, launcher, setup-sheet generator and the run_job workflow.

Related MCP server: solidworks-mcp

Install

From the release package (testers)

Requirements: Windows, Mastercam 2027, Python 3.10+ (no .NET SDK). Unzip mastercam-mcp-<version>.zip, close Mastercam, then from that folder:

powershell -ExecutionPolicy Bypass -File .\install.ps1 -Startup -Client cursor,vscode

It installs the server, copies the prebuilt add-in (approve the UAC prompt, or run from an elevated PowerShell), sets the add-in to load with Mastercam and registers the server with the clients you name (claude-desktop, claude-code, cursor, vscode, windsurf, codex, gemini, lmstudio; each file is backed up first). install.ps1 -Uninstall removes it. See docs/TESTING.md for a first session and what to report.

From source

Requirements: Windows, Mastercam 2027, .NET 10 SDK, Python 3.10+. .\scripts\make-release.ps1 builds the release zip.

# 1. Python package
pip install -e .[test]

# 2. Build and install the add-in. Close Mastercam first (the DLL is locked while it runs).
#    Copying into C:\Program Files\mcam needs administrator rights: run from an elevated PowerShell,
#    or approve the UAC prompt. The script checks the installed DLL's hash and fails loudly if the copy did not happen.
.\scripts\install-plugin.ps1            # add -Startup to load the bridge every time Mastercam starts
.\scripts\install-plugin.ps1 -Uninstall

# 3. Check (with Mastercam running and the add-in loaded: Add-Ins > MCP Bridge)
python -m mastercam_mcp --check

Without -Startup, load the bridge per session from Add-Ins > MCP Bridge; launch_mastercam starts Mastercam and waits for the bridge.

MCP client configuration

The server is started by the client: command python, arguments -m mastercam_mcp. To register it:

python -m mastercam_mcp --configure cursor,vscode       # any of: claude-desktop, claude-code, cursor, vscode,
                                                         # windsurf, codex, gemini, lmstudio (backs up each file)
python -m mastercam_mcp --print-config                   # the common "mcpServers" JSON block, for any other client
python -m mastercam_mcp --print-config codex             # the block in that client's format

The common block (Claude Desktop, Cursor, Windsurf, Gemini CLI, LM Studio and most others):

{
  "mcpServers": {
    "mastercam": {
      "command": "python",
      "args": ["-m", "mastercam_mcp"],
      "env": { "MCAM_MCP_ALLOWED_DIRS": "C:\\CAM\\jobs" }
    }
  }
}

VS Code (mcp.json) uses "servers" with "type": "stdio"; Codex uses [mcp_servers.mastercam] in config.toml.

Fewer tools. Some clients cap the number of tools, and small models choose better from a short list. Set MCAM_MCP_TOOLS (or --tools) to core (about 25 tools, enough for a 2D part end to end), or to groups and tool names: core,planes,wireframe. Groups: session, files, part, wireframe, planes, setup, tools, toolpaths, edit, check, output, scripting. --configure ... --tools core writes it into the client config.

HTTP clients. For a client that connects to a URL instead of starting a program: python -m mastercam_mcp --http serves http://127.0.0.1:8765/mcp (--port to change). It listens on this PC only; there is no authentication, so do not expose it with --host unless a firewall or tunnel you control is in front of it.

Any model. examples/ollama_agent.py is a 90-line agent loop that connects a local Ollama model to the server, as a reference for other harnesses.

Environment variables

Variable

Default

Meaning

MCAM_MCP_PIPE

mastercam_mcp

Base pipe name (must match the add-in).

MCAM_MCP_PID

—

Pin the server to one Mastercam process (mastercam_mcp_<pid>). select_mastercam does the same at runtime.

MCAM_MCP_TIMEOUT

120

Default seconds per bridge call (long tools such as post/regenerate use more).

MCAM_MCP_ALLOWED_DIRS

—

;-separated folders. When set, every path read or written must be inside one of them.

MCAM_MCP_ALLOW_SCRIPTS

off

1 exposes execute_csharp (arbitrary C# inside Mastercam). Also --allow-scripts. The add-in accepts it only when Mastercam also runs with it set.

MCAM_MCP_NC_EXTENSIONS

—

Extra file extensions read_nc_file / check_nc_file may read (;-separated), if your post writes an unusual one.

MCAM_MCP_TOOLS

all

Tools to expose: all, core, or groups / tool names separated by commas (see above). Also --tools.

MASTERCAM_EXE

auto

Full path to Mastercam.exe if it is not in the standard location.

Tools

Area

Tools

Session

mastercam_status, select_mastercam, launch_mastercam, get_state

Guidance

knowledge (master guide, topics, search)

Files

open_file, new_file, save_file, export_file (STEP, Parasolid, ACIS, STL, DXF), screenshot

Part

get_part_info, get_extents, list_levels, list_geometry

Wireframe

create_geometry, delete_geometry, set_level

Planes

list_planes, create_plane, update_plane, set_planes (WCS, tool and construction planes, work offsets)

Setup

list_machine_groups, create_machine_group, set_output_folder, set_stock, create_toolpath_group, set_active_group

Tools

list_tools, list_library_tools, create_tool (22 tool types)

Toolpaths

create_facing, create_contour, create_pocket, create_drill, create_circle_mill, create_helix_bore, list_library_operations, import_operations

Edit

list_operations, update_operation, get_operation_parameters, set_operation_parameters, move_operations, copy_operations, delete_operations, regenerate_operations, get_cycle_time, operation_stats

Output

post_process, read_nc_file, check_nc_file, generate_setup_sheet, run_native_setup_sheet

Workflow

run_job (open → library ops → regenerate → save → post → setup sheet), prompt program_part

Scripting

execute_csharp (opt-in)

Notes for agents and integrators (the knowledge tool serves these and more to the agent):

  • Heights in linking are absolute unless the matching *_incremental flag is set (Mastercam's own default for new operations is incremental). For drilling, feed_plane is the R plane.

  • chain picks curves that lie flat in the operation's tool plane (plane, else the active one), at any depth. If they are at several depths the call is refused until you give chain.depth (a Z in that plane, or "all") or entity_ids. Closed chains run clockwise seen from the plane, so comp_side: left is outside and right is inside.

  • plane is the tool plane (top, front, ... or a plane name; on a horizontal machine front is usually B0). For holes, positions and bolt_circle are in that plane's coordinates.

  • bolt_circle is {diameter, count, start_angle, center, z} or a list of them. coolant is flood, mist, thru or off.

  • create_circle_mill plunges at the hole center: use it on pre-drilled holes. create_helix_bore cuts from solid.

  • Taps need threads in create_tool (threads per inch, or pitch in mm), otherwise they post a zero feed.

  • New operations take the tool's H/D numbers unless length_offset / diameter_offset are given.

  • Every create_* starts from the machine's default settings: Mastercam itself would copy the last operation of the same type (a plain drill after a tap came out as a tap). Only what you pass changes them.

  • Stock to leave is 0 unless given, and stepovers follow the tool (pocket 50%, facing 75%), so the depth asked for is the depth cut. Contour lead in/out lines and arcs are 100% of the tool diameter (lead to change them, lead: false for none).

  • post_errors: true from post_process / run_job: the post reported errors; do not run that NC file until they are explained.

  • check_nc_file reviews posted G-code (F0, spindle off while cutting, H/D vs tool, rapids into the stock zone, travel, program end) and lists each tool's Z range, feeds and speeds. run_job runs it on every NC file. It is not a simulation.

  • Mastercam cannot move an operation into another group, so move_operations with group_id copies and deletes: the operation gets a new id (new_ids in the result).

  • Facing across_overlap (default 50) / along_overlap (default 110) are percent of the tool diameter (Mastercam needs ≥ 50 to face a boundary). In set_operation_parameters, CutParams.AcrossOverlap/AlongOverlap are raw distances in part units.

  • get_operation_parameters dumps every parameter group of an operation; set_operation_parameters writes any of them by path ({"EntryHelix.MaxRadius": 0.05}), so the structured tools are never a ceiling.

  • Results may carry mastercam_messages — dialogs Mastercam showed and how the bridge answered them. A regenerated: false / warning result means the operation exists but has no toolpath; post_process reports such operations as dirty_operations.

Safety

  • Every toolpath produced by automation must be verified (simulation, backplot, review) before it runs on a machine.

  • Save As and run_job keep an existing .mcam unless overwrite is true. Posted NC files in the output folder are replaced.

  • With several Mastercam windows open, mastercam_status lists them and the agent must select_mastercam the right one.

  • execute_csharp is off by default, in both the MCP server and the Mastercam add-in. It is on only when MCAM_MCP_ALLOW_SCRIPTS=1 is set for both (as a user environment variable: setx MCAM_MCP_ALLOW_SCRIPTS 1, then restart Mastercam and the MCP client). Enable it only for trusted clients: it runs arbitrary code inside Mastercam.

  • Use MCAM_MCP_ALLOWED_DIRS to fence file access to job folders.

  • File tools only touch their own file types (Save As .mcam, exports, .png, .html; NC readers only NC extensions, extendable with MCAM_MCP_NC_EXTENSIONS). The add-in's pipe accepts only the same Windows user. --http listens on this PC only and rejects foreign Host headers and browser origins. See SECURITY.md.

Troubleshooting

Symptom

Fix

BridgeUnavailable: No bridge is listening

Start Mastercam and load Add-Ins > MCP Bridge (or install with -Startup).

Install says "Elevated copy failed"

The UAC prompt was declined or hidden. Run the script from an elevated PowerShell.

Install says "Mastercam is running"

Close every Mastercam window; the add-in DLL is locked while it runs.

A call timed out

Mastercam may be busy or showing a non-standard dialog. Look at its window; the command still runs and later calls continue normally.

Commands go to the wrong Mastercam

mastercam_status, then select_mastercam(pid), or set MCAM_MCP_PID.

version_warning in mastercam_status

The add-in and the server are different releases: close Mastercam and rerun install-plugin.ps1.

AmbiguousDepth from a create tool

Curves exist at several depths; pass chain.depth or chain.entity_ids.

Anything else

Bridge log: %LOCALAPPDATA%\McamMcp\bridge.log.

Development

python -m pytest              # protocol, server and workflow tests against a fake bridge (no Mastercam needed)
dotnet build plugin\McamMcp -c Release

License and trademarks

MIT (see LICENSE). Mastercam is a trademark of CNC Software, LLC. This project is independent and is not affiliated with or endorsed by CNC Software. It needs a licensed copy of Mastercam to do anything.

Available Tools

54 tools
check_nc_fileA
Read-only

Review posted G-code before it runs: F0 feeds, cutting with the spindle off, H/D numbers that do not match the tool, rapids into the stock zone, moves outside the machine travel, missing program end; plus each tool's Z range, feeds and speeds and the program extents. A review aid, not a simulation.

Inputs: path (required), stock_top_z, travel_limits.

copy_operationsA

Duplicate operations with their geometry; the copies are regenerated. Returns new_ids.

Inputs: ids (required), group_id, name_suffix.

create_circle_millA

Circle mill round holes at the given centers (best for pre-drilled holes; it plunges at the center). For counterbores or holes cut from solid use create_helix_bore.

Inputs: depth (required), tool_number (required), circle_diameter (required), name, +23 more.

create_contourB

Create and regenerate a 2D contour toolpath in the active machine group. Closed chains run clockwise, so comp_side left cuts outside and right cuts inside. Lead in/out arcs and lines are sized to the tool.

Inputs: depth (required), tool_number (required), lead, name, +17 more.

create_drillB

Create and regenerate a drill/peck/tap/bore toolpath. Give entity_ids, arc_diameter, positions and/or bolt_circle.

Inputs: depth (required), tool_number (required), name, peck, +19 more.

create_facingB

Create and regenerate a facing toolpath over the chained boundary (usually the part outline).

Inputs: depth (required), tool_number (required), name, chain, +16 more.

create_geometryA

Create wireframe (all or nothing). Returns the new entity ids per shape, ready for chain={"entity_ids": [...]} or drilling by entity_ids. Rectangles are lines (and corner arcs) in a closed loop.

Inputs: entities (required), z, color, level, +1 more.

create_helix_boreB

Helix bore counterbores / round holes from solid with an end mill (helix down, then a finish circle).

Inputs: depth (required), tool_number (required), circle_diameter (required), name, +21 more.

create_machine_groupB

Create a machine group (this selects the machine, control definition and post processor).

Inputs: product, machine_definition.

create_planeA

Create a work/tool plane, e.g. a fixture face with its own work offset. On a horizontal machine B0 is usually base front, B90 right, B180 back, B270 left: check against the machine before posting.

Inputs: name (required), set, base, origin, +2 more.

create_pocketB

Create and regenerate a 2D pocket (closed chains; chains inside others are islands).

Inputs: depth (required), tool_number (required), name, chain, +16 more.

create_toolA

Create a tool in the open part (units follow the part). Its rpm/feeds become the default for toolpaths that use it.

Inputs: type (required), diameter (required), rpm, feed, +13 more.

create_toolpath_groupA

Create a toolpath group (e.g. one per setup or fixture side) and make it active: new operations go there.

Inputs: name (required), machine_group_id.

delete_geometryA
Destructive

Delete entities from the open part (never files). Operations chained to them keep their old toolpath until regenerated: regenerate_operations and check them afterwards.

Inputs: ids, level.

delete_operationsC
Destructive

Delete operations by id.

Inputs: ids (required).

export_fileA

Export the part's geometry to a CAD file (e.g. STEP for a customer or a fixture designer). The open .mcam stays the current file.

Inputs: path (required), overwrite.

generate_setup_sheetB

Write a printable HTML setup sheet + operator run sheet (operations, tools, offsets, times, part image).

Inputs: output_path (required), notes, title, nc_files, +2 more.

get_cycle_timeB
Read-only

Estimated machining time per operation and in total (seconds).

Inputs: ids.

get_extentsB
Read-only

Bounding box of all geometry: min, max and size as [x, y, z].

Inputs: no named parameters.

get_operation_parametersB
Read-only

All parameter groups of an operation with current values (names usable in set_operation_parameters).

Inputs: id (required), path.

get_part_infoB
Read-only

Open file, units, geometry counts by type, bounding box, levels, machine groups and operation counts.

Inputs: no named parameters.

get_stateA
Read-only

What Mastercam is set to now: file, units, active machine/toolpath group, WCS / tool / construction planes (with work offsets), active level, selection count, operation and dirty-operation counts. Check it before creating geometry or operations: new operations go into the active group and take the current tool plane. The knowledge tool explains planes, chaining, linking and posting with measured facts.

Inputs: no named parameters.

import_operationsB

Import toolpath operations (with their tools and parameters) into the active machine group.

Inputs: path (required), ids, names, regenerate, +2 more.

knowledgeA
Read-onlyIdempotent

How to program Mastercam well with these tools: the master guide (default), one topic, or a search across all guides. Built from behaviour measured on Mastercam 2027.

Inputs: topic, search.

launch_mastercamA

Start Mastercam (if it is not running) and wait for the MCP Bridge add-in to answer.

Inputs: wait_seconds.

list_geometryB
Read-only

List geometry entities (ids, type, level; arc centers/radii, line endpoints, point positions).

Inputs: level, limit, types, selected_only.

list_levelsB
Read-only

Levels (layers) with names, entity counts and visibility.

Inputs: include_empty.

list_library_operationsB
Read-only

List the operations and toolpath groups stored in an operation library / other Mastercam file.

Inputs: path (required).

list_library_toolsB
Read-only

List the tools in a tool library or another Mastercam file.

Inputs: path (required).

list_machine_groupsB
Read-only

Machine groups with machine definition, NC output folder, and toolpath groups.

Inputs: no named parameters.

list_operationsC
Read-only

Operations in the Toolpaths Manager: id, name, type, tool, spindle/feeds, dirty/locked status.

Inputs: group_id.

list_planesB
Read-only

Planes in the part (origin, X/Y/Z axes in world, work offset) and which is the current WCS / tool / construction plane.

Inputs: no named parameters.

list_toolsB
Read-only

Tools defined in the current part (number, name, type, diameter, corner radius, lengths, offsets).

Inputs: group_id.

mastercam_statusA
Read-only

Start here. Is Mastercam running and is the MCP Bridge add-in answering? Returns versions, open file, units and, when several Mastercam windows are open, each instance so you can select_mastercam the right one. Before programming a part, read the knowledge tool's master guide (call knowledge with no arguments).

Inputs: no named parameters.

move_operationsB

Reorder operations (they keep their order among themselves). Returns the new order.

Inputs: ids (required), after, before, group_id.

new_fileA
Destructive

Start a new empty part. Unsaved changes in the current file are discarded.

Inputs: no named parameters.

open_fileA
Destructive

Open a part in Mastercam (unsaved changes in the current file are discarded unless merge=true).

Inputs: path (required), merge.

operation_statsB
Read-only

Per operation: toolpath extents (min/max in WCS and world, so deepest Z and XY reach) and cycle time.

Inputs: ids.

post_processB

Post-process toolpaths to G-code with the machine group's post. Regenerates dirty operations first.

Inputs: ids, also_nci, output_dir.

read_nc_fileA
Read-only

Read (part of) a posted NC program or other text output to verify it.

Inputs: path (required), max_lines, start_line.

regenerate_operationsA
Idempotent

Recalculate toolpaths. Returns regenerated ids, per-operation errors, and anything still dirty.

Inputs: ids, only_dirty.

run_jobA

One-shot CAD-to-CAM: open part (optionally into a template), machine group, stock, import operations, regenerate, save .mcam, post .nc and write the setup/run sheet. Returns every artifact path and a step log.

Inputs: part_path (required), output_dir (required), post, notes, +9 more.

run_native_setup_sheetC

Run Mastercam's own setup-sheet report (configured template) without its dialog.

Inputs: pdf, images.

save_fileA

Save the current file (Save As when path is given; existing files are kept unless overwrite=true).

Inputs: path, overwrite.

screenshotA
Read-only

Capture Mastercam's graphics window as an image.

Inputs: fit, view, save_to.

select_mastercamA
Idempotent

Send all following commands to one specific Mastercam window (when several are open).

Inputs: pid.

set_active_groupA
Idempotent

Make a toolpath group active (ids from list_machine_groups): new operations are added to it.

Inputs: group_id (required).

set_levelA
Idempotent

Create, name, activate or show/hide a level.

Inputs: number (required), name, active, visible.

set_operation_parametersA

Change any operation parameters by path, then regenerate the operation.

Inputs: id (required), parameters (required).

set_output_folderC

Set where a machine group's NC files are written.

Inputs: folder (required), group_id.

set_planesB
Idempotent

Set the current WCS / tool plane / construction plane. New operations take the tool plane; the WCS decides which coordinates are posted.

Inputs: all, wcs, tool_plane, construction_plane.

set_stockA

Define the mill stock of a machine group (bounding box of all solids / all entities, or an explicit box).

Inputs: max, min, mode, group_id.

update_operationB

Change an operation's name, spindle speed, feeds or H/D offset numbers (then it is regenerated).

Inputs: id (required), name, locked, feed_rate, +5 more.

update_planeA
Idempotent

Move, renumber or rename a plane you created (system planes can only get a work offset).

Inputs: name (required), set, origin, new_name, +1 more.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.2/5.0

    Scored across 54 tools

    Disambiguation4/5

    Despite 54 tools, most have a clearly distinct resource+action target, and the descriptions actively disambiguate the risky pairs (create_circle_mill vs create_helix_bore, generate_setup_sheet vs run_native_setup_sheet, list_tools vs list_library_tools). There is residual overlap among the several 'what is the current state' tools (mastercam_status, get_state, get_part_info, list_operations) and between run_job and the individual step tools, but an agent can still choose correctly from the text.

    Naming Consistency4/5

    The dominant convention is snake_case verb_noun (create_contour, set_planes, list_geometry, delete_operations), applied across nearly the whole surface. Minor deviations exist: bare nouns (knowledge, screenshot, operation_stats), noun-first names (mastercam_status), and 'new_file' where create_* would be expected, plus launch_mastercam/select_mastercam placing the server name in different positions.

    Tool Count2/5

    54 tools is well past the point where an agent can reason about the surface at once, even though the CAD-to-CAM domain is genuinely broad and most tools are non-redundant. The set is sensibly grouped into lifecycle areas, but it would benefit from consolidation (e.g. run_job-style wrappers for common sequences).

    Completeness4/5

    Coverage is strong across the domain: session/file management, geometry, levels, planes, tools, toolpath operations, machine groups, stock, posting, NC verification, setup sheets and a one-shot job runner. Gaps remain around geometry modification/transforms (only create and delete), tool editing/library import, and machine-group removal, but these are workaroundable.

    Maintenance

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      B
      quality
      C
      maintenance
      Connects AI coding agents to Autodesk Fusion 360 for CAD/CAM automation, exposing 84 tools for sketching, modeling, assembly, inspection, export, and G-code post-processing through any MCP-compatible client.
      85
      MIT
    • A
      license
      B
      quality
      D
      maintenance
      Enables MCP clients like Claude to automate SOLIDWORKS 2025 and SOLIDWORKS CAM via COM, covering parts, assemblies, drawings, and CAM toolpaths. It generates real geometry, mass properties, and posted G-code files directly on disk.
      40
      2
      MIT
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants like Claude for Desktop or Cursor to control supported CAD applications through MCP, supporting drawing, layer and entity management, block operations, data export, and file/session control via natural language or unified tool calls.
      -
    • F
      license
      Not graded
      quality
      A
      maintenance
      Enables AI assistants like Claude Desktop or Cursor to control supported CAD applications through MCP, supporting drawing, layers, entities, blocks, files, exports, and complex multi-step CAD tasks via direct tool calls or natural language.
      -