surfcad-mcp 0.0.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +74 -1
- package/bin/surfcad-mcp.js +7 -0
- package/data/commands.json +14368 -0
- package/package.json +40 -9
- package/src/bridge/localAddress.mjs +55 -0
- package/src/bridge/relayHub.mjs +266 -0
- package/src/bridge/relayServer.mjs +223 -0
- package/src/catalog.mjs +26 -0
- package/src/errors.mjs +21 -0
- package/src/nodeClient.mjs +42 -0
- package/src/packageVersion.mjs +16 -0
- package/src/relay.mjs +119 -0
- package/src/relayMessages.mjs +16 -0
- package/src/server.mjs +169 -0
package/README.md
CHANGED
|
@@ -1 +1,74 @@
|
|
|
1
|
-
# surfcad-mcp
|
|
1
|
+
# surfcad-mcp
|
|
2
|
+
|
|
3
|
+
Stdio [Model Context Protocol](https://modelcontextprotocol.io/) server for the SurfCAD browser agent bridge. Each tool maps to one `window.surfcad` command from the shipped command catalog (`data/commands.json`). The server pairs to your open SurfCAD tab through the **M1** loopback WebSocket relay (`ws://127.0.0.1:17341` by default).
|
|
4
|
+
|
|
5
|
+
## Install and run
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npx surfcad-mcp
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
The process speaks MCP over **stdio** and **starts the local relay** on `127.0.0.1:17341` (loopback only). If another process is already listening there (a second MCP client or the SurfCAD dev server), it reuses that relay instead of failing.
|
|
12
|
+
|
|
13
|
+
Pair it to a running SurfCAD tab (see below), then your MCP client can call bridge tools (`status`, `set_script`, `run`, …) plus a `pair` helper.
|
|
14
|
+
|
|
15
|
+
Environment variables:
|
|
16
|
+
|
|
17
|
+
| Variable | Purpose |
|
|
18
|
+
| --- | --- |
|
|
19
|
+
| `SURFCAD_PAIRING_CODE` | 6-character code from the SurfCAD **Local agent** panel (optional if you use the `pair` tool). |
|
|
20
|
+
| `SURFCAD_AGENT_BRIDGE_WS_URL` | Relay URL (default `ws://127.0.0.1:17341`). |
|
|
21
|
+
| `SURFCAD_MCP_START_RELAY` | Set to `0` to skip starting the relay (tests only). |
|
|
22
|
+
|
|
23
|
+
## Pair with SurfCAD (Local agent)
|
|
24
|
+
|
|
25
|
+
1. Open [https://surfcad.com](https://surfcad.com) (or local dev).
|
|
26
|
+
2. Open the **profile** menu → **Local agent** → **Show pairing code** and leave the tab open.
|
|
27
|
+
3. Add `surfcad-mcp` to your MCP client (`npx surfcad-mcp`), set `SURFCAD_PAIRING_CODE` to that code, or call the MCP **`pair`** tool with `{ "code": "ABCDEF" }`.
|
|
28
|
+
4. Click **Allow connection** in SurfCAD when prompted.
|
|
29
|
+
|
|
30
|
+
Nothing pairs silently — you must show the code and approve the connection.
|
|
31
|
+
|
|
32
|
+
## MCP client config (Cursor / Claude Desktop)
|
|
33
|
+
|
|
34
|
+
```json
|
|
35
|
+
{
|
|
36
|
+
"mcpServers": {
|
|
37
|
+
"surfcad": {
|
|
38
|
+
"command": "npx",
|
|
39
|
+
"args": ["-y", "surfcad-mcp"],
|
|
40
|
+
"env": {
|
|
41
|
+
"SURFCAD_PAIRING_CODE": "ABCDEF"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
In Cursor, add the same block under **Settings → MCP** or your project `.cursor/mcp.json`.
|
|
49
|
+
|
|
50
|
+
## Safety and consent
|
|
51
|
+
|
|
52
|
+
- **Commerce:** Agents cannot place orders or drive checkout. Quote/cart/checkout controls are not exposed as MCP tools.
|
|
53
|
+
- **Git on real repos:** Writes may return `real_repo_blocked` until the user consents in the app.
|
|
54
|
+
- **Destructive git operations:** Need explicit approval; the bridge returns `confirm_required` unless args include `confirm: true` after the user has confirmed in SurfCAD.
|
|
55
|
+
|
|
56
|
+
Bridge refusals (`real_repo_blocked`, `confirm_required`, `not_paired`, user deny, etc.) are returned as structured JSON in MCP tool errors.
|
|
57
|
+
|
|
58
|
+
## Monorepo maintenance
|
|
59
|
+
|
|
60
|
+
In the [SurfCAD monorepo](https://github.com/artur0x0/surfcad), `npm run export:agent` regenerates `data/commands.json` from `src/agent/commands.json`. CI fails if that copy is stale (`test/commandsFreshness.test.mjs`). Before publishing, run `export:agent` and `npm run smoke:pack` in this package.
|
|
61
|
+
|
|
62
|
+
Agent-oriented guide: [`docs/agent/SKILL.md`](https://github.com/artur0x0/surfcad/blob/main/docs/agent/SKILL.md). Scripted demo from a full checkout: `npm run demo:mcp` at the repo root.
|
|
63
|
+
|
|
64
|
+
## Releasing to npm
|
|
65
|
+
|
|
66
|
+
The [`surfcad-mcp`](https://www.npmjs.com/package/surfcad-mcp) package is published from GitHub Actions (workflow [`.github/workflows/publish-mcp.yml`](../../.github/workflows/publish-mcp.yml)) using [npm Trusted Publishing](https://docs.npmjs.com/trusted-publishers) (OIDC). The trusted publisher is configured on npm for this repository and workflow file — no `NPM_TOKEN` is stored in GitHub.
|
|
67
|
+
|
|
68
|
+
Ways to release a new version:
|
|
69
|
+
|
|
70
|
+
1. **Version bump on `main`** — In a PR, bump `version` in `packages/surfcad-mcp/package.json`. After merge, when the **CI** workflow completes successfully on `main` and the version differs from the parent commit, publish runs automatically (skipped if that version is already on npm).
|
|
71
|
+
2. **Git tag** — Push a tag `surfcad-mcp-vX.Y.Z` that exactly matches the `version` field at that commit (for example `surfcad-mcp-v0.2.0` for `"version": "0.2.0"`).
|
|
72
|
+
3. **Manual** — In GitHub → Actions → **Publish surfcad-mcp** → **Run workflow** on branch `main`.
|
|
73
|
+
|
|
74
|
+
Before bumping, run `npm run export:agent` at the repo root if the command catalog changed, and `npm test` plus `npm run smoke:pack` in this package.
|