ec-sim-mcp
v0.3.0MCP server that lets an AI agent drive the Ec-Sim circuit simulator in an open browser tab
Lets an AI agent (Claude Code, Claude Desktop, any MCP client) design and simulate circuits in Ec-Sim while the editor is open in your browser. The agent's changes appear on the schematic as it makes them, simulations run in the tab, and the waveforms it measures are the ones you see. The server is a relay. The circuit, the engine and the results stay in the tab, so the engine's origin lock and the web app's own code paths apply unchanged. Nothing is uploaded. Needs Node.js 20 or newer. Register the server with your MCP client. In Claude Code:
Summary extracted from the README.
Ec-Sim MCP server
Lets an AI agent (Claude Code, Claude Desktop, any MCP client) design and simulate circuits in Ec-Sim while the editor is open in your browser. The agent's changes appear on the schematic as it makes them, simulations run in the tab, and the waveforms it measures are the ones you see.
agent ⇄ stdio ⇄ this server ⇄ WebSocket on 127.0.0.1 ⇄ editor tab
The server is a relay. The circuit, the engine and the results stay in the tab, so the engine's origin lock and the web app's own code paths apply unchanged. Nothing is uploaded.
Use
Needs Node.js 20 or newer. Register the server with your MCP client. In Claude Code:
claude mcp add ec-sim -- npx -y ec-sim-mcp
On Windows (not WSL), npx has to be started through cmd /c, or the server fails to start:
claude mcp add ec-sim -- cmd /c npx -y ec-sim-mcp
In Claude Desktop and other clients that use a JSON configuration:
{ "mcpServers": { "ec-sim": { "command": "npx", "args": ["-y", "ec-sim-mcp"] } } }
From a checkout of the repository (development):
cd mcp && npm ci
claude mcp add ec-sim -- node /path/to/Ec-Sim/mcp/src/server.mjs
# against a local dev server (cd web && npm run dev):
claude mcp add ec-sim -e ECSIM_EDITOR_URL=http://localhost:5173/editor -- node /path/to/Ec-Sim/mcp/src/server.mjs
A complete session, from one sentence to a checked 20 V / 5 A bench supply, is written up at https://ec-sim.com/articles/designing-with-an-ai-agent.
Then ask the agent for something ("build an RC low-pass with a 1 kHz corner and show me the step
response"). Its first call, open_editor, opens a pairing link in your browser. Press Connect
in the dialog. A badge in the menu bar shows the link and has a Disconnect button.
| Variable | Meaning |
|---|---|
ECSIM_EDITOR_URL |
Editor to pair with. Default https://ec-sim.com/editor. Only this origin may link. |
ECSIM_MCP_PORT |
Loopback port for the tab link, 1024 to 65535. Default: any free port. |
Tools
| Tool | Purpose |
|---|---|
open_editor |
Link to a tab (opens the pairing link, waits for Connect) |
list_component_types |
Part types, pins, pin positions and outline for each rotation, spacing rule, parameters with SI units and defaults |
list_parts |
The editor's parts library (diodes, BJTs, MOSFETs, JFETs, op-amps): categories, or one category's table in SI, with limits on any column (where), sorting, word search and paging |
list_examples, load_example |
Built-in circuits |
get_circuit |
The circuit as a netlist (works for hand-drawn circuits), ERC result, revision |
place_part |
Place one part without wires, at a grid point or next to a pin of another part, rotated or mirrored; the reply gives its pin positions |
draw_wire, remove_wire |
Draw one wire along a stated path (pins, points, corners); remove a wire or one of its segments |
place_symbol, remove_symbol |
Ground symbols and net labels at a stated point |
move_label |
Move a part's designator and value text, a probe's badge, or a net label / ground symbol |
get_drawing |
The drawing with positions: parts, pin coordinates and nets, symbols, wires with ids, and the layout numbers |
set_circuit |
Replace the circuit from a structured netlist or a SPICE deck; drawn and wired automatically |
edit_circuit |
Change values and parameters, swap in a library part, add and remove parts, move, turn or mirror a part, move a pin to another net, rename a net and choose how its name is shown (all or nothing) |
get_variables |
The variable table (Edit > Variables in the editor): each variable's value or formula, the number it resolves to, and the part fields, settings and expressions that use it |
set_variables |
Create variables or overwrite existing ones (value or formula, unit, note, rename); every part and setting that follows a changed variable moves in the same step, and the reply lists them |
delete_variables |
Delete variables; one that is still in use is refused unless detach is set, which leaves what used it at its present value |
set_measurements |
Save named measurements with limits (ripple, overshoot, a level at a time); every run then reports them with pass or fail, and stepped or Monte Carlo runs with min, max, mean, sigma and yield |
keep_reference, list_references, remove_reference |
Keep a signal of the last result as a reference trace to compare later runs with (usable by name in measure), optionally as an upper or lower limit |
set_probes |
Choose the signals in the waveform viewer |
set_design_notes |
Write the project's design notes (Edit > Design Notes in the editor); get_circuit returns them |
set_math_waveforms |
Named expressions drawn as traces in the viewer (avg, rms, d/dt, integ, arithmetic); the tool description carries the syntax |
run_simulation |
Transient, AC, DC operating point, DC sweep; time accuracy normal/high/very high; step repeats the run over values of a variable (a list or a generated range), monte_carlo draws the toleranced values, worst_case finds the tolerance corner that pushes each saved measurement to its extremes; returns a summary, not waveforms |
measure |
Scalars from the last result: levels, timing, settling, −3 dB points (cutoff_3db, or one side with cutoff_low / cutoff_high), math expressions |
get_waveform |
The plotted data: resampled points, capped at 2000 per signal; from/to return one part of the run |
export_waveforms |
Write the full-resolution data of the last run to a CSV file on this computer and return its path |
screenshot |
PNG of the schematic (the whole drawing, or a close-up around named parts) or of the waveform viewer as shown, returned as an image |
export |
SPICE netlist, BOM, share link |
Definitions are in src/tools.mjs; the handlers are in the web app
(web/src/agent/agentHandlers.ts in the repository). A web test fails if the two lists differ.
How it stays safe and honest
- Loopback only. The server listens on 127.0.0.1. The tab connects to the literal address.
- Three checks before a tab links: the page's
Originmust be the editor, theHostheader must be a loopback name, and the first message must carry the random token from the pairing link. The token is removed from the address bar as soon as the page has read it. - You confirm in the tab. Nothing links until you press Connect, and the dialog warns about unsaved changes.
- Every agent change is one undo step, applied through the editor's normal state and validated like an opened file.
- Revisions. Every change to the document, yours or the agent's, increments a revision. The
count starts at a random number when the page loads, so a revision read before a reload never
names the reloaded document.
edit_circuitmust name the revision it is based on and fails if you edited in between. An agent call waits until you let go of a drag before it reads the circuit, and its change is applied only if the circuit is still as it read it. - Timeouts. The tab handles one call at a time and tells the server when it starts one; a call's time counts from then. A call still waiting behind another when its time is up is withdrawn and never applied. One that started and ran too long may still be applied, and the error says so.
- A lost link. When the link breaks while the tab stays open, the agent is told to ask you to press Reconnect on the badge, not to open a second tab.
- Netlist = drawing. The agent states parts and net names; the tab draws real parts, wires, net labels and ground symbols, then reads the drawing back through the editor's connectivity and refuses the change if any pin is not on the net that was asked for.
- Library parts take the editor's path. A part's
modelapplies the same catalog entry, the same way, as picking it in the Property Inspector.list_partsshows that catalog converted to SI withdeviceDefaults.ts. - SI at the boundary. Conversion to the datasheet units the Property Inspector shows uses the
same table (
deviceDefaults.ts) as the path to the engine. Defaults reported to the agent are computed from that table, not copied. - One file, where you say.
export_waveformsis the only tool that writes to disk: a.csvat an absolute path (or a new file in the system temp folder), never over an existing file unless asked, and complete or absent. - Bounded output. No tool returns a raw waveform; lists and text are capped, and a screenshot
is at most 2400 px wide. A reply larger than the link carries (8 MB) is answered with an error
instead;
export_waveformsfetches its rows in pieces of at most 4 MB, all from one result (a run that finishes during the export makes it fail rather than mix two runs in one file).
How the agent draws
First everything at once, then tidying by hand. The agent is told to plan the placement, draw
the whole circuit with one set_circuit call (the editor places and wires it, as described in the
next section), look at a screenshot, and then fix what does not read cleanly one change at a
time: move_part for a part in the wrong place or out of line, remove_wire and draw_wire for
a wire with a detour or a needless crossing, move_label for text in the way. You see the
circuit appear and then being cleaned up.
Placement is by pins, on the 20 px grid. The first part of a block gets at: {x, y} (its
centre in grid steps); every part around it gets next_to: {pin, to, dx, dy}, which puts one of
its pins a stated number of steps from a pin of another part. The editor works out the centre from
the rotation and the pin offsets, so the agent does no coordinate arithmetic and connected pins
end up exactly in line. line_up only straightens a part that already has a place.
list_component_typesgives, for every type and rotation, the pin offsets and the outline (the body with its pins), where the text is written, and the spacing rule.- A part that is too close is refused with the reason and the room both parts take. The check is
on what will be drawn: bodies need 1 free step between them; every connected pin gets a wire
2 steps straight out (a ground pin also its symbol), which needs 2 free steps to other parts and
1 to the lead-out wires of other nets. A part placed bare with
place_partonly needs the step between bodies, since the agent draws its wires itself. - Every reply that draws (
set_circuit,edit_circuit,get_drawing) carrieslayout: size of the drawing in grid steps, area and wire length per part, crossings, net labels, texts that lie on another part, and the values to aim for (about 80 to 150 square steps per part). - A whole-drawing screenshot that would be too small to read says so in
noteand points to close-ups by block. at: {col, row}still names a cell of a coarse grid (16 x 12 steps), and a part given no place goes to the next free cell. That is for a quick sketch: it is about three times too wide for a finished drawing, which is why the instructions steer agents to pins and blocks.
The hand tools work like this:
- Positions are in grid steps of 20 px, x to the right and y downwards.
- A wire goes exactly where the agent says. Nothing is snapped: an off-grid point, a wire through a part's outline, or a wire that would pass over a pin or symbol the agent did not name as one of its points is refused. Two points that are not in line get one corner between them.
- Nothing is assumed about what a wire connects. The reply to
draw_wirereports what the editor's connectivity finds on it: the pins it joined and their net, and warnings when it bridged a part, joined two named nets, crossed other wires or left an end open. After hand changes the agent comparesget_circuitwith the circuit it meant. - Each step is one undo step.
revisionis optional on these tools.
A circuit can also be built entirely by hand (place_part, then draw_wire), which the agent is
told is fine for a handful of parts or for adding to an existing circuit.
The wording that steers the agent (workflow, layout and wire style) is INSTRUCTIONS in
src/tools.mjs.
How the automatic drawing works
Parts go where the agent says (at, next_to, rotation); parts given no place go into free
cells of a 320 × 240 px grid below the placed ones, row by row in the order listed. Every connected pin is led out of its part
on a short stub. Then, per net (web/src/agent/wireRouter.ts):
- Pins are joined by orthogonal wires on the 20 px grid, nearest first, as short as the placement allows. A pin is led two grid steps out of its part before a wire turns or joins, and a wire keeps two straight grid steps on each side of a crossing where there is room (a preference: it gives way when other connections need the space).
- A wire may cross another net's wire but never ends on it, runs along it or passes over one of its corners, so a crossing is never a connection.
- A pin gets a net label instead of a wire only when no clear path exists within about
1800 px of wire (bends and crossings count extra). The reply to
set_circuit/edit_circuitthen carries adrawingnote naming those nets, so the agent can move parts closer. - Each net carries its name on its wires (what
V(name)refers to), without showing it. The agent chooses the names to show:labelsinset_circuit, or thename_netoperation ofedit_circuit, as text on a wire or as a net label. Ground pins get a ground symbol each. - Only names that are shown connect. Nets that show the same name are one net; a name that is not shown connects nothing. So where a pin has to be joined by a label, the rest of its net gets a label too. Two separate nets that carry the same unshown name stay separate, and the check warns about it.
add_partputs the new part in the free cell nearest to the pins it connects to and wires it to the existing net, including nets of a hand-drawn circuit that have no label.remove_partalso removes the wires that were left leading nowhere.move_partandconnecttake the part out with the wires drawn for it and draw it again at its (new) place on its (new) nets. Every other connection must come out exactly as it was, or the change is refused. Probes follow their parts and nets.
A circuit given as a SPICE deck goes through the editor's SPICE import instead, which puts a net label on every pin.
After the agent draws or extends a circuit, the editor zooms your view to the whole drawing, and the server's instructions tell the agent to look at a screenshot of the layout before going on.
If the wired drawing ever fails the read-back, the circuit is drawn with a label on every pin instead and the reply says so.
Limits
- Placement is the agent's job: there is no automatic placement. The server's instructions
(
LAYOUTinsrc/tools.mjs) tell it to work in functional blocks, place by pins, keep the drawing about one and a half to two times as wide as it is high, check the layout numbers and the screenshot, and fix withmove_part. - Text is not placed for the agent: a value can lie on a wire of its own part (a horizontal
capacitor), and
layout.text_overlapsonly reports text on other parts. move_parton a hand-wired part redraws that part's wires automatically.list_partscovers the built-in library only. Passives have no library entries.- Design notes are not part of undo, and writing them does not change the circuit revision.
- No parameter sweeps, Monte Carlo or thermal tools yet.
- One tab at a time; a second tab that links takes over.
- A page on
https://ec-sim.comconnecting tows://127.0.0.1has only been tested from a local dev server (http://localhost). Browsers treat loopback as trustworthy, but Chrome may show a local-network permission prompt and Safari may refuse; this needs checking on the live site.
Tests
cd mcp && npm test # server: MCP over stdio, origin/host/token checks, relay, request timing
cd web && npx vitest run src/test/agent_bridge.test.ts src/test/agent_bridge_editor.test.tsx
# Real browser, real engine (needs chromium and a running dev server on port 5199):
cd web && npx vite --port 5199 --strictPort &
node mcp/scripts/e2e-browser.mjs /tmp/ecsim-e2e.png