# Sommerwire MCP server

A read-only [Model Context Protocol](https://modelcontextprotocol.io) server for Sommerwire. An MCP client can
check, solve, share and export Sommerwire antenna models through four tools. It runs the same engine and the same
model code as the browser app, so its figures are the figures the page shows.

- **Hosted:** `https://mcp.sommerwire.app/mcp`, Streamable HTTP, no login. One small shared public instance with
  tighter limits. The service receives your tool arguments. See [Hosted server](#hosted-server).
- **Local stdio:** your MCP client starts `src/server.js` as a child process. It is offline and private, has no HTTP
  listener and needs nothing configured.
- **Read-only.** No tool writes a file, takes a path, runs a command, publishes or posts anything, or fetches a
  URL (a share link is decoded, never opened). Results come back as tool output only.
- **No secrets or accounts** on either transport.
- **Simulation, not measurement.** Every `solve` result says so and lists the model's assumptions, the solver's
  warnings and the approximation flags.

## Tools

Every tool takes **exactly one model source**:

| argument | what it is |
|---|---|
| `model` | a Sommerwire model as JSON: the share-link model schema (`name`, `freq`, `wires`, `sources`, `loads`, `tls`, `objects`, `seg`, `ground`, `material`, `z0`, `ins`, `boom`, `bands`, `comment`, `junctions`), with cells as numbers or expressions (`R/4`) |
| `share_link` | a Sommerwire share link (`https://sommerwire.app/#sw=1.d.…`, with or without `?embed=1`) or just its `#sw=` fragment |
| `maa` | the text of an MMANA-GAL `.maa` file |
| `example` | a built-in example by its full model name, for example `RF.Guru EFOC17 end-fed off-centre, 40/20/17/15/10 m, 4:1, flat top`. The app opens with `RF.Guru EFOC29 end-fed off-centre, 80–10 m, 4:1, flat top`. |

| tool | does | extra arguments |
|---|---|---|
| `validate_model` | checks the model without solving: schema, share-link bounds, expressions, wire positions, ground, and the mesh the solver would build at each frequency (segments, unknowns, mesh warnings), with `topology`: the junction report of that mesh; returns the cleaned model and its assumptions | `frequency` |
| `solve` | solves at the calculation frequency and, unless `include_bands: false`, at each of the model's bands: feed R + jX and SWR (first source), gain (total, H, V), F/B, take-off elevation and azimuth, polarization, the page's angle summary (RDF, low/high-angle windows, H/V peaks), every solver warning, `flags`, and `power`: where the accepted power goes (below); once per call, `geometry`: the page's geometry box (wire lengths with IDs and their total, house wires left out; side lengths only for a feed point inside a wire; feed points; line lengths from the line entries; feed-point spacing) and `topology`: the junction report of the solved mesh | `frequency`, `include_bands`, `include_branch_currents` |
| `share_link` | makes a `https://sommerwire.app/#sw=1.d.…` link that opens the model in the app (made by the server, never stored; the link carries the model, the calculation frequency and the pattern view, never results) | `frequency`, `pol` (`tot`, `h`, `v`, `hv`, `all`) |
| `export_maa` | returns the `.maa` text exactly as the app's **Save .maa** writes it, plus `format_loss`: what the file does not keep | `frequency` |

When the numeric endpoints and source match the EFOC17 or EFOC8 flat top or the feed-end EFOC29 inverted L, `geometry.wires` includes each wire's
`role` and each radiator's `orientation`. `geometry.radiatorLength` sums just the radiator wires, while `geometry.total`
sums all the modelled wires. The retired far-end drop is still accepted as a saved model or share link.

`topology` is the page's junction report ([topology.js](../topology.js)) for the mesh the solver uses at the calculation
frequency: which wires are actually joined. It is an added field; no figure of `solve` depends on it.

| field | what it is |
|---|---|
| `rule` | `legacy` (wires are joined wherever mesh nodes coincide, the default) or `explicit` (at wire ends only) |
| `frequency`, `signature` | the frequency of that mesh, and a hash of its electrical graph: equal signatures mean the same wires joined the same way |
| `stable`, `signatures` | whether the graph is the same at every frequency of the call, with the signature at each |
| `counts` | totals of `junctions`, `open_ends`, `warnings` and `advisories`; `house_junctions` and `house_open_ends` are counted, not listed |
| `junctions` | each electrical node where conductors meet: `id` (`w1e+w2b+w8b`; `w2*` is the inside of wire 2), `at`, `degree` (conductors on it), `kind` (`ends`, `mesh`, `centre`, `ground`) |
| `open_ends` | wire ends joined to nothing |
| `warnings` | probable slips, each with `code`, `short` and `text`: `near-miss` (not connected, closer than the wire radii), `mesh-junction` and `mesh-crossing` (joined, or not, only by where mesh nodes fall), `near-ground`, `open-port`, `frequency-dependent` |
| `advisories` | open and taken as intended: `gap`, and with the `explicit` rule `open-tee` and `open-crossing` |
| `truncated`, `approximate` | a list was cut at 60 entries (the totals are in `counts`); the model has more than 2500 unknowns and the report is for the mesh before the solver cuts long wires coarser |
| `notes` | how to read the report |

Nothing is joined, moved or split. `"junctions": "explicit"` in the `model` is the opt-in that joins wires at wire ends
only, at every segmentation; `share_link` carries it and `export_maa` writes it as a `Sommerwire JUNCTIONS` line.
Without it a model is solved as before. If the report cannot be made, `topology` holds one field, `unavailable`, and
the rest of the output is as usual. The rule, the distances and the signature are described in
[Electrical topology and junction diagnostics](../README.md#electrical-topology-and-junction-diagnostics).

The calculation frequency is `frequency` if given, else the share link's, else the model's design frequency.

**Checking vs. previewing.** `validate_model` and `solve` check and calculate a model; neither returns a link. Only
`share_link` makes the clickable preview that opens the model in Sommerwire. The server's initialization instructions
tell the client: for each model it actually recommends, call `share_link` and put the exact returned `url` unchanged in
the final answer; never write, guess or edit a link itself; and if `share_link` fails for a model, say so with the
error instead of giving a link. Clients that show server instructions to the model pass this on; it is guidance to the
client, not something the server can enforce.

### What a result means

`solve` returns `kind: "simulation"`, a `notice`, `assumptions` (ground and soil, wire material, ideal transformers,
lines, loads, insulation, boom, houses, segmentation) and `model_comment` (the model author's own description, shown as
given and not checked). Each entry of `results` carries the page's own result fields (`R`, `X`, `swr`, `z0`, `gain`,
`gainH`, `gainV`, `fb`, `el`, `az`, `pol`, `approx`, `capDb`, `N`, `nseg`, `sources`, `Pin`, `earthed`, `sum`,
`warnings`) and a `flags` summary:

| flag | meaning |
|---|---|
| `perfect_mirror_fallback` | a wire touches real ground, so the impedance was solved over a perfect mirror (as MMANA does) while the pattern uses real ground: gain is approximate |
| `gain_capped_db` | gains were lowered by this many dB because the pattern held more than the input power |
| `earthed_wires` | wires connected to the ground |
| `negative_resistance` | the feed resistance came out negative: not physical |
| `non_finite_result` | impedance or gain is not a finite number |
| `coarse_sky_grid`, `over_unity` | the angle summary's grid misses the lobe, or holds over 5 % more power than supplied |
| `uncertain` | any of the above, or the page's own "uncertain" mark |
| `warnings` | how many solver warnings there are (the texts are in `warnings`, verbatim) |

An SWR of a total mismatch is returned as the string `"Infinity"`; JSON has no infinite numbers.

<!-- [power] energy account -->
### Where the power goes: `power`

Each entry of `results` also carries `power`, the page's power box as data: the account of that same solve. Powers are
in watts for the source voltages as given (peak volts); a `share` is the power over `accepted`, the total the sources
accept.

| field | meaning |
|---|---|
| `accepted`, `passive` | total accepted power (the sum over the sources, signed) and whether it is positive |
| `sources` | `items` with `pos`, `power`, `share` per source. With several sources a figure can be negative: that source takes power. Only the total decides whether a result is passive. `why` is present when the figures per source are not to be read as a power flow |
| `loads` | total, and `items` per load: `index`, `pos`, `connected`, `power`, `share`; `house_earth: true` for an earth resistor on a house wire; `why` for a load that does nothing (on a free wire end, or not on a wire) |
| `conductor`, `insulation` | skin-effect loss in the wire material (`lossless: true` for lossless wire) and loss in the wire insulation |
| `lines` | total, and `items` per transmission line (`index`, `power`, `share`); exactly zero for a lossless line |
| `known`, `field` | the sum of the parts above, and the rest: the power the currents hand to the field |
| `radiated` | the far field integrated over the sky (`domain: "sky"`) or over all directions in free space (`"sphere"`) |
| `remainder` | `field` minus `radiated`, with `kind`, `label` and `why`: `unresolved` (free space or perfect ground: numerical error), `ground+unresolved` (real ground: ground loss and numerical error together, by difference) or `inconsistent` (mirror currents with a real-ground pattern: not an energy balance) |
| `ground` | `power: null` with a reason over real ground: ground loss is never a figure of its own. Zero in free space and over perfect ground |
| `transformer` | present when a feed has a ratio: `power: null`, because the transformer is ideal in the model |
| `flags`, `notes` | `non-passive`, `source-absorbs`, `over-unity`, `unresolved`, `mirror-mix`, `not-integrated`, `load-unconnected`, each with a sentence in `notes` |

Nothing is clamped and nothing is invented: a term the model does not hold is `null` with a `why`, and a result
whose total is not positive has `share: null` everywhere. Lists hold at most 32 entries per kind (the largest), with
`omitted` for the rest; the totals always cover everything. These are figures of the simulation, not measurements.
An account that adds up says the currents and their far field agree; it does not say the segmentation is fine enough.

`include_branch_currents: true` adds `branch_currents` to each result: for at most 32 of the model's own wires
(house wires left out), the current at both ends (`begin`, `end`) and the largest current (`peak`), in amperes, relative
to the first source's current (`rel`) and with its phase against that current in degrees. A current is positive from
the wire's first end to its second. It is off by default.
<!-- [power] end -->

### What `.maa` loses

`export_maa` lists, in `format_loss`, what reopening the file would not give back: the soil (`.maa` keeps no
permittivity or conductivity), the real-ground method, the band list, the calculation frequency and pattern view,
expressions (written as their values at the design frequency), materials MMANA-GAL has no match for, and the
Sommerwire-only extensions (transformer ratios, trap extras, lines, insulation, boom, houses, the radio side and
ferrite chokes) that travel as `Sommerwire …` comment lines which Sommerwire reads back and MMANA-GAL ignores. It also
reopens its own output and compares the solver input, so any other change (for example a phase with more decimals
than `.maa` keeps) is reported too. The transmit conditions are compared as the result uses them: a duty, air
temperature or power that is not given is its default (1, 50 °C, 100 W), so writing a default out is no change. An
empty list means the file reopens in Sommerwire as the same model.

### Measured loads

A load in `model` may be a measured one-port: `type: 3` with `zf`, rows of `[frequency MHz, R ohm, X ohm]` (the
series impedance between the two terminals of the gap, an inductive X positive, frequencies increasing, R not
negative), and optionally `plane`, the reference plane in words. Share links and `.maa` text carry the same load.
There is no new tool: the four tools take it as part of the model.

- At most 1001 rows per table, 0.01 to 10 000 MHz, |R| and |X| up to 10⁹ ohm, `plane` up to 200 characters. `zf` and
  `plane` on a load of another type are refused, as any unknown key is.
- R and X are interpolated linearly between rows. A frequency outside the rows is never extrapolated:
  `validate_model` and `solve` refuse a calculation frequency outside a table, with the load, its range and the
  frequency named. A band outside a table is listed in `validate_model`'s `notes` and comes back from `solve` as
  `{ f, error }` with the same message (also on the hosted server, where other solver errors are not shown), while
  the bands inside it are solved. `share_link` still makes a link that opens at such a frequency.
- A row with R below 0 is refused, never repaired. A malformed row is refused with the load and the row named.
- `assumptions` names each measured load: its rows and range, the reference plane as described, that the data are
  not verified, the interpolation, and that it is a one-port series impedance in that gap: not a transformer and
  not a mixed-mode choke.
- `export_maa` writes MMANA-GAL a fixed R + jX (the table's value at the design frequency, or its nearest end row
  when the design frequency is outside the table) and says so in `format_loss`; the table and the plane text travel
  in `Sommerwire ZF` comment lines that Sommerwire reads back.
- The hosted limits are unchanged: a request holds at most 48 000 JSON values and 1 MiB, so eleven full tables fit
  one request and twelve do not.

<!-- [system lane] the radio side -->
### The radio side and ferrite chokes: `system` and `heat`

A `model` may describe what lies between the antenna and the radio, with upstream Sommerwire's fields. A part that is
absent is not modelled, so a model without any gives the result it always gave. Share links and `.maa` text carry the
same parts. Out-of-range values are refused by name, never repaired.

| input | fields and units |
|---|---|
| `feed` | `cable`: a library cable, or your own with `custom: true` and `z0` (ohm), `vf` and `k1`, `k2` (matched loss in dB/100 m = k1·√f + k2·f, f in MHz); `len` in m (0 or absent: no feed line). `pw`: the transmit power in W, 0 to 10⁶ (100 when absent; 0 is 0 W). `duty`: above 0 to 1 (1 when absent, key down). `amb`: the air at the cores in °C, −50 to 150 (50 when absent). `pw`, `duty` and `amb` apply with or without a feed line |
| `xfmr` | a real unun or balun at the first source in place of its ideal ratio: `topo` (`auto`, `ruthroff`, `guanella`), `core`, `mix`, `stack`, turns `Np`, `Ns` or `N`, `lleak` (nH per turn²), `cs` (pF), `ccomp` (pF or `auto`), `wire` (mm), the line's `z0` (ohm), `vf`, `lineLoss` (matched loss in dB per metre at 10 MHz, scaled with √f; 0.05 when absent, which is 5 dB/100 m) and `len` (m), `id` |
| `tuner` | `type`: `none` (a radio of the model's `z0` without a tuner), `ideal`, `L` or `T`; `at`: `radio` or `antenna`; `qL`, `qC`; `cmax` (pF); `lmax` (µH) |
| load `type: 4` | a ferrite choke: `core`, `mix`, `stack` (cores stacked), `N` (turns) and `Cs` (winding capacitance, pF). Upstream numbers it 3; here `type: 3` stays the measured table, so `zf` or `plane` on type 4 and choke fields on any other type are refused |

**Reference planes.** Each result's `R`, `X` and `swr` are at the feed point the page's Calculate tab shows: with a
real unun or balun its input (the coax side), otherwise the source after its ideal ratio. The page's optimizer, Find
resonance and sweep use the same plane. `z0` is the reference of every SWR, the impedance a tuner matches to, and the
radio of `tuner.type: "none"`. With a radio side, `system` gives every plane and stage:

| field | meaning |
|---|---|
| `antenna` | `R`, `X` at the antenna terminals: the source in the wires, before any ratio |
| `feedpoint` | `R`, `X`, `swr` and `plane` (`transformer input`, `ideal ratio` or `source`): the result's own `R`, `X` and `swr` |
| `xfmr` | the unun or balun: `name`, `ratio`, its input `R`, `X`, the share it passes on (`eta`) and its core figures |
| `tuner` | `type`, `at`, what it sees (`inR`, `inX`, `swrIn`), what it gives (`R`, `X`), `eta`, its `parts` (`k`: L or C, `v` in H or F), `inCircuit`, and `bypassed` when it cannot match |
| `feedline` | `cable`, `len` (m), `z0line`, the radio end of the first source's line (`R`, `X`, `swr`), `eta` and `lossDb` of all lines together, `matchedDb`, `n` and `lines` (below) |
| `lineEnd`, `radio` | `R`, `X`, `swr` at the radio end of the line, and at the radio after a tuner there |
| `mismatch`, `ref` | the reflection at the radio (`gamma`, `eta`), taken only when a tuner (or `none`) is given; `ref` is then `available`, else `delivered` |
| `stages`, `k` | from the radio: `key` (`mismatch`, `tuner`, `feedline`, `xfmr`), `eta`, `before`, `lost`; `k` is the share that reaches the antenna terminals |
| `shares`, `pw` | where the radio's power goes (`rows` with `key`, `kind`, `label`, `share`), its `totals`, and `pw`: the transmit power in W, so a row's watts are `share × pw` |
| `warnings` | the radio side's own warnings, also in the result's `warnings` |

**Several sources** each get their own line of the same cable; the unun or balun and the tuner apply to one source and
are left out with a warning. `feedline.lines` has one entry per source: `spec`, the radio end of its line (`R`, `X`,
`swr`), and the power at its antenna end `Pa` and its radio end `Pr`, in W for the source voltages given (as in
`power`) and signed, positive towards the antenna. A source that takes power from the array has `Pa` below 0: its
line carries that power back to its radio (`flow: "to the radio"`, `Pr` below 0), or, where the line loses more than
it gets, the radio feeds it too (`flow: "into the line from both ends"`, `Pr` 0 or more); otherwise `flow` is
`"to the antenna"`. `lost` = `Pr − Pa` is what the line dissipates at the source's own current, never below 0 for a
passive line. A source with no real power of its own (0 V with its current induced by the array, or a purely reactive
load) still loads its line: its radio puts in `Pr` = `lost` and none of it reaches the antenna (`flow: "to the
antenna"`, `eta` 0, `lossDb` `null`, as the loss in dB has no bound). `eta` is the share the line passes on in the
direction the power flows (`Pa/Pr` towards the antenna, `Pr/Pa` towards the radio), and `lossDb` the same in dB; for a
line fed at both ends both are `null`, because no such share exists, and so for a line with no real power at either
end (`flow: "none"`: no current, or a lossless line at 0 V). With one source, a real unun or balun or a tuner at the
antenna is modelled by the share it passes on, so the power into it is known only while the antenna takes power; where
it takes none, the line's powers are `null` (`flow: "not available"`). `feedline.eta` is the sum of `Pa` over the sum of
`Pr`: what reaches the antennas over what the radios put in (with one source, its line's forward efficiency; 1, nothing
lost, where no current flows at all).

**`heat`** comes with a radio side or a choke: `pw` (W), `duty`, `amb` (°C), `worst` (`ok`, `warm` or `hot`), `flux`
(true when a core is above 5 mT, far beyond the small-signal data) and `rows`, one per core: `what` (`xfmr` or
`choke`), `watts` in the core key down and its `average` over the duty cycle (W), `temp` and `curie` (°C), `flux`
(mT), `limitW` (the transmit power in W at which the core reaches its Curie temperature) and `status`; for the unun or
balun `name`, `inputW` (W) and `inputVpeak` (V); for a choke `pos`, `core`, `mix`, `stack`, `N`, `ohms` (|Z|) and
`vrms` (V). `notes` give a tuner's parts at the transmit power (`value` in H or F, `arms` in A rms, `vpeak` in V). At
0 W nothing heats and every core is at `amb`.

**`.maa`**: the radio side travels in `Sommerwire FEED`, `XFMR`, `TUNER` and `DUTY` comment lines as upstream writes
them, and a choke as a fixed R + jX row (its impedance at the design frequency) with a `Sommerwire CHOKE` line.
Upstream writes the transmit power only in its FEED line, which exists only with a feed line; without one this
edition writes it as a third field of the DUTY line (`duty, air °C, power W`), which upstream's reader passes over. A
file that gives the power in both lines is refused.
<!-- [system lane] end -->

## Local stdio limits

These are the stdio limits. The hosted server is stricter: see [HTTP limits](#http-limits). Every input is checked before anything heavy is built, with the share-link bounds (`share.js`), and refused with a
reason (a tool error) rather than partly used:

| what | limit |
|---|---|
| one JSON-RPC message on stdin | 1 MiB (a longer line is dropped as it streams in and answered with a JSON-RPC error; the session stays open) |
| `model` as JSON, `.maa` text | 512 KiB |
| `share_link` | 64 000 characters of fragment |
| wires, sources, loads, lines, houses, bands | 3000, 64, 1000, 200, 8, 16; table cells 100 characters |
| frequency | 0.01 to 10 000 MHz |
| coordinates | 100 km |
| segments | about 25 000 at the highest frequency solved (estimated before any mesh is built) |
| house grid wires | 4000 |
| unknowns | 2500 (the engine's limit; long passive wires are coarsened first, with a warning) |
| frequencies per `solve` | the calculation frequency plus the model's bands (at most 17) |
| solve wall time | 120 s per call (`SOMMERWIRE_MCP_SOLVE_TIMEOUT_MS`, 1000 to 600000) |
| solves at a time | 1 (`SOMMERWIRE_MCP_MAX_SOLVES`, 1 to 4); a call beyond it is refused, not queued |
| solver heap | 512 MB per solve (`SOMMERWIRE_MCP_WORKER_HEAP_MB`, 64 to 4096) |

Models are strict: an unknown key anywhere is refused (not silently dropped), positions must be `w<N>b|c|e` on an
existing wire, every source/load/line value must be a finite number, and the ground type, ground method, material,
load type, roof, gutters, downpipes and boom settings must be supported values. Buried wires, wires without radius
and models without a source are refused before a solve starts. Each solve runs in its own worker thread, which is
terminated when its time runs out or the client cancels the request.

## Install

Node.js 20 or newer. From the repository root:

```bash
cd mcp
npm ci
```

This installs the pinned dependencies from `package-lock.json`: the official MCP TypeScript SDK v2 server package
(`@modelcontextprotocol/server` 2.4.0, the SDK's stable release line) and `zod` 4.6.7. The SDK client
(`@modelcontextprotocol/client` 2.4.0) is a development dependency, used by the tests only (`npm ci --omit=dev` leaves
it out). There is no build step: the server is plain JavaScript modules in `src/`. The browser app itself still has no
dependencies; nothing in `mcp/` is loaded by the page.

## Client configuration

### Hosted

**Claude Code:**

```bash
claude mcp add --transport http --scope user sommerwire https://mcp.sommerwire.app/mcp
```

or in a project's `.mcp.json`:

```json
{
  "mcpServers": {
    "sommerwire": { "type": "http", "url": "https://mcp.sommerwire.app/mcp" }
  }
}
```

**Claude (claude.ai, Claude Desktop, mobile):** **Customize → Connectors → + Add → Add custom connector**, the URL
`https://mcp.sommerwire.app/mcp` and **No sign in**. Claude connects from Anthropic's cloud. Free plans can add one
custom connector. On Team and Enterprise an owner adds it under **Organization settings → Connectors** first.
[Claude help](https://support.claude.com/en/articles/11175166-getting-started-with-custom-connectors-using-remote-mcp)

**OpenAI Codex** (CLI and IDE extension, which share `~/.codex/config.toml`):

```bash
codex mcp add sommerwire --url https://mcp.sommerwire.app/mcp
```

which writes:

```toml
[mcp_servers.sommerwire]
url = "https://mcp.sommerwire.app/mcp"
```

**ChatGPT** depends on the plan and workspace. OpenAI lists full MCP for Business, Enterprise and Edu (admins may
need to allow it), and custom MCP servers with read/fetch permissions for Pro. Sommerwire has not been tested in
ChatGPT. [OpenAI help](https://help.openai.com/en/articles/12584461)

### Local stdio

Use absolute paths; replace `/path/to/sommerwire` with the repository folder. A client keeps one entry per name, so
use another name (for example `sommerwire-local`) to keep both the hosted and the local server.

**Claude Code** (add `--scope user` to make it available in every project):

```bash
claude mcp add sommerwire -- node /path/to/sommerwire/mcp/src/server.js
```

or a `.mcp.json` in your project:

```json
{
  "mcpServers": {
    "sommerwire": { "command": "node", "args": ["/path/to/sommerwire/mcp/src/server.js"] }
  }
}
```

**Claude Desktop** (`claude_desktop_config.json`) and other stdio clients take the same `command` and `args`:

```json
{
  "mcpServers": {
    "sommerwire": {
      "command": "node",
      "args": ["/path/to/sommerwire/mcp/src/server.js"],
      "env": { "SOMMERWIRE_MCP_SOLVE_TIMEOUT_MS": "120000" }
    }
  }
}
```

**OpenAI Codex** (CLI and IDE extension, which share `~/.codex/config.toml`):

```bash
codex mcp add sommerwire -- node /path/to/sommerwire/mcp/src/server.js
```

which writes:

```toml
[mcp_servers.sommerwire]
command = "node"
args = ["/path/to/sommerwire/mcp/src/server.js"]
```

claude.ai, the Claude mobile apps and ChatGPT cannot start a local stdio process. Use the hosted server there. The
[Help page](https://sommerwire.app/help.html#h-mcp) explains the alternatives.

**Optional hardening** with Node's permission model (Node 25 or newer also restricts the network): the server needs
read access to the repository and worker threads, nothing else.

```json
"args": ["--permission", "--allow-fs-read=/path/to/sommerwire", "--allow-worker", "/path/to/sommerwire/mcp/src/server.js"]
```

The server speaks JSON-RPC on stdin/stdout and logs to stderr. With SDK 2.4.0 it negotiates protocol version
`2025-11-25` with current clients and accepts the older `2025-06-18`, `2025-03-26` and `2024-11-05` handshakes.

## Hosted server

`https://mcp.sommerwire.app/mcp` serves the same four tools over stateless Streamable HTTP, without login. It runs on
Google Cloud Run (`europe-west1`), reached through Cloud Run's native custom domain mapping with a Google-managed
certificate. It is an MCP endpoint, not a web page: `POST /mcp` only, and a browser GET gets HTTP 405.
[Deployment runbook](../deploy/cloudrun/RUNBOOK.md)

### What leaves your device

- **Hosted.** The MCP client sends the tool arguments to the service over HTTPS. JSON and `.maa` inputs can contain
  full geometry, house outlines, names, comments, frequencies and other model settings. A share link sent as a tool
  argument includes its fragment. The service decodes the fragment in memory and never opens the link. An example
  call sends its name and any options. The client may include protocol metadata. With Claude connectors, the
  request comes from Anthropic's cloud. With Claude Code and Codex, it comes from your computer.
- The app processes models in memory and returns the tool output. It has no model store, request-body logging,
  request tracing or analytics. Unexpected errors return a generic message. Google Cloud can record request metadata such
  as time, source address, method, path and status. Send models only in the JSON body, never in URLs or headers.
- **Stdio.** Sommerwire processes tool inputs and outputs on the machine running the MCP process. Use it for models
  you want to keep private.
- With either transport, a cloud-backed agent can send model details, tool outputs and chat text to its AI provider
  under that provider's settings. Treat generated share links and exports as copies of the model. Anyone with a
  share link can decode its fragment. The browser omits the fragment from its normal HTTP request when you open the
  link.

### HTTP compatibility

The official TypeScript SDK serves stateless Streamable HTTP with the 2025-era initialize flow and the 2026-07-28
per-request flow. POST uses JSON-RPC with JSON or SSE responses. There are no server-issued session IDs, standalone GET
streams, SSE resume, subscriptions, CORS headers or legacy HTTP+SSE endpoints. The service accepts only
`Host: mcp.sommerwire.app` (optionally `:443`) and an absent Origin or `https://mcp.sommerwire.app`. Query strings
are refused. The worker stops when the client disconnects, if that reaches the container, or at its deadline. A
separate `notifications/cancelled` POST cannot target a running request on another instance.

### HTTP limits

The public service runs as one Cloud Run instance (`--max=1`, concurrency 4, 1 vCPU, 1 GiB), so these limits are
shared by everyone using it. There is no availability guarantee, and it can be rate limited or switched off.

| What | Limit |
|---|---|
| Admission | Before the body is read: a burst of 8 requests, then one per second (HTTP `429`, `Retry-After: 1`). At most 4 active MCP requests (`503`) |
| Request | 1 MiB of UTF-8 JSON, one message, 24 nested levels and 48,000 values, with an 8 KiB header limit |
| Upload and exchange | 5 s to receive a body, 25 s total exchange; compressed HTTP bodies are rejected |
| Model payload | 512 KiB each for JSON, UTF-8 `.maa`, or decoded link data; `.maa` also has a 16,000-line limit |
| Validation mesh | Conservative upper bounds of 32,000 segments per frequency and 100,000 in total |
| Solve work | At most 1,200 estimated segments per frequency and 2 billion total cubed segment estimates |
| Solve capacity | One solve at a time with no queue (`503`), four burst solve attempts refilling one every 5 s (`429`), a 15 s deadline and a 192 MiB old-generation heap |

A model that exceeds a work budget, or a solve that reaches its deadline, returns a tool error. One frequency of an
RF.Guru preset takes a few seconds on the hosted instance. All eight bands of an EFOC29 in one call take longer than
15 s, so call `solve` once per band with `include_bands: false` and a `frequency`, or use stdio. The DX Commander
presets are heavier: see their [solve times and hosted limits](../validation/dx-commander/README.md#hosted-mcp).

### Run the HTTP transport yourself

After `npm ci`, `PORT=8080 npm run start:http` from `mcp/` listens on `127.0.0.1:8080`. Point a Streamable HTTP client
at `http://127.0.0.1:8080/mcp`, or check `GET /healthz`. On loopback, the Host must be `127.0.0.1:8080` or
`localhost:8080`. A cloud bind (`SOMMERWIRE_MCP_BIND=0.0.0.0`) needs an explicit `SOMMERWIRE_MCP_ACCESS`:

- `public-native`: the public service. Canonical Host only, `/healthz` hidden on that Host, and the admission limits above.
- `private-preview`: behind Cloud Run IAM for an authenticated canary. One exact `SOMMERWIRE_MCP_PROXY_HOST`
  (`*.run.app`) is allowed. Up to 8 active requests, with no pre-parse bucket.
- `public-edge` is still accepted by the runtime for a load-balancer-fronted deployment. This repository no longer
  carries its deployment tooling.

The container (`Dockerfile`, `.dockerignore` at the repository root) installs locked production dependencies, copies
only the runtime files and licence notices, and runs `node mcp/src/http.js` as the non-root `node` user.

## Worked example

Ask the client something like *"Validate and solve this 20 m dipole at 10 m over average ground, then give me a share
link and the .maa file"*. It calls the tools with:

```json
{ "model": { "name": "20 m dipole", "freq": 14.15, "material": 1,
    "wires": [{ "x1": 0, "y1": "-R/4*0.95", "z1": 10, "x2": 0, "y2": "R/4*0.95", "z2": 10, "r": 1, "seg": -1 }],
    "sources": [{ "pos": "w1c" }],
    "ground": { "type": 2, "eps": 13, "sigma": 0.005 } } }
```

`validate_model` (abridged):

```json
{ "ok": true, "frequencies": [14.15], "estimate": { "segments": 33, "houseWires": 0, "fMax": 14.15 },
  "mesh": [{ "f": 14.15, "segments": 26, "unknowns": 25, "warnings": [], "fits": true }] }
```

`solve` (abridged; figures rounded here, full precision in the result):

```json
{ "kind": "simulation", "notice": "Simulation, not measurement: …",
  "assumptions": ["Real ground: relative permittivity 13, conductivity 0.005 S/m, height offset 0 m; impedance method sommerfeld (homogeneous soil assumed).",
                  "Wire material: Copper.", "Feed impedance and SWR are those of the first source, against 50 ohm.", "…"],
  "results": [{ "f": 14.15, "R": 67.21, "X": -40.63, "swr": 2.104, "gain": 7.02, "fb": 0, "el": 29.5, "az": 0, "pol": "Horizontal",
                "flags": { "perfect_mirror_fallback": false, "uncertain": false, "warnings": 0, "…": "…" }, "warnings": [] }] }
```

`share_link` with `"pol": "h"` returns a 339-character `https://sommerwire.app/#sw=1.d.…` link that opens this
model in the app. `export_maa` returns `20 m dipole.maa` and reports one loss:

```json
{ "format_loss": ["Expressions are written as numbers at 14.15 MHz: w1.y1 = -R/4*0.95, w1.y2 = R/4*0.95."] }
```

The default example, `solve` with `{ "example": "RF.Guru EFOC29 end-fed off-centre, 80–10 m, 4:1, flat top" }`,
starts at 3.6 MHz and solves eight bands at 3.6, 7.1, 10.125, 14.175, 18.118, 21.225, 24.94 and 28.5 MHz in that order.
The sloper, inverted U and inverted L use the same frequencies. The [EFOC29 model notes](../README.md#rfguru-efoc29-example-provenance-and-assumptions)
list the simulated 50 Ω SWRs for all four layouts. Existing share links keep their saved bands, geometry and selected frequency.
Set `frequency` to choose a supported calculation frequency. Set `include_bands` to `false` to solve only that frequency.

For the EFOC17 layouts, pass one of these names as the `example` for `solve`.

- `RF.Guru EFOC17 end-fed off-center, 40/20/15/10 m, 4:1, sloper` (alias `RF.Guru EFOC17 sloper`)
- `RF.Guru EFOC17 end-fed off-center, 40/20/15/10 m, 4:1, inverted L` (alias `RF.Guru EFOC17 inverted L`)

Both start at 7.1 MHz in Horizontal + vertical and solve 7.1, 10.125, 14.175, 18.118, 21.225, 24.94 and 28.5 MHz in that order.
Both feeds are at 4 m. The sloper top is 16 m and the inverted L top is 14 m. See the supplied model assumptions and
simulated 50 Ω SWRs in the [EFOC17 layout notes](../README.md#rfguru-efoc17-sloper-and-inverted-l).

For EFOC8, use `solve` with `{ "example": "RF.Guru EFOC8 end-fed off-centre, 20/10 m, 4:1, flat top" }`.
It starts at 14.175 MHz and also solves 28.5 MHz, with simulated 50 Ω SWRs of 1.65 and 2.74. The preset uses the
supplied share geometry with an ideal 4:1 unun and about 2.1 m of modeled coax shield ending at the ideal choke.

For EFOC30 and EFOC1712, pass one of these names as the `example` for `solve`.

- `RF.Guru EFOC30 end-fed off-centre, 30 m, 4:1, flat top` opens and solves at 10.125 MHz, with simulated SWR 1.0352.
- `RF.Guru EFOC1712 end-fed off-centre, 17/12 m, 4:1, flat top, 2.5 m stub` opens at 18.118 MHz and also solves
  24.94 MHz, with simulated SWRs of 1.0172 and 1.2435.

Both have 8 m feed and top heights and leave the polarization view unspecified.
[Original share links and geometry](../README.md#rfguru-efoc30-and-efoc1712-flat-tops)

For the EFOC1712 sloper (menu ID 45), pass
`RF.Guru EFOC1712 end-fed off-centre, 17/12 m, 4:1, sloper, 2.62 m stub` as the `example` for `validate_model`
or `solve`. It opens at 18.118 MHz and also solves 24.94 MHz, with simulated 50 Ω SWRs of 1.0871 and 1.1782.
The feed and top heights are both 8 m, and `validate_model` returns an empty `view` object.
[Original share and geometry](../README.md#rfguru-efoc1712-sloper)

For the monoband EFHW inverted-Ls, pass one of these names as the `example` for `validate_model` or `solve`.
Each opens and solves at one frequency, its simulated SWR dip, and returns `{ "pol": "hv" }` as its `view`.

- `RF.Guru EFHW16080 monoband inverted-L, 160 m, 68:1` (menu ID 46): 1.932 MHz, simulated 50 Ω SWR 1.3204,
  feed 3.70 m and top 26.00 m.
- `RF.Guru EFHW8040 monoband inverted-L, 80 m, 70:1` (menu ID 47): 3.681 MHz, SWR 1.0846, feed 1.00 m and top 13.50 m.
- `RF.Guru EFHW8040 monoband inverted-L, 40 m, 70:1` (menu ID 48): 7.102 MHz, SWR 1.0631, feed 1.00 m and top 13.50 m.

They are the `RF.Guru EFHW16080 inverted-L, 160/80 m, 68:1` and `RF.Guru EFHW8040 inverted-L, 80/40 m, 70:1` examples
with only the horizontal wire shortened. Those two names are unchanged and still solve both of their bands.
[Band edges, SWR windows and limits](../README.md#rfguru-monoband-efhw-inverted-ls)

For the 49:1 EFHW flat tops, pass the canonical name or the short alias as the `example`. Both return
`{ "pol": "hv" }` as their `view`, and feed and top are both 15.9 m.

- `RF.Guru EFHW4020 flat top, 40/20 m, 49:1` (alias `RF.Guru EFHW4020 flat top`, menu ID 49): opens at 7.1 MHz and
  also solves 14.248 MHz, with simulated 50 Ω SWRs of 1.3996 and 1.0043. The 20.51 m radiator is at 15.9 m.
- `RF.Guru EFHW20 flat top, 20 m, 49:1` (alias `RF.Guru EFHW20 flat top`, menu ID 50): solves 14.169 MHz only, its
  simulated dip, SWR 1.2158. The 10.07 m radiator was trimmed from exactly half the EFHW4020's, 10.255 m.

[Geometry, assumptions and bandwidth](../README.md#rfguru-efhw4020-and-efhw20-flat-tops-491)

For the 80/40 m centre-stub sloper, pass `RF.Guru EFOC8040 sloper, 80/40 m, 4:1, centre stub` as the `example`.
Its former name, `RF.Guru EFOC sloper, 80/40 m, 4:1, centre stub`, remains an alias.
It starts at 3.6 MHz and solves 3.6 and 7.1 MHz with simulated 50 Ω SWRs of 1.46 and 1.64. Feed and top height
are both 10 m. The preset and its original share leave the polarization view unspecified.

For the 12 m TermiLoop models, pass either example name to `solve`.

- `RF.Guru TermiLoop far end terminated, allband, flat top loop` models a load at `w5c` and gives a simulated SWR of 1.078 at 7.1 MHz. Its former name, `RF.Guru TermiLoop approximation, 12 m high`, remains an alias.
- `RF.Guru TermiLoop cold side terminated, allband, flat top loop` models a load at `w4c` and gives a simulated SWR of 4.507 at 7.1 MHz. Its former name, `RF.Guru TermiLoop approximation, 12 m high, feed-end termination`, remains an alias.

The models use the supplied approximate loop geometry and termination placement. Both start at 7.1 MHz in
Horizontal + vertical and keep the saved band list of 1.85, 3.6, 5.36, 7.1, 10.125, 14.175, 18.118, 21.225,
24.94, 28.5 and 50.15 MHz. `solve` returns the 7.1 MHz result first, followed by the other ten bands in list order.
[12 m share URLs, geometry and simulated SWRs](../README.md#termiloop-approximations-at-12-m)

For the DX Commander group, pass one of these names as the `example`. Each opens on its lowest band and lists all its
bands. The older `DX Commander vertical, fed against the ground` and `DX Commander vertical, 16 × 5 m radials` keep
their names and models.

- `DX Commander Classic, 40–10 m` (menu ID 51), `DX Commander Signature 9, 40–10 m` (52) and
  `DX Commander Expedition, 40–10 m` (53): 7.1, 10.125, 14.175, 18.118, 21.225, 24.94 and 28.5 MHz.
- `DX Commander Expedition speed build, 40/20/15/10 m` (54): 7.1, 14.175, 21.225 and 28.5 MHz.
- `DX Commander Rapide, 30–10 m` (55): 10.125, 14.175, 18.118, 21.225, 24.94 and 28.5 MHz.
- `DX Commander Nebula 18 m, 80–17 m` (56): 3.6, 5.36, 7.1, 10.125, 14.175, 18.118 and 21.225 MHz.

They are starting models from the manufacturer's cut charts. Their results are simulated, with labelled
assumptions and several high SWRs. Through the MCP worker on a desktop machine, one frequency takes 3–9 s, and
8–20 s for the Nebula above 5.36 MHz. On the hosted service, all bands of any of them in one call exceed the work budget, so
call `solve` with `include_bands: false` and one `frequency`. The Nebula from 7.1 MHz up is refused even then. The
21–28.5 MHz bands of the others pass the work budget but may reach the 15 s deadline. Use local stdio for those.
[Sources, coverage, results and solve times](../validation/dx-commander/README.md)

For the RF.Guru Rigid Multiband Verticals group, pass one of these names as the `example`:

- `RF.Guru VertX A, original layout` (menu ID 57, menu label VertX A, original layout) and
  `RF.Guru VertX B, 10 m wire sloped out` (58, VertX B, 10 m wire sloped out): 3.65, 7.1, 10.125, 14.175, 18.118,
  21.225, 24.94 and 28.5 MHz.
- `RF.Guru VertX C, no 40/80 m wires, 15 and 10 m wires sloped out` (59, VertX C, no 40/80 m wires, 15 and 10 m wires
  sloped out): 10.125, 14.175, 18.118, 21.225, 24.94 and 28.5 MHz.
- `RF.Guru VertX D, 20–10 m` (60, VertX D, 20–10 m): 14.175, 18.118, 21.225, 24.94 and 28.5 MHz. Designed in Sommerwire,
  not a supplied link (below).

A, B and C are each a supplied share link as it is, with only the name changed. `validate_model`, `solve`, `export_maa` and
`share_link` get the link's model. The calculation frequency is the link's 14.175 MHz, so `solve` returns 14.175 MHz
first, and there is no view (`{}`). The junction rule is the link's: wires join at their ends only. `share_link`
returns the link's payload under the new name. The presets have 75 to 79 wires and 1,336 to 1,502 unknowns per band,
and their results are simulated, with the links' own assumptions.

On local stdio, one frequency took 18.6 to 23.2 s on a desktop machine, so all bands in one call can exceed the 120 s
budget. Over a stdio server with nothing else running, all bands of VertX A and B were stopped at 120 s, and VertX C
finished in 119.3 s. Call `solve` with `include_bands: false` and one `frequency`, or raise
`SOMMERWIRE_MCP_SOLVE_TIMEOUT_MS`. The hosted service refuses every band of all three, alone or together, with "The
model exceeds the hosted solve work budget". The 64 radials alone count 1,344 segments against its 1,200 per
frequency. The three preset names are available in local stdio from this checkout. For hosted MCP, pass the supplied
`share_link` to `validate_model`, `export_maa` or the `share_link` tool rather than relying on its built-in catalog.
[Links, results and timings](../validation/vertx/README.md)

`RF.Guru VertX D, 20–10 m` was designed in Sommerwire for this edition from VertX C's tube, clamp, feed lead and
radials: the tube is the 20 m radiator, the 17 and 15 m wires run straight up beside it and the 12 and 10 m wires slope
up and out from their own holes. Its model, calculation frequency (14.175 MHz), view (`{}`) and junction rule (wire ends
only) are those of its stored link, [tests/fixtures/vertx-d.share](../tests/fixtures/vertx-d.share). `share_link` by
name returns a link that decodes to the same model, frequency and view; its compressed characters can differ from
the stored link's, because deflate output depends on the runtime's zlib. It has 77 wires and 1,368 to 1,395 unknowns
per band. Solve it on local stdio, one band per call, as A, B and C: the hosted service refuses every band of D too,
alone or together, before solving (its 64 radials are VertX C's). The results are simulated, not measured.
[Design, search and results](../validation/vertx-d/README.md)

The original 8 m `RF.Guru TermiLoop approximation` built-in is retired. Pass the original saved URL as
`share_link` to validate or solve it with its saved settings.
[Original 8 m TermiLoop share](../tests/fixtures/termiloop-original.share)

## Tests

```bash
cd mcp
npm test            # node --test test/
```

The tests start the real server over stdio with the official SDK client: initialize, tools/list and tools/call of all
four tools; an older client's raw JSON-RPC handshake; unknown tools, methods and arguments, malformed and oversized
messages; the server under Node's permission model; the EFOC29 default bands against the pinned SWRs and against the
engine and page code loaded independently (as `tests/` loads them); ground-contact and complex-image warnings and
flags; the time budget (the worker is killed and the next call works) and the concurrency limit; strict-schema, share-bound and
ill-formed-model refusals; share links of every example decoded by `share.js` to the same solver input; `.maa` export
against the bundled model files and the format-loss report; the junction report and the opt-in junction rule
(`test/topology.test.js`). `test/power.test.js` covers `power` (equal to the app
pipeline, bounded, no shares for a non-passive result), the opt-in `branch_currents`, and the hosted limits staying
as they were. `test/http.test.js` covers the HTTP transport: Host and
Origin checks, body, JSON and mesh limits, admission and solve quotas, the `public-native` profile, and SDK calls over
loopback. `test/smoke.test.js` runs the deployment smoke test (`deploy/cloudrun/smoke.mjs --public-native`) against a
loopback `public-native` server. `test/feed-network.test.js` covers measured loads (load type 3) over stdio and over
the hosted transport: the schema, validation and solve against the engine, refusals, share links, `.maa` export and
the unchanged request bounds. `test/system-chain.test.js` covers the radio side and the ferrite choke (load type 4)
over stdio: upstream's file with its planes and account from the radio, the choke's fields and refusals, upstream's
`.maa` lines through `export_maa` and `share_link`, the transmit power kept through `solve`, `export_maa` and `solve`
again with or without a feed line (0 W too), and the signed power at both ends of each line of two coupled dipoles,
one of them taking power from the array, with lossless lines passing on all of it; with the second source at 0 V (its
feed point shorted) or a tiny voltage either way, its line dissipating what its radio puts in; and every tool that
takes a model giving the unun or balun's winding line loss in dB per metre at 10 MHz. `test/integration.test.js` covers one model with the junction rule, a fixed resistor
and a measured load through all four tools, over stdio and the hosted transport (the page's figures, the loss of the
same solve on the measured load, a band outside the table refused by name, links and `.maa` files that carry both
fields), and the runtime files: the loader, the Dockerfile, `.dockerignore` and the deploy check name the same
files, and a tree of only those files gives the same answers as the checkout. `test/dx-commander.test.js` covers the
DX Commander group: every tool takes the six presets and the two older verticals by name, a stdio solve of each
preset matches the stored study, a link saved before the catalogue gives the same model and solve, and over a real
HTTP server the hosted guard admits and refuses the bands listed above. `test/vertx.test.js` covers the VertX presets:
every tool takes the three names, each gives the model, frequency, view and solver input of its supplied link and a
`share_link` with its link's payload under the new name. One stdio solve of VertX A matches the stored study, and the
hosted guard refuses every band, also over a real HTTP server. `test/vertx-d.test.js` covers VertX D: every tool takes
its name, right after C; by name and by its stored link it gives the same model, frequency, view and solver input;
`share_link` returns a link with the stored link's decoded payload, `validate_model` the stored bands and unknowns, and one stdio solve
matches the stored study; the hosted guard refuses every band. The mesh convergence check of the page
is not a tool and no code of it is on the server.

## How it reuses the app

`src/app.js` loads `engine.js`, `structgen.js`, `hexgen.js`, `efhwgen.js`, `share.js` and `topology.js` unchanged into a `vm`
context, and takes the app's own model code from `index.html` by its section markers, the way the repository's tests
do: the examples, `normalize()` and `numericModel()`, the hexbeam table, `modelFromMAA()` and `maaFile()`, and the
worker's `packZ()` / `finish()`. The only browser-file change made for the server is the `.maa` row-count check in
`engine.js`, which refuses a truncated file in the app too. If those markers move,
`loadApp()` stops with a message naming the missing section, and the tests fail.

## Files

```
mcp/package.json, package-lock.json   pinned dependencies
mcp/src/tools.js                      the four tools, shared by both transports
mcp/src/server.js                     stdio entry point with its message cap
mcp/src/http.js, http-server.js       Streamable HTTP entry point: Host/Origin, admission, body and deadline limits
mcp/src/http-budget.js                hosted input, mesh and solve budgets
mcp/src/core.js                       schemas, sources, validation, labels, share link, .maa export
mcp/src/solver.js, solve-worker.js    solves in a worker thread with time, heap and concurrency limits
mcp/src/app.js                        loads the app's code (above)
mcp/test/                             node --test, through the SDK client over stdio and HTTP
```
