Skip to main content
Glama
README.md
<img src="assets/icon.svg" width="64" height="64" alt="">

# logicSimOnSteroids

A three-state logic circuit simulator that runs as a local MCP server. Ask your MCP client to build a half adder and show it. In a client that supports MCP Apps, click the inputs to see the schematic and outputs update in place. The server and iframe use the same Rust engine compiled to WebAssembly.

The [product scope and roadmap](docs/product-scope.md) cover the planned local browser editor and MCP workflows for saved circuits.

## Build and test

Install Node.js 20.19+ and stable Rust with rustup. The npm lockfile includes the wasm-pack and MCPB build tools.

```sh
rustup target add wasm32-unknown-unknown
npm ci
cargo test
npm test
npm run build:mcpb
```

`cargo test` covers the gate truth tables, the half adder, the full adder, and the 2-bit counter. `npm test` builds the project and starts the stdio server from a separate working directory to call both tools and read the view.

## Install

### Claude Desktop

1. Build the bundle and locate `dist/logic-sim-on-steroids.mcpb`.
2. In Claude Desktop, go to **Settings → Desktop app → Extensions → Manage**. Under **Advanced settings**, choose **Install Extension…** and select the bundle. Older versions list **Extensions** directly under **Settings**.
3. Start a new chat and ask **“Build me a half adder and show it. Start both inputs at 0.”** Toggle A and B. Sum is high when exactly one input is high. Carry is high when both inputs are high.

The interactive view requires a client that mounts MCP Apps and permits WebAssembly in its iframe. Clients with text-only support can read the initial output summary or ask for a trace with `simulate`. See [Anthropic’s local installation guide](https://support.claude.com/en/articles/10949351-getting-started-with-local-mcp-servers-on-claude-desktop).

### npx, editor setup, and GitHub Pages

Build the setup site and its downloads with `npm run build:site`. Open `dist/site/index.html` for Cursor and VS Code configurations and the Claude Code command. Use `dist/site/` as the GitHub Pages publish directory or upload its contents as a Pages deployment artifact.

The npx entry point can run from the built tarball without a registry publish.

```sh
npx --yes "--package=$PWD/dist/site/logic-sim-on-steroids.tgz" logic-sim-on-steroids
```

Configure that command as a stdio server in your MCP client. The terminal version of Claude Code displays the text result.

## Netlist and tools

A circuit is an object with `components` and `wires` arrays. See the [JSON schema](engine/circuit.schema.json). Each component has a unique, case-sensitive `id` and a `type`. A wire connects `from` and `to` endpoints, each with a `component` ID and a `pin`.

| Component | Input pins | Output pin |
| --- | --- | --- |
| `INPUT`, `CLOCK` | | `out` |
| `OUTPUT` | `in` | |
| `AND`, `OR`, `XOR`, `NAND`, `NOR` | `a`, `b` | `out` |
| `NOT` | `in` | `out` |
| `DFF` | `d`, `clk` | `q` |

Signals are the numbers `0` and `1` or the string `"X"`. Undriven pins read `"X"`. INPUT and DFF values start at `"X"` unless the component sets `initial`. CLOCK starts at `0`. Fan-out is allowed. Each input pin accepts one driver, and feedback must pass through a DFF. The netlist accepts up to 128 components and 256 wires.

- `simulate(circuit, input_sequence)` starts with a fresh circuit. Each entry in the sequence maps INPUT IDs to values and retains omitted inputs. Use an empty object to step without changing the inputs. Each step toggles every CLOCK, settles the gates, samples DFFs simultaneously on known `0 → 1` clock edges, then settles the outputs. Derived rising edges are processed within the same step. If sequential feedback fails to settle after 256 sampling rounds, the tool reports an error. The result is a `trace` array with zero-based `step` numbers and `outputs` maps. The sequence accepts 1–512 steps.
- `show_circuit(circuit)` opens the interactive SVG view and returns a text summary of initial outputs. Input buttons set an unknown input to `1`, then toggle between `0` and `1`. The **Step clock** control advances CLOCK components. Toggling an input can drive a DFF clock pin without advancing the CLOCK components.

For example, pass this payload to `simulate` to invert a signal across three steps.

```json
{
  "circuit": {
    "components": [
      { "id": "A", "type": "INPUT", "initial": 0 },
      { "id": "invert", "type": "NOT" },
      { "id": "Y", "type": "OUTPUT" }
    ],
    "wires": [
      { "from": { "component": "A", "pin": "out" }, "to": { "component": "invert", "pin": "in" } },
      { "from": { "component": "invert", "pin": "out" }, "to": { "component": "Y", "pin": "in" } }
    ]
  },
  "input_sequence": [{}, { "A": 1 }, { "A": "X" }]
}
```

The trace reports `Y` as `1`, `0`, then `"X"`.

## Repository

- `engine/` contains the Rust simulator, WASM interface, tests, and netlist schema.
- `server/` registers MCP tools and resources independently of the stdio entry point.
- `ui/` builds the self-contained HTML and SVG view.
- `docs/` contains the static setup page.

Licensed under the [MIT License](LICENSE).