# sa-mcp — SA1 stdio MCP :id=top

------

> _Doc Ver:_ 1.0  
_App Ver:_ 2.6.6.53  
_Date:_ 09/10/2026

------

`sa-mcp` exposes existing **sa-web HTTP** as MCP tools for Cursor / Claude / other MCP clients. Separate process, **stdio** by default, no TCP listen, **do not** embed it in sa-web, no built-in LLM, not sax.

Binary: `/var/sa/bin/sa-mcp` in the package, **not** supervised. There is no `--listen` flag; do not run it as a daemon.

**Not** SA2 `sa_mcp` (no daq `:8081` / `sa_control` `:8090` / MQTT). Do not open 7090.

Hub: [Ops tools](ops.md). Same HTTP as [sa-cli](sa-cli.md). Checkup: [sa-doctor](sa-doctor.md). JSON: [API §8](api.md).

The binary `--help` text is **Chinese**. English below matches it.

```bash
sa-mcp --help          # print help and exit 0 immediately
sa-mcp --version
# no args: wait on stdin. Hanging with an empty TTY is normal for an MCP server.
```

**Do not** put `--help` / `--version` in Cursor `mcp.json` `args`, or the child exits at once and the client reports a disconnect.

------

## 1. CLI help (same coverage as `sa-mcp --help`) :id=cli

```
sa-mcp 2.6.6.29 — SA1 stdio MCP server (not SA2 sa_mcp)

Wraps sa-web HTTP as MCP tools. Separate process, stdio, no TCP port,
do not embed in sa-web. Remote is HTTP only. Do not open 7090. Not sax,
no built-in model.

Usage:
  sa-mcp [flags]                 # stdio MCP (Cursor child)
  sa-mcp --help                  # print this and exit 0; never put in mcp.json args
  sa-mcp --version
  sa-mcp                         # no args: wait on stdin. Not help. Blocking is normal.

Flags:
  --url URL          sa-web: host, host:port, or http://host[:port]
                     If omitted, probe 127.0.0.1 80 → 8080 → 81. Env: SA1_URL
  --user NAME        Web user (default admin). Env: SA1_USER
  --password PASS    Web password. Env: SA1_PASSWORD (required except sa1_info)
  --timeout DURATION HTTP timeout (default 12s)
  -h, --help         this text and exit
  -v, --version      print version and exit

Environment: SA1_URL  SA1_USER  SA1_PASSWORD  (or flags)

Transport: MCP 2024-11-05, stdio. Prefer Content-Length: N, then a blank line,
           then N bytes of JSON (N max 8MiB; header ends with CRLF blank line).
           Without Content-Length, one JSON object per line.
Methods: initialize, ping, tools/list, tools/call, resources/list, prompts/list
         notifications/initialized (notifications with no id are not answered)
initialize.serverInfo: name=sa-mcp, version=this binary
resources/list and prompts/list return empty arrays (this process has none)

Tools (tools/list):

  sa1_info       public GET /api/info. No args. No password.
  sa1_health     GET /api/ops/health after login. No args.
  sa1_me         GET /api/me. No args.
  sa1_scpi       whitelist SCPI. Args: cmd (string, required), confirm (bool)
                 reads (? or :JSON:GET / :JOSN:GET / :FILE:GET / :FBG:GET /
                 :FBG:CFG / :VS:GET / :VS:CFG) allowed; writes need confirm=true.
                 Gateway still denies *CHS! / *CHW! / :CMD? shell / :SYS:HOOK /
                 shutdown-upgrade family.
                 e.g. {"cmd":"*IDN?"}
                      {"cmd":":DATA:PVJ?"}
                      {"cmd":":SYS:RELOAD","confirm":true}
                 Precise-wl verify with :DATA:PVJ?, not :DATA:PV?
                 After precise_wl.json: sa1_reload with confirm true
  sa1_sensors    :FBG:CFG?. No args.
  sa1_frq        :SYS:FRQ? (hardware rate, immediate; not 20s :DATA:FRQ?).
  sa1_save       data_save.json. No args.
  sa1_reload     :SYS:RELOAD. confirm=true required. Operator.
                 e.g. {"confirm":true}
  sa1_set_time   :SYS:TIME. value (string, required) + confirm=true.
                 value is one token (Unix seconds or sa-di stamp); no ;|& or space.
                 e.g. {"value":"1710000000","confirm":true}
  sa1_upgrade    background sa1-upgrader upgrade -y. confirm=true. No reboot.
                 Log: /home/debian/sa1/persist/log/sa1-upgrader.log
                 e.g. {"confirm":true}

Discover: without a port, 80 → 8080 → 81 (3s each). --timeout after login (12s).
          Without --password / SA1_PASSWORD, every tool except sa1_info errors.

RBAC is sa-web: guests cannot reload/upgrade; MCP only adds confirm.
Destructive tools without confirm=true are refused locally (no HTTP to the device).

Cursor on the device: command /var/sa/bin/sa-mcp, args --url http://127.0.0.1,
env SA1_USER / SA1_PASSWORD. On a laptop, point command at your built binary
and --url at the device HTTP. Do not commit the password.

Exit codes:
  0   stdin closed (client disconnect) or --help / --version
  1   runtime (bad frame, …)
  3   usage / unknown flag

Binary: /var/sa/bin/sa-mcp (package, not supervised; not a long-running --listen daemon)
Not: SA2 sa_mcp; not sax; not inside sa-web; no LAN 7090.
```

------

## 2. Tools (complete list) :id=tools

| Tool | HTTP | Arguments | Password | Local confirm | Role |
|------|------|-----------|----------|---------------|------|
| sa1_info | GET `/api/info` | none | no | | public |
| sa1_health | GET `/api/ops/health` | none | yes | | signed in |
| sa1_me | GET `/api/me` | none | yes | | signed in |
| sa1_scpi | GET `/tcpclient.php?cmd=` | `cmd` required; writes need `confirm=true` | yes | writes | writes also need operator (gateway 403) |
| sa1_sensors | `:FBG:CFG?` | none | yes | | signed in |
| sa1_frq | `:SYS:FRQ?` immediate | none | yes | | signed in. **No** `:DATA:FRQ?` tool — use `sa1_scpi` |
| sa1_save | GET `/getjson.php?name=data_save.json` | none | yes | | signed in |
| sa1_reload | POST `/api/ops/action` op=reload | `confirm=true` required | yes | refused locally if missing | operator |
| sa1_set_time | POST op=time | `value` + `confirm=true` | yes | refused locally if missing | operator |
| sa1_upgrade | POST op=upgrade | `confirm=true` | yes | refused locally if missing | operator; no reboot by default |

No-arg tools use MCP `inputSchema` `{"type":"object","properties":{}}`.

Read-SCPI detection matches sa-cli. Successful `tools/call` returns `content: [{type:text, text:…}]`. Failures (missing confirm, HTTP 4xx) set `isError: true`.

------

## 3. Protocol :id=proto

- **MCP 2024-11-05**
- `initialize` → `protocolVersion`, `capabilities.tools`, `serverInfo.name=sa-mcp`, `serverInfo.version` (same as `--version`), `instructions` (HTTP only; destructive tools need `confirm=true`)
- `ping` → `{}`
- `tools/list` → all 10 tools above
- `tools/call` → `{name, arguments}`
- `resources/list` / `prompts/list` → empty arrays
- `notifications/initialized`: no id, no reply
- Framing: `Content-Length` (max 8MiB) + CRLF blank line + N bytes; else one JSON line
- `confirm` also accepts strings `"true"` / `"1"`

------

## 4. Cursor / Claude :id=cursor

On the device (`mcp.json`):

```json
{
  "mcpServers": {
    "sa1": {
      "command": "/var/sa/bin/sa-mcp",
      "args": ["--url", "http://127.0.0.1"],
      "env": {
        "SA1_USER": "admin",
        "SA1_PASSWORD": "…"
      }
    }
  }
}
```

Laptop: `command` is your built `sa-mcp` (static Go on macOS is fine); `--url` is `http://<device-IP>` (`:8080` or `:81` if port 80 is unbound). Password in `env` only. Claude Desktop uses the same `mcpServers` block. **Do not** add `--help` to `args`.

------

## 5. Exit codes :id=exit

| Code | When |
|------|------|
| 0 | client closed stdin, or `--help` / `--version` |
| 1 | runtime (bad frame, …) |
| 3 | unknown flag |

Missing `SA1_PASSWORD` does **not** exit 3 at startup. The first `tools/call` that needs login fails (`sa1_info` excepted).

------

## 6. Precise wavelength :id=wlcal

Verify with `sa1_scpi` `{"cmd":":DATA:PVJ?"}`, not `:DATA:PV?`. After persist `precise_wl.json`, `sa1_reload` `{"confirm":true}`. Vs wavemeter ~+22 pm → 0.5 pm. [Precise wavelength](precise_wl.md) “Command line”.

------

### [Top](#top)
