Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
ec1988c
CLI: add the MCP SDK at the desktop pin
sambitcreate Nov 11, 2026
53391e7
Merge remote-tracking branch 'origin/claude/aiden-mcp-server-core' in…
sambitcreate Nov 11, 2026
985b3cf
aiden serve: host the loopback /mcp endpoint, managed with aiden apps
sambitcreate Nov 11, 2026
a656aa8
Merge remote-tracking branch 'origin/claude/aiden-mcp-server-core' in…
sambitcreate Nov 11, 2026
6fa6b5a
aiden apps revoke: disconnect an app while Bot storage waits for repair
sambitcreate Nov 11, 2026
e740f3e
Merge remote-tracking branch 'origin/claude/aiden-mcp-server-core' in…
sambitcreate Nov 11, 2026
77378e5
aiden apps: count an app name's characters, and document the any-port…
sambitcreate Nov 11, 2026
016493a
Merge branch 'ciw-800' into ciw-802
sambitcreate Nov 11, 2026
35875f8
aiden apps revoke: use the shared Bot notice revoke policy
sambitcreate Nov 11, 2026
bb047a9
Merge branch 'ciw-800' into ciw-802
sambitcreate Nov 11, 2026
f6eb360
aiden apps connect prints each app's own token variable
sambitcreate Nov 11, 2026
79ff4a6
Merge remote-tracking branch 'origin/claude/aiden-mcp-server-core' in…
sambitcreate Nov 17, 2026
82057dd
copy(cli): say this Mac or this computer for where the MCP server lis…
sambitcreate Nov 17, 2026
a957577
Merge remote-tracking branch 'origin/main' into mcp-802-local
sambitcreate Nov 17, 2026
4cf6f75
Merge remote-tracking branch 'origin/main' into mcp-802-local
sambitcreate Nov 17, 2026
79b21b5
Merge remote-tracking branch 'origin/main' into mcp-802-local
sambitcreate Nov 18, 2026
121b9db
Merge remote-tracking branch 'origin/main' into mcp-802-local
sambitcreate Nov 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions .memory/aiden-mcp-server.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Aiden MCP server for outside apps (W4a, 2026-11-11)

Core only: a loopback MCP server that lets Claude Code, Codex or any MCP client use Aiden's chats. Ported in spirit from T3 Code PR #33196 (no code copied). Off by default, with no Settings UI yet (W4b) and no `aiden serve` wiring (W4c). User docs: `docs/aiden-mcp-server.md`; threat model section 10 of `docs/security/aiden-remote-threat-model.md`. README and PRODUCT.md make no claims until W4b ships.
Core only: a loopback MCP server that lets Claude Code, Codex or any MCP client use Aiden's chats. Ported in spirit from T3 Code PR #33196 (no code copied). Off by default, with no Settings UI yet (W4b); `aiden serve` hosts it too (W4c, below). User docs: `docs/aiden-mcp-server.md`; threat model section 10 of `docs/security/aiden-remote-threat-model.md`. README and PRODUCT.md make no claims until W4b ships.

## Layout

Expand Down Expand Up @@ -58,7 +58,31 @@ Core only: a loopback MCP server that lets Claude Code, Codex or any MCP client
- Its client is `@earendil-works/pi-mcp` `McpClient`. ESLint forbids importing `@modelcontextprotocol/sdk/client*`.
- A fake generation's finish must check `owner.isDestroyed()` first, because `owner.send` throws after revocation.

## Open for W4b and W4c
## Headless server (W4c, 2026-11-11)

`aiden serve` hosts the same endpoint, and `aiden apps list|connect|revoke|on|off` manages it.

- **Wiring:**
- `packages/cli/src/apps.ts` has `createCliMcpHost` and `cliAppsCommand`.
- `packages/cli/src/apps-display.ts` holds the connect rendering, the snippets and `CLI_MCP_DEFAULT_PORT`. It has type-only imports, so the admin client never loads the SDK.
- The SDK is pinned at `@modelcontextprotocol/sdk` 1.32.1 in `packages/cli/package.json`, the desktop pin.
- **Inside the Remote runtime.** `createCliRemote` builds the host:
- The chat runtime is shared through a memoized `loadChatApi` (a failed load is retried).
- MCP gets its own cached `AidenRemoteWorkspaceService`, so it never rebuilds Remote's host feed.
- `revokeDevice` is the one shared path that drains feeds, runs and Bot sessions and calls `revokeAidenRemoteRuntimeDevice`; `remote revoke` uses it too.
- `start()` calls `mcp.initialize()` after Remote is up, and a failure only logs. `stop()` stops MCP first.
- `--no-remote` means no MCP server: `serve.ts` refuses `apps` with a restart hint.
- **Port.** 49500–49507 (`CLI_MCP_DEFAULT_PORT`), a +100 shift from the desktop's 49400, mirroring Remote's 49220 → 49320. It is saved in `remote.json`. Tests pass `mcpPort: 0`.
- **Off by default.** `connect` calls `setEnabled(true)` before `issueApp`, so a failure to enable never loses a just-issued token. An argument error refuses before either step. The default access is Read.
- **Connect output.** On a TTY, `commands.ts` renders text with the token once and `claude mcp add --scope user --transport http aiden <url> --header 'Authorization: Bearer ${AIDEN_MCP_TOKEN_<NAME>_<ID>}'` / `codex mcp add aiden --url <url> --bearer-token-env-var AIDEN_MCP_TOKEN_<NAME>_<ID>`, the per-app name from core's `aidenMcpTokenEnvName` (renderer/shared/aiden-mcp-token-env.ts), the same one W4b's Settings sheet prints. Piped output is JSON plus a stderr warning, like pairing.
- **Analytics.** `remote-chats.ts` passes `deviceReportsAnalytics` (false for `agent` devices), matching the desktop. `aiden apps` sends nothing.
- **Docker.** Container loopback is unreachable from the host, which is documented. MCP without Remote would be a possible follow-up.
- **Tests.** `packages/cli/tests/mcp-apps.test.mjs` (in the CLI `test` script; the registry covers it through `test:cli`):
- spawned `aiden serve` end to end: off by default, connect, 401s, Read tools, a real chat through a fake provider, provenance, revoke, off/on, and the port across a restart
- in-process refusals and a phone id
- `--no-remote`
- the snippets never carrying the token

## Open

- W4b: the Settings UI and IPC over the five main exports, plus a "Started by" label from provenance (nothing reads it yet).
- W4c: `packages/cli` has no `@modelcontextprotocol/sdk` dependency and no MCP host wiring in `aiden serve`.
22 changes: 21 additions & 1 deletion docs/aiden-mcp-server.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@

Aiden can act as a [Model Context Protocol](https://modelcontextprotocol.io) server, so another app on the same computer (Claude Code, Codex, or any MCP client) can list Aiden's workspaces and chats, read them, and, with permission, start and follow Aiden turns.

Status (2026-11-11): the server core is in the desktop main process, behind the `mcpServer` host capability (macOS and Linux desktop; see `main/services/host-platform-capabilities.ts`). It is **off by default**. The Settings screen for turning it on and connecting apps is still to come (workstream W4b), and so is a headless `aiden serve` counterpart (W4c). Until those ship, the only way to turn the server on or issue an app is through the main-process functions listed under [Main-process API](#main-process-api).
Status (2026-11-11): the server core is in the desktop main process, behind the `mcpServer` host capability (macOS and Linux desktop; see `main/services/host-platform-capabilities.ts`). It is **off by default**. The Settings screen for turning it on and connecting apps is still to come (workstream W4b); until it ships, the desktop server is turned on and apps are issued only through the main-process functions listed under [Main-process API](#main-process-api). The headless server hosts the same endpoint, managed with `aiden apps` (see [Headless server](#headless-server-aiden-serve)).

## How an app connects

- **Transport:** stateless MCP Streamable HTTP. Each POST is a whole JSON-RPC exchange, answered as JSON. There are no sessions, no server-sent events and no `GET` stream.
- **Address:** `http://127.0.0.1:<port>/mcp`, loopback only. The server is a dedicated listener and is never served on the Remote Access LAN TLS listener, Tailscale or any other interface.
- **Port:**
- Release builds try 49400 first, then the next seven ports up. Development builds start at 50400.
- If every candidate is busy the first time the server starts, the system picks a free loopback port instead.
- The first port that binds is saved in Aiden's Remote state file, so the URL stays the same across restarts and an app's configuration keeps working.
- If another program later holds the saved port, the server reports `port_in_use` rather than moving, because moving would break every configured app silently.
- **Credential:** each app gets its own bearer token, a 43-character base64url secret shown once when it is issued. Aiden stores only a hash. A token is sent as `Authorization: Bearer <token>`.
Expand Down Expand Up @@ -110,6 +111,25 @@ Privacy:

The Remote Access threat model has the matching section: [`docs/security/aiden-remote-threat-model.md`](security/aiden-remote-threat-model.md#10-local-mcp-server-for-outside-apps).

## Headless server (`aiden serve`)

`aiden serve` in `packages/cli` hosts the same server, built from the same `AidenMcpHost` and tool runner, with the same tools, access levels, limits, token handling and request checks. The differences:

- **Port:** 49500 and the next seven ports, 100 above the desktop's range, so a desktop and a server on the same computer never take each other's port. Like the desktop, if all eight are busy on first start, the system picks a free loopback port, and the first port that binds is saved, in the server's `remote.json`, and a busy saved port is reported as `port_in_use`.
- **Administration:** `aiden apps`, sent to the running server over its private control socket:
- `aiden apps connect <name> [--access read|supervised]` turns the server on if it is off, issues the app (Read unless `--access supervised`) and shows its token once.
- On a terminal it also prints the `claude mcp add` and `codex mcp add` commands, which read the token from the app's own `AIDEN_MCP_TOKEN_<NAME>_<ID>` variable (the same name Settings prints) rather than storing it in the app's config.
- Piped, it prints JSON and warns on stderr that the output holds the token.
- `aiden apps list` shows the server's status and the connected apps, revoked ones with `revokedAt`.
- `aiden apps revoke <app-id>` disconnects one app through the same revocation path as `aiden remote revoke`. A phone's or Mac's id is refused.
- `aiden apps on|off` opens or closes the listener and saves the choice.
- **Requires Remote:** the server lives in the CLI's Remote runtime, which holds the device records and chat services. `aiden serve --no-remote` has no MCP server.
- **Containers:** loopback in a container is the container's own, so apps on the host can't reach it. Run `aiden serve` on the host for outside apps.
- **Files:** the provenance note is `<agentDir>/aiden-mcp-chat-provenance.json`.
- **Analytics:** `aiden apps` sends nothing, and app chats and turns send no usage events, as on the desktop.

Code: `packages/cli/src/apps.ts` (host wiring and the `apps` command), `packages/cli/src/apps-display.ts` (the connect output) and `packages/cli/src/remote.ts`. Tests: `packages/cli/tests/mcp-apps.test.mjs`.

## Main-process API

These are exported from `main/services/aiden-remote-service-main.ts` for the Settings IPC in W4b:
Expand Down
1 change: 1 addition & 0 deletions docs/security/aiden-remote-threat-model.md
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@ Outside app (Claude Code, Codex, any MCP client) on this computer
- The app that started a chat is recorded only locally (`aiden-mcp-chat-provenance.json`) and is never projected.
- Logs follow section 7 and carry only content-free events.
- No analytics events are sent.
- **Headless server.** `aiden serve` runs the same host and tools inside its Remote runtime, on loopback ports 49500–49507 so it never takes a desktop's port. It is administered only through `aiden apps` over the owner-private control socket, and it has no MCP server under `--no-remote`. `packages/cli/tests/mcp-apps.test.mjs` drives it end to end: off by default, 401 for a missing, wrong or revoked token, Read apps without write tools, a phone's id refused by `aiden apps revoke`, and the port kept across `off`/`on` and a restart.

Required evidence: `main/services/aiden-mcp-server.test.ts` covers:

Expand Down
22 changes: 21 additions & 1 deletion packages/cli/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,24 @@ Phones and Macs paired with the server see its workspaces, chats, Bots, schedule
- **Missing workspace folders.** If a chat's workspace folder (or its managed worktree checkout) was moved, renamed or deleted on the server, a turn from a paired device is refused before the message is kept, with the same `409 workspace_unavailable` refusal the Mac sends and no path in the message. The same send runs once the folder is back. A scheduled run in that workspace records a clear missing-folder error instead of a raw file-system error.
- **Scheduled-run notifications.** Run completions show up through `aiden schedule runs <id>`, `aiden schedule notifications` and, for tasks with `notify`, local notifications on paired phones via the Remote `scheduled-tasks/notifications` feed.

## Outside apps (MCP server)

`aiden serve` hosts the same loopback MCP server as the desktop, so Claude Code, Codex or any MCP client on the same computer can list the server's workspaces and chats, read them, and, with Supervised access, start and follow turns. Tools, access levels, limits and the threat model are in [`docs/aiden-mcp-server.md`](../../docs/aiden-mcp-server.md).

```bash
aiden apps connect "Claude Code" --access supervised # turns the server on, shows the token once
aiden apps list # server status and connected apps
aiden apps revoke <app-id> # disconnects one app at once
aiden apps off # closes the listener; `aiden apps on` reopens it
```

- **Off by default.** The listener opens only after the first `aiden apps connect` or an explicit `aiden apps on`, and the choice is saved in `remote.json`.
- **Address.** `http://127.0.0.1:<port>/mcp`, on loopback only. The server tries port 49500 and the next seven, 100 above the desktop's 49400, so a desktop and a server on one computer never collide. If all eight are busy the first time it starts, the system picks a free loopback port instead. The first port that binds is saved, so the URL stays the same across restarts; if another program later holds it, `aiden apps list` reports `port_in_use` instead of moving.
- **Connecting.** `connect <name>` defaults to Read access. On a terminal it prints the token once, with `claude mcp add` and `codex mcp add` commands that read it from the app's own variable, such as `AIDEN_MCP_TOKEN_CLAUDE_CODE_K3J9QX` (the same name the desktop's Settings sheet prints), instead of writing it into their config, so two apps in one shell profile keep separate tokens; piped, it prints JSON and warns on stderr that the output holds the token.
- **Requires Remote.** Apps share the Remote runtime's chats and device records, so `aiden serve --no-remote` has no MCP server and `aiden apps` says to restart without the flag. The listener never joins Remote's LAN or Tailscale listener.
- **Admin over the control socket.** `aiden apps` needs a running server and talks to it over the private control socket, like `aiden remote`. Admin commands send no analytics, and chats an app starts send no usage events.
- **Containers.** Loopback inside a container is the container's own, so an app on the host can't reach `/mcp` in the Docker image. Run `aiden serve` on the host for outside apps.

## Workspace tools and generation limits

Workspace chats hosted by `aiden serve` use the desktop's file and search tools: `read_file`, `list_dir`, `glob`, `grep`, `write_file` and `edit_file`, plus `run_command`. File-tool paths stay inside the workspace. CLI read and search tools apply the existing credential-path policy to supplied paths and canonical targets, refusing `.env` files and protected credential/private-key file paths. Public keys, credential-named source files and `.env.example` stay readable. Ask, Full and None workspace access still control tool admission, and file tools cannot change hook or agent configuration. Telegram and scheduled workspace chat turns still require Full access. Read-only scheduled inference receives only `read_file`, `list_dir`, `glob` and `grep`; Full scheduled inference also receives the file mutation and shell tools.
Expand Down Expand Up @@ -182,6 +200,7 @@ The desktop's per-workspace skill and connector switches (Workspace settings) ar
| `remote status\|devices\|pair lan\|tailscale\|pair-status\|pair-cancel <id>\|revoke <id>\|roots\|approve-root <path>` | Pairing and paired-device administration (server must be running) |
| `remote network local\|tailscale\|both` | Who can reach the server; Tailscale is set up for you (server must be running) |
| `remote check` | Check each step a phone needs to reach the server, with fixes |
| `apps list\|connect <name> [--access read\|supervised]\|revoke <id>\|on\|off` | Outside apps (Claude Code, Codex) on the local `/mcp` endpoint (server must be running) |
| `auth list\|login\|logout` | Provider credentials (OAuth or API key) |
| `workspace list\|add\|remove\|access\|scratch` | Workspace registry and tool access tiers |
| `mcp list\|presets\|add\|preset\|login\|logout\|remove` | MCP connectors and their OAuth sign-ins |
Expand Down Expand Up @@ -215,7 +234,7 @@ Notes:

| Path | Contents |
| --- | --- |
| `~/.aiden/agent/` | Server state: `settings.json`, `auth.json`, `aiden.json` (device-local feature settings), `aiden-mcp.json`, `web-search.json`, `remote.json` (Remote identity and paired devices), `chat-read-markers.json` and `chat-triage.json` (Inbox read state and Pin, Done and Snooze), `schedules.json`, `hooks/` (hooks, approvals and run log), `sessions/`, `bots/`, `bot-service/`, `artifacts/`, `credentials/`, `serve.log` and the private control socket |
| `~/.aiden/agent/` | Server state: `settings.json`, `auth.json`, `aiden.json` (device-local feature settings), `aiden-mcp.json`, `web-search.json`, `remote.json` (Remote identity, paired devices, connected apps and the MCP server setting), `aiden-mcp-chat-provenance.json` (which app started a chat, local only), `chat-read-markers.json` and `chat-triage.json` (Inbox read state and Pin, Done and Snooze), `schedules.json`, `hooks/` (hooks, approvals and run log), `sessions/`, `bots/`, `bot-service/`, `artifacts/`, `credentials/`, `serve.log` and the private control socket |
| `~/.aiden/` | Shared Aiden home (the desktop's portable `config.json`, `skills/`, `scripts/`; `memory/` is the shared desktop and server memory store, `ws-<folder-hash>` scopes) |
| `AIDEN_CODING_AGENT_DIR` | Environment override for the agent directory (mirrors Pi's `PI_CODING_AGENT_DIR`; use it for tests and for running more than one server) |

Expand All @@ -227,6 +246,7 @@ New Memory databases support bounded incremental space reclamation on open and c
- **Aiden usage data.** A server built from a clone or the Docker image has no project key and sends nothing. Only the `aiden serve` process of a distribution build (`npm run cli:dist`) can send the anonymous usage and crash data in [`docs/analytics.md`](../../docs/analytics.md); admin commands send nothing, apart from the one final event of `aiden telemetry off`. It sends only after its one-time notice, shown at `aiden service install` or the first `aiden serve` on a terminal; a server that never showed the notice stays silent. `aiden telemetry status|on|off` is the switch (`off` also stops a running server; a server picks up `on` at its next start). `DO_NOT_TRACK=1` and `AIDEN_ANALYTICS=0` turn it off for that process, and a service does not inherit them from your shell, so use `aiden telemetry off` there. With `CI` set nothing is ever sent. State lives in `<agentDir>/aiden-analytics.json`, not Pi's `settings.json`.
- **Manual-only catalogs.** models.dev, Artificial Analysis and OpenRouter benchmark data are fetched only by the explicit `aiden catalog models-dev fetch` and `aiden insights aa|openrouter fetch` commands, never on startup or in the background, and the fetched data is display-only. Speech models download only with `aiden speech download`.
- **Remote.** Paired devices authenticate to the server's own TLS identity. Tailscale is used only after you choose it for pairing.
- **MCP server.** Off until you connect an app. It listens on loopback only and makes no outbound requests of its own.

## Linux container

Expand Down
Loading
Loading