misc-mcp-server
# misc-mcp-server
A personal, modular [MCP](https://modelcontextprotocol.io) server. The first connectors let an
**LLM agent operate embedded boards on its own** (Raspberry Pi, Jetson Nano, Android/adbd boards)
over **SSH** and **ADB**: run commands, start and watch long-running jobs, read and write files.
More connectors (web scraping, ...) can be added as plain Python files.
## Setup
```bash
python3 -m venv .venv
.venv/bin/pip install -e ".[dev]"
cp config.example.yaml config.yaml # optional, then edit your devices
```
For ADB tools, install `adb` (`sudo apt install adb` or Android platform-tools).
### Register with Claude Code
```bash
claude mcp add --scope user misc -- /path/to/misc-mcp-server/.venv/bin/misc-mcp \
--config /path/to/misc-mcp-server/config.yaml
```
To let the agent run these tools without asking each time, allow them in Claude Code settings
(`"permissions": {"allow": ["mcp__misc"]}`) — or allow only the read-only ones and keep
`ssh_exec` / `adb_shell` on approval.
Other MCP clients (Claude Desktop, Cursor, ...) use the same command in their JSON config.
For a network server: `misc-mcp --transport streamable-http --port 8765` (endpoint `/mcp`).
## Docker
```bash
docker build --build-arg UID=$(id -u) --build-arg GID=$(id -g) -t misc-mcp .
```
Register the container as a stdio MCP server (the client starts it on demand):
```bash
claude mcp add --scope user misc -- docker run -i --rm --network host \
-v ~/.ssh:/home/mcp/.ssh:ro \
-v misc-mcp-data:/data \
-v /path/to/misc-mcp-server/config.yaml:/config/config.yaml:ro \
-v ~/mcp-files:/workspace \
-e JETSON_PASSWORD \
misc-mcp
```
| Mount / flag | Why |
|---|---|
| `-i` | stdio transport needs stdin open (no `-t`) |
| `--network host` | reach boards on your LAN by their usual addresses, and reuse the **host's adb server** at `localhost:5037` (USB devices + already-authorized keys just work; start it on the host with `adb start-server`) |
| `~/.ssh:/home/mcp/.ssh:ro` | your keys and `~/.ssh/config` aliases (build with your UID so keys are readable) |
| `misc-mcp-data:/data` | writable `known_hosts` for newly accepted boards (seeded from your `~/.ssh/known_hosts`) |
| `config.yaml:/config/config.yaml` | device list (optional) |
| `~/mcp-files:/workspace` | local paths used by `*_upload`, `*_download`, `adb_push`/`adb_pull` refer to the **container**; this is the shared folder |
| `-e VAR` | forward env vars referenced by `password_env` / `sudo_password_env` |
Without host networking, let the container run its own adb server instead: add
`--device /dev/bus/usb -v ~/.android:/home/mcp/.android` (USB) and use `adb_connect` for network devices.
HTTP mode (one long-lived server, several clients):
```bash
docker run -d --name misc-mcp --network host -v ~/.ssh:/home/mcp/.ssh:ro -v misc-mcp-data:/data \
misc-mcp --transport streamable-http --host 127.0.0.1 --port 8765
claude mcp add --scope user --transport http misc http://127.0.0.1:8765/mcp
```
## What makes it agent-ready
- **Non-interactive by design**: stdin is closed unless given, so prompts can't hang a call;
`sudo` works with a configured password (`sudo -S`, fed over the channel, never in argv) or `sudo -n`.
- **Timeouts really stop things**: on timeout the remote command's whole process group is killed.
- **Background jobs** for anything long (builds, servers, training, flashing, `tail -f`):
`*_job_start` returns a `job_id` immediately; `*_job_status` can wait up to 10 min for completion and
returns state, exit code and the output tail. Jobs live on the device, so they survive dropped connections.
- **Robust output**: binary/garbled output is decoded leniently and long output is truncated (head + tail).
- **New boards work first time**: host keys are accepted on first contact (`accept-new`), but a
*changed* key is refused.
- **Readable errors**: failures (unreachable host, auth, missing file, adb unauthorized...) reach the
model as text it can act on.
- Commands run in the user's login shell (bash on Pi/Jetson), each call in a fresh shell (use `cwd`).
## Tools
### SSH (`ssh` connector)
`target` = device name from config, a `~/.ssh/config` alias, or `[user@]host[:port]`.
Connections are pooled; `~/.ssh/config` (HostName, User, Port, IdentityFile, ProxyJump) and
your ssh-agent are honoured.
| Tool | What it does |
|---|---|
| `ssh_list_targets` | configured devices, `~/.ssh/config` hosts, open connections |
| `ssh_exec` | run a command → exit code / stdout / stderr; `timeout`, `cwd`, `stdin`, `sudo` |
| `ssh_job_start` / `ssh_job_status` / `ssh_job_list` / `ssh_job_stop` | background jobs (with `sudo` too) |
| `ssh_read_file` / `ssh_write_file` | read (chunked) / write text files over SFTP |
| `ssh_board_info` | model, OS, kernel, CPU, RAM, disk, temps, network, Jetson L4T/JetPack, Pi `vcgencmd` |
| `ssh_upload` / `ssh_download` | SFTP file or directory transfer |
| `ssh_disconnect` | close one or all pooled connections |
### ADB (`adb` connector)
`device` = configured name, serial, or omitted when only one device is attached.
| Tool | What it does |
|---|---|
| `adb_devices` | attached devices (`adb devices -l`) + configured ones |
| `adb_connect` / `adb_disconnect` | TCP/IP connections |
| `adb_shell` | run a command; `timeout`, `cwd`, `stdin`, `root` (via `su`) |
| `adb_job_start` / `adb_job_status` / `adb_job_list` / `adb_job_stop` | background jobs |
| `adb_read_file` / `adb_write_file` | read / write text files |
| `adb_device_info` | Android properties + the same board overview as SSH |
| `adb_push` / `adb_pull` | file transfer |
| `adb_logcat` | dump recent logcat lines with optional filter |
| `adb_install` | install an APK |
| `adb_reboot` | reboot (normal / bootloader / recovery / ...) |
## Security notes
- These tools run **arbitrary commands** on your devices. Only connect the server to clients you trust.
- Put passwords in env vars (`password_env`, `sudo_password_env`) — never as tool arguments.
- `host_key_policy: accept-new` trusts a board on first contact (like OpenSSH's
`StrictHostKeyChecking=accept-new`). Use `strict` on untrusted networks.
## Adding a connector
1. Create `src/misc_mcp/connectors/<name>.py` with `register(mcp, config)`; decorate tools with
`@tool(mcp, ...)` from `misc_mcp.connectors` (gives the model readable error messages).
Read your settings from `config.section("<name>")`. Return an async cleanup function or `None`.
Shell-like connectors can reuse `connectors/_shell.py` (exec with kill-on-timeout + background jobs)
by implementing its small `Backend` protocol.
2. Add it to `AVAILABLE` in `src/misc_mcp/connectors/__init__.py`.
3. Enable it under `connectors:` in `config.yaml`.
## Tests
```bash
.venv/bin/pytest
# live tests against a real board (exec, timeouts, jobs, files, host keys):
MISC_MCP_TEST_SSH_HOST=pi@192.168.1.50 MISC_MCP_TEST_SSH_KEY=~/.ssh/id_ed25519 .venv/bin/pytest
```
TDQS
Scored across 28 tools
The ssh_* and adb_* families form two clearly parallel, non-overlapping domains, and within each domain the tools split cleanly into exec/job/file/device concerns. The only mild overlaps are text-writing tools (ssh_write_file, adb_write_file) versus transfer tools (ssh_upload, adb_push), but descriptions make the text-vs-file distinction explicit. ssh_job_list vs ssh_job_status and their adb twins are also easily told apart.
Nearly everything follows a predictable `domain_noun_verb` pattern (ssh_job_start, adb_read_file, adb_device_info) in consistent snake_case with a domain prefix. The one deviation is ssh_list_targets, which flips to verb-noun ordering unlike ssh_job_list/adb_job_list, a minor blemish in an otherwise uniform scheme.
28 tools is on the heavy side, but it is really two symmetric 14-tool domains (SSH and ADB), each of which covers exec, background jobs, file transfer and diagnostics with no filler. A dual-domain server justifies the size better than most, yet it still sits above the comfortable 15-tool range and could be trimmed by folding job_list into job_status.
Both domains are close to lifecycle-complete: shell exec, background job start/status/list/stop, file read/write/transfer, device/board info, and connect/disconnect are all present, with ADB adding install, logcat and reboot. Remaining gaps are modest but real — no adb_forward/reverse port forwarding, no uninstall, and no explicit file-delete (workable via shell exec).