Repository navigation
Add a local MCP server core so other apps can use Aiden's chats #800
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
0300151
Add a local MCP server core so other apps can use Aiden's chats
sambitcreate 24c277f
MCP apps reach only the chats aiden_chat_list shows
sambitcreate fc71b60
MCP: wake waits on a missed finish, replay forgotten retries free, se…
sambitcreate 8d94068
Memory: MCP apps cannot reach assistant or feature chats; replay and …
sambitcreate be96c7b
Revoke an MCP app even when Bot storage waits for repair
sambitcreate 5038923
Docs: list the MCP revoke-bot-notices-unavailable log event
sambitcreate 27e6113
Share the app-revoke Bot notice policy as a tested helper
sambitcreate b8ae294
Name each MCP app's token variable from one shared helper
sambitcreate 5b9d0b6
Merge remote-tracking branch 'origin/main' into mcp-stack-800-local
sambitcreate 93b47c6
docs(mcp): describe app turns under approval modes, not Full access
sambitcreate File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| # 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. | ||
|
|
||
| ## Layout | ||
|
|
||
| - `main/services/aiden-mcp-server.ts` | ||
| - `AidenMcpServer`: | ||
| - a dedicated `http` listener on 127.0.0.1, `/mcp` only | ||
| - each POST builds a fresh SDK `Server` and a stateless `StreamableHTTPServerTransport` with `enableJsonResponse` | ||
| - a response close aborts the call's signal, which `aiden_chat_wait` uses | ||
| - `AidenMcpHost` owns the on/off reconcile, port selection and commit, and issue, list and revoke. | ||
| - `main/services/aiden-mcp-tools.ts` | ||
| - `AidenMcpToolRunner` holds the 9 `aiden_*` tools, TypeBox schemas, per-app limits, the `clientRequestId` cache and the run ownership map. | ||
| - It calls the shared `AidenRemoteChatService` and `AidenRemoteStreamService`, the same ones phones use. | ||
| - `main/services/aiden-mcp-provenance.ts` | ||
| - The local-only `startedBy {kind:"app", appId, name, startedAt}` log, in `aiden-mcp-chat-provenance.json` under userData, holding the newest 1,000 entries. | ||
| - A failed write is swallowed, so the turn still runs. | ||
| - `aiden-remote-state.ts` | ||
| - Device type `agent`, with `AGENT_CAPABILITY_CEILING` (read: `server:read` and `chat:read`; supervised adds `chat:write`), re-applied on every parse. | ||
| - `MAX_AIDEN_REMOTE_AGENT_APPS = 16`. | ||
| - `issueAgentApp`, `listAgentApps`, `mcpServerSettings`, `setMcpServerEnabled` and `commitMcpServerPort`. | ||
| - The `mcpServer {enabled, port?}` setting lives in the Remote state document. | ||
| - `aiden-remote-router.ts`: an `agent` token on `/api/aiden/v1` gets 401, like an unknown one. | ||
| - `aiden-remote-streams.ts`: added `watch` for the wait tool. | ||
| - `aiden-remote-service-main.ts` | ||
| - Builds the host inside the Remote runtime (`runtime.mcp`). | ||
| - `initializeAidenRemoteService` starts the host's reconcile; stop and settle also stop it. | ||
| - Exports `aidenMcpServerStatus`, `setAidenMcpServerEnabled`, `issueAidenMcpApp`, `listAidenMcpApps` and `revokeAidenMcpApp` for W4b's IPC. | ||
| - `host-platform-capabilities.ts`: `mcpServer` is darwin or linux. | ||
|
|
||
| ## Verified behaviour | ||
|
|
||
| - **Port:** | ||
| - Release builds use 49400 and the next 7 ports; development builds use 50400 and the next 7. | ||
| - The first port that binds is committed. After that only the saved port is tried, and if it is busy the status is `problem: "port_in_use"`. | ||
| - **Requests:** | ||
| - Host must be `127.0.0.1:<port>` or `localhost:<port>`, and any Origin other than the same loopback origin gets 403. No CORS headers are sent, OPTIONS included. | ||
| - A missing or bad token gets 401 with `WWW-Authenticate: Bearer realm="aiden"`. | ||
| - **Body limit:** | ||
| - Over 1 MiB, declared or streamed, gets 413. | ||
| - The server drains the rest for up to 5 s and then destroys the socket. Using `connection: close` instead raced the client's upload, and the client saw ECONNRESET in place of the 413. | ||
| - **Write tools:** | ||
| - They need `chat:write`, and Read apps do not see them listed. | ||
| - Turns are limited to 10 a minute and 2 concurrent runs per app; an idempotent retry does not count, even after the 128-entry request cache forgets it or a restart (`AidenRemoteChatService.hasRecordedRequest` checks the durable ledger before admission). | ||
| - MCP app chats and turns send no `chat_created` / `chat_message_sent` (`deviceReportsAnalytics` is false for `agent` devices). | ||
| - Waits are at most 55 s and default to 25 s. | ||
| - **Reach:** | ||
| - `aiden_workspace_list` and `aiden_chat_start` exclude `noWorkspace` folders and `ASSISTANT_WORKSPACE_ID`. | ||
| - Chat list is regular chats only. `requireOrdinaryChat` refuses by id every chat the list hides (Bot, feature, assistant), via `AidenRemoteChatService.isListedChat`, with the unknown-id answer so existence is not leaked. | ||
| - Phones can still read and send to assistant and feature chats by id; MCP apps cannot. | ||
| - **No approval tool.** `aiden_chat_wait` returns `waiting_for_approval` or `waiting_for_input` with `approveIn` / `answerIn` set to "Aiden on <computer name>". | ||
| - **Revoke:** | ||
| - It runs `revokeAidenRemoteRuntimeDevice`, which denies approvals, cancels runs and closes watchers. | ||
| - It then runs `tools.revokeApp`, which aborts that app's waits with "This app was disconnected from Aiden." | ||
| - A phone or Mac id returns false. | ||
| - **Tests:** `main/services/aiden-mcp-server.test.ts` (13 tests, in `test:aiden-remote` and `scripts/ci-test-registry.json`) runs a real registry, streams and chat service over fakes. | ||
| - 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 | ||
|
|
||
| - 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`. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| # Aiden MCP server | ||
|
|
||
| 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). | ||
|
|
||
| ## 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. | ||
| - 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>`. | ||
|
|
||
| Claude Code (the single quotes keep `${AIDEN_MCP_TOKEN_CLAUDE_CODE_K3J9QX}` literal in its saved configuration; Claude Code expands it from the environment when it connects): | ||
|
|
||
| ```sh | ||
| export AIDEN_MCP_TOKEN_CLAUDE_CODE_K3J9QX='<token>' | ||
| claude mcp add --transport http aiden http://127.0.0.1:49400/mcp \ | ||
| --header 'Authorization: Bearer ${AIDEN_MCP_TOKEN_CLAUDE_CODE_K3J9QX}' | ||
| ``` | ||
|
|
||
| Codex: | ||
|
|
||
| ```sh | ||
| export AIDEN_MCP_TOKEN_CODEX_P7QD2M='<token>' | ||
| codex mcp add aiden --url http://127.0.0.1:49400/mcp --bearer-token-env-var AIDEN_MCP_TOKEN_CODEX_P7QD2M | ||
| ``` | ||
|
|
||
| Use the port your Aiden reports if it is not 49400. Each app reads its token from its own variable, `AIDEN_MCP_TOKEN_<NAME>_<ID>` (the app's name and the start of its id, from `aidenMcpTokenEnvName` in `renderer/shared/aiden-mcp-token-env.ts`), so the desktop and `aiden apps connect` print the same name and two apps in one shell profile keep separate tokens. | ||
|
|
||
| ## Access levels | ||
|
|
||
| An app is a Remote device of type `agent`. Its capabilities are set to one of two levels when it is issued. When Aiden loads its Remote state, an app record is stripped of anything beyond the Supervised set, so an edit to the state file cannot widen an app's access: | ||
|
|
||
| | Level | Capabilities | Tools | | ||
| | --- | --- | --- | | ||
| | Read | `server:read`, `chat:read` | `aiden_server_info`, `aiden_workspace_list`, `aiden_chat_list`, `aiden_chat_read`, `aiden_chat_wait` | | ||
| | Supervised | Read, plus `chat:write` | Read tools, plus `aiden_chat_start`, `aiden_chat_send`, `aiden_chat_stop` | | ||
|
|
||
| An app is never granted `approval:respond`, files, Git, shell, Bots, schedules, settings, devices or pairing. A Read app does not see the write tools in `tools/list`, and calling one anyway is refused. | ||
|
|
||
| At most 16 apps can be connected at once, separately from the phone and Mac device limit. | ||
|
|
||
| ## Tools | ||
|
|
||
| | Tool | What it does | | ||
| | --- | --- | | ||
| | `aiden_server_info` | Aiden's version, the computer's name, and this app's access level. | | ||
| | `aiden_workspace_list` | The person's workspaces. It leaves out the folders Aiden makes for a single chat, and the assistant's own workspace. | | ||
| | `aiden_chat_list` | Recent ordinary chats, newest first, with a cursor. It leaves out Bot chats, feature chats and assistant chats. | | ||
| | `aiden_chat_read` | A chat's recent messages, paged with `before`. | | ||
| | `aiden_chat_wait` | Waits up to `timeoutSeconds` (default 25, maximum 55) for a run this app started. Returns `running`, `waiting_for_approval` or `waiting_for_input` (each with `approveIn`/`answerIn`, for example "Aiden on Studio Mac"), `done` with the final reply, or `failed`. It returns early if the app disconnects. | | ||
| | `aiden_chat_start` | Starts a new chat in an offered workspace, with optional `providerId`/`modelId`, and sends the first message. Needs a `clientRequestId`. Retrying with the same one returns the same chat and run, and never starts a second turn. | | ||
| | `aiden_chat_send` | Sends a follow-up to an existing ordinary chat (also idempotent by `clientRequestId`). | | ||
| | `aiden_chat_stop` | Stops a run **this app** started. Another app's runs, and the person's own, cannot be stopped or waited on. | | ||
|
|
||
| Arguments are validated against each tool's schema, and unknown properties are rejected. A message can be at most 200,000 characters, and messages read back are capped at 20,000 characters each. A chat `aiden_chat_list` leaves out (Bot, feature or assistant) cannot be read, waited on, sent to or stopped by id, even when the id is known. Every chat tool answers it exactly as it answers an unknown id (`This Aiden chat no longer exists.`), so an app cannot tell such a chat exists. MCP apps are trusted less than paired phones, which can open assistant chats. | ||
|
|
||
| There is deliberately no tool for approvals or questions. When a turn needs one, `aiden_chat_wait` says so and where, and the person answers it in Aiden on that computer. | ||
|
|
||
| A turn an app starts is approved exactly like a turn the person types in that workspace, and like one a paired phone starts. Aiden reads the workspace's approval policy before every tool call: the global mode in Settings → Approvals, or the workspace's own mode if the person chose Customize, plus the "Allowed in this workspace" grants: | ||
|
|
||
| - **Ask:** anything that sends, spends or changes something waits for the person. Only what the workspace's grants allow (running commands, changing files, Computer Use) runs without a card. | ||
| - **Auto:** a model approves routine actions and the rest wait for the person. A Supervised app's turn can therefore run routine tools with nobody watching. | ||
| - **Never ask:** only purchases, sharing the person's data and the first use of the computer wait for the person. Everything else runs unattended. | ||
| - **Chat only** workspaces cannot read or change their folder in any mode. | ||
|
|
||
| `aiden_workspace_list` reports each workspace's `toolPermission` as the same tier a phone sees (`legacyWorkspaceTier`): `none` for Chat only, `ask` for Ask with nothing allowed in the workspace, and `full` whenever something can run without a card (Auto, Never ask, or any grant). A well-behaved app that should not run tools unattended can start turns only where `toolPermission` is `ask`, but Aiden does not enforce that for it. | ||
|
|
||
| ## Limits | ||
|
|
||
| - **Turns:** each app can start or send 10 turns a minute and have 2 runs at once. A retry of an accepted `clientRequestId` does not count again, even after a restart or after many newer requests: Aiden's durable request record answers it. | ||
| - **Requests:** | ||
| - A request body over 1 MiB is answered 413 before any tool runs, whether its size is declared or streamed. | ||
| - The server drains the rest of an oversized upload for up to 5 seconds so the app sees the 413, then cuts the connection. | ||
| - A body that is not JSON gets JSON-RPC parse error `-32700`. | ||
| - **Connections:** at most 16 at once. | ||
|
|
||
| ## Threat model | ||
|
|
||
| Who could call the server: | ||
|
|
||
| - **Other software running as the same user.** It can reach loopback but has no token, so it gets 401. The token check is constant-time over hashes, and a missing, malformed, wrong or revoked token gets the same 401 with `WWW-Authenticate: Bearer realm="aiden"`. | ||
| - **A web page in the person's browser.** | ||
| - DNS rebinding is blocked by requiring the `Host` header to be exactly `127.0.0.1:<port>` or `localhost:<port>`, and refusing any `Origin` other than that same loopback origin, with 403. | ||
| - The server sends no CORS headers, `OPTIONS` included, so a page cannot read a response even on a same-machine origin. | ||
| - **A phone or paired Mac.** Their Remote credentials are refused on `/mcp`, and an app token is refused on `/api/aiden/v1`, both with 401. The audiences never cross. | ||
| - **A connected app that misbehaves.** | ||
| - It is limited to its access level, its own runs, ordinary chats and offered workspaces, and the rate and concurrency limits. | ||
| - It cannot settle an approval or answer a question. | ||
| - A Supervised app can still ask Aiden to do anything the chosen workspace's approval mode and grants allow without a card: routine actions in Auto, nearly everything in Never ask, and whatever is allowed in that workspace in Ask. That is why Supervised is a deliberate choice. Aiden does not narrow a workspace's policy for app turns, and a Supervised app may start turns in any offered workspace, so an app that must never act unattended should be given Read access instead. | ||
|
|
||
| Revoking an app: | ||
|
|
||
| - Rejects its token on the next request. | ||
| - Ends any `aiden_chat_wait` it has open ("This app was disconnected from Aiden."). | ||
| - Stops the runs it started, and denies their pending approvals, through the same revocation path as a phone. | ||
|
|
||
| Turning the server off closes the listener and every open connection. | ||
|
|
||
| Privacy: | ||
|
|
||
| - Aiden keeps a local note of which app started a chat (`startedBy {kind: "app", name}`, in `aiden-mcp-chat-provenance.json`, the newest 1,000 entries). It is never sent to phones, Macs or apps. | ||
| - App ids never appear in tool results. | ||
| - Server logs carry only `started`, `stopped`, `start-failed` (with a problem code), `request-failed` and `revoke-bot-notices-unavailable` (an app was disconnected while Bot storage waits for repair), never a token, an app name, a path or chat text. | ||
| - No analytics events are sent for the MCP server: a chat an app starts sends no `chat_created`, and its turns send no `chat_message_sent`. | ||
|
|
||
| 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). | ||
|
|
||
| ## Main-process API | ||
|
|
||
| These are exported from `main/services/aiden-remote-service-main.ts` for the Settings IPC in W4b: | ||
|
|
||
| - `aidenMcpServerStatus()` returns `{supported, enabled, running, port?, url?, problem?}`. | ||
| - `setAidenMcpServerEnabled(enabled)` turns the server on or off and saves the choice. | ||
| - `issueAidenMcpApp({name, access: "read" | "supervised"})` returns `{credential, app}`. The credential is returned only this once. | ||
| - `listAidenMcpApps()` lists the connected apps. | ||
| - `revokeAidenMcpApp(appId)` disconnects one app. A phone's or Mac's id returns `false`. | ||
|
|
||
| Code: `main/services/aiden-mcp-server.ts` (listener, `AidenMcpHost`), `main/services/aiden-mcp-tools.ts` (tools and limits), `main/services/aiden-mcp-provenance.ts`, and agent-app state in `main/services/aiden-remote-state.ts`. Tests: `main/services/aiden-mcp-server.test.ts` (in `npm run test:aiden-remote`). | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
toolPermission: "ask"does not guarantee that every consequential action will show a card: an Always allow rule can run a non-Mac tool in Ask, whilelegacyWorkspaceTierconsiders only the mode and Mac grants. Please remove this safety guarantee or expose/enforce a signal that accounts for every unattended allow path.Technical details