Skip to content

Add a local MCP server core so other apps can use Aiden's chats - #800

Merged
sambitcreate merged 10 commits into
mainfrom
claude/aiden-mcp-server-core
Nov 17, 2026
Merged

sambitcreate merged 10 commits into
mainfrom
claude/aiden-mcp-server-core

Conversation

@sambitcreate

@sambitcreate sambitcreate commented Nov 11, 2026 •

Copy link
Copy Markdown
Owner

Summary

Workstream W4a of the upstream week: the core of a local MCP server that lets other apps on the same computer (Claude Code, Codex, any MCP client) use Aiden's chats. Ported in spirit from T3 Code PR #33196. No code was copied.

  • Transport and listener. Stateless MCP Streamable HTTP (@modelcontextprotocol/sdk 1.32.1) on a dedicated 127.0.0.1 listener at /mcp.
    • It is never served on the Remote Access LAN TLS listener.
    • It uses a stable port, saved in the Remote state file: 49400 in release builds and 50400 in development, each with up to 7 neighbours tried at first bind. If the saved port is busy, the status reports port_in_use.
  • Off by default, gated by a new mcpServer host capability (macOS and Linux desktop), and switched separately from Remote Access.
  • Request hardening:
    • exact Host and same-origin Origin checks, refused with 403
    • no CORS headers ever sent, OPTIONS included
    • bodies over 1 MiB (declared or streamed) get 413, and the rest is drained for up to 5 s so the app sees it
    • a cap of 16 connections
    • timing-safe bearer checks, with the same 401 for a missing, wrong or revoked token
  • Outside apps are Remote devices of type agent.
    • Each gets its own token and a quota of 16.
    • Access is Read (server:read and chat:read) or Supervised (adds chat:write). That ceiling is re-applied on every state parse, so approval:respond, files, Git, Bots, schedules and settings can never be granted.
    • /api/aiden/v1 refuses agent tokens, and /mcp refuses phone and Mac tokens.
  • Tools (all aiden_ prefixed):
    • read: server_info, workspace_list, chat_list, chat_read, chat_wait
    • write: chat_start, chat_send, chat_stop
    • chat_wait is a bounded long-poll (55 s at most) that returns running, waiting_for_approval, waiting_for_input, done or failed, says where to approve ("Aiden on "), and returns early when the app disconnects.
    • There is no approval or question tool.
  • Limits and reach:
    • Each app can start or send 10 turns a minute and have 2 runs at once.
    • clientRequestId is required, and a retry returns the original chat and run.
    • An app can wait on and stop only runs it started.
    • Bot chats, the one-chat folders and the assistant workspace are out of reach.
  • Revocation goes through the shared revokeAidenRemoteRuntimeDevice: it ends the app's waits, stops its runs and denies their approvals.
  • Provenance. A local-only startedBy {kind: "app", name} record is kept in aiden-mcp-chat-provenance.json and is never sent anywhere.
  • Main-process API for the Settings UI that follows: aidenMcpServerStatus, setAidenMcpServerEnabled, issueAidenMcpApp, listAidenMcpApps and revokeAidenMcpApp. This PR has no Settings UI (W4b) and no aiden serve wiring (W4c).
  • No analytics events added. README and PRODUCT.md are unchanged until W4b makes the feature visible.

Docs:

  • new docs/aiden-mcp-server.md: threat model, tools, limits, and the claude mcp add and codex mcp add snippets
  • new section 10 in docs/security/aiden-remote-threat-model.md
  • .memory/aiden-mcp-server.md

Tests

New main/services/aiden-mcp-server.test.ts has 13 behavioral tests. It uses a real registry, stream service and chat service over a real MCP client, with fakes only for storage and generation. It covers:

  • off by default, the stable port, and a busy saved port
  • unsupported hosts
  • 401 for a missing, wrong or revoked token
  • phone and Mac credentials refused on /mcp
  • Host and Origin rebinding refused, and no CORS headers
  • declared and streamed bodies over 1 MiB, and a parse error
  • a Read app refused the write tools
  • idempotent chat_start
  • approvals the app can see but not settle
  • stop only your own runs
  • revoke ending a wait and a run
  • the rate limit and the run cap
  • Bot chats and hidden workspaces out of reach

The state and router suites gain tests for the agent capability ceiling, a tampered state file, the quota, the saved switch and port, and agent tokens refused on /api/aiden/v1. The new file is registered in test:aiden-remote and scripts/ci-test-registry.json.

Validation

  • npx tsx --test main/services/aiden-mcp-server.test.ts: 13/13 passed in 10 consecutive runs, after fixing a 413 race that showed up as an intermittent ECONNRESET
  • npm run test:aiden-remote: everything passes except 4 tests in scripts/aiden-remote-lan-transport-spike.test.mjs. This branch does not touch that file. Its certificate setup runs openssl x509 -days 0 -copy_extensions, and neither openssl on this Mac accepts that: Homebrew OpenSSL 4.1 refuses -days 0, and macOS LibreSSL lacks -copy_extensions. CI's OpenSSL 3 should run it.
  • Each Remote suite passes on its own: router 114, state 42, streams 83, service 77, chats 96, revocation, handlers, host capabilities, popover, and Remote Access settings
  • npm run test:ci-policy
  • npm run type-check
  • npx eslint on every touched file
  • npm run cli:build

Follow-ups

  • W4b:
    • a Settings screen and IPC over the five main-process functions
    • a "Started by" label from the provenance record
    • README and PRODUCT.md claims once that ships
  • W4c:
    • packages/cli has no @modelcontextprotocol/sdk dependency and no MCP host in aiden serve yet

CI flakes

🤖 Generated with Claude Code

Flaky CI seen after merging main (2026-11-17)

On the run for 93b47c6 (Actions run 44030902768, attempt 1), two required jobs failed in code this PR does not touch. It changes no ios/ or design-canvas file.

The failed jobs were rerun once, per AGENTS.md.

sambitcreate and others added 2 commits November 11, 2026 15:16
Aiden can now serve MCP on a dedicated loopback listener, off by default,
so Claude Code, Codex or any MCP client on the same computer can list
workspaces and chats, read them, and (with Supervised access) start, send
to, wait on and stop Aiden turns. Approvals and questions stay with the
person in Aiden; no tool can answer them.

- Stateless Streamable HTTP on 127.0.0.1 with a stable saved port, exact
  Host and same-origin checks, no CORS, a 1 MiB body limit and a
  connection cap.
- Outside apps are Remote devices of type "agent" with their own tokens,
  quota and a Read/Supervised capability ceiling re-applied on every state
  parse; /api/aiden/v1 refuses them and /mcp refuses phones and Macs.
- Per-app turn rate limit and run cap, idempotent clientRequestId, own-run
  wait and stop, Bot chats and hidden workspaces out of reach.
- Revoking an app ends its waits, stops its runs and denies their
  approvals through the shared revocation path.
- Local-only "started by" provenance, never projected.
- Main-process status/enable/issue/list/revoke functions for the Settings
  UI that follows; no UI or CLI wiring yet.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
An agent credential could read, wait on, send to or stop assistant and
design-project chats by id although aiden_chat_list hides them. Every chat
tool now refuses any chat the list leaves out with the unknown-id answer,
so an app cannot learn such a chat exists.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

MCP turns currently violate the documented analytics contract, and two lifecycle guarantees can fail after cache pressure or stream races.

Reviewed changes in 0300151, covering the complete 18-file diff and the surrounding Remote state, chat, stream, analytics, and lifecycle paths.

  • Loopback transport. Adds the off-by-default Streamable HTTP listener, stable-port selection, Host/Origin checks, bearer authentication, request limits, and connection handling.
  • Outside-app identity. Adds agent records, capability ceilings, audience separation, quotas, persisted server settings, and revocation integration.
  • Chat tools. Adds read/write tool schemas, ordinary-chat/workspace filtering, run ownership, long polling, rate/concurrency limits, and request replay.
  • Runtime integration. Reuses the Remote chat and stream services, adds observer-only stream watches and local provenance, exposes main-process controls, and documents the threat model and follow-up UI/CLI work.

⚠️ MCP activity is sent as phone analytics

aiden_chat_start reaches both the existing chat_created and chat_message_sent reporters, while aiden_chat_send reaches chat_message_sent. Since an agent is not a peer, the latter is recorded with origin: "phone", contradicting the new no-analytics guarantee and contaminating phone usage metrics.

Technical details
# Keep MCP activity out of product analytics

## Affected sites
- `main/services/aiden-remote-service-main.ts:1285-1290` — the MCP runner receives the shared Remote chat service without an MCP-specific analytics policy.
- `main/services/chat-application-service.ts:274-275` — every newly created chat reports `chat_created`.
- `main/services/aiden-remote-chats.ts:2942-2950` — every started Remote turn reports `chat_message_sent`, and a non-peer device becomes `origin: "phone"`.
- `docs/aiden-mcp-server.md:99` and `docs/security/aiden-remote-threat-model.md:196` — both state that the MCP server sends no analytics events.

## Required outcome
- Starting or sending an MCP turn must not emit `chat_created`, `chat_message_sent`, or another analytics event if the documented no-analytics policy remains the intended contract.
- Add behavioral coverage with a registered analytics reporter so this is proved at the MCP entry point rather than inferred from source shape.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

Comment thread main/services/aiden-mcp-tools.ts Resolved
Comment thread main/services/aiden-mcp-tools.ts Resolved

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ The new chat-visibility restriction is sound; one stale project-memory claim remains inline.

Reviewed changes since the prior Pullfrog review, covering commit 24c277f and its six-file incremental diff.

  • Chat visibility. Adds isListedChat and applies the same summary-list inclusion policy to read, wait, send, and stop operations by id.
  • Non-enumeration coverage. Verifies assistant, design-project, and unknown chat ids all receive the same not-found result, and updates the user and threat-model docs.
  • Prior findings. This commit does not touch the three findings raised against 0300151; they remain open.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

Comment thread .memory/aiden-mcp-server.md Resolved
sambitcreate and others added 2 commits November 11, 2026 15:46
…nd no usage data

- aiden_chat_wait re-reads the run once its watch is attached, so a run that
  finishes in between wakes it at once, and it answers with the finished state
  it saw even if that run is later evicted.
- A clientRequestId Aiden already recorded replays without counting against
  the rate limit or run cap, after the in-memory cache forgets it or a restart.
- Chats and turns from an MCP app (an agent device) send no chat_created or
  chat_message_sent.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…analytics notes

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The app's token is tombstoned first; a BotCapabilityUnavailableError from
removing its Bot notice audience (no Secret Service on Linux, say) is now
logged instead of failing the revoke and leaving the app listed in
Settings. Phone revokes still require it. Ported from W4b (#803).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ℹ️ No critical issues — one documentation mismatch is noted inline.

Reviewed changes since the prior incremental head, covering the MCP revocation adjustment in be96c7b.

  • Completed degraded revocation. Allowed an MCP app's already-tombstoned revocation to finish when Bot capability storage is unavailable.
  • Preserved paired-device strictness. Kept Bot notice cleanup failures blocking for phone and desktop-device revocation while logging the MCP-only degraded case.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

sambitcreate and others added 2 commits November 11, 2026 16:18
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
`revokeBotNoticeAudience` in bot-capability-store-core.ts decides when a
revoke may skip clearing Bot notices: only for an outside app, and only on
BotCapabilityUnavailableError. It has its own behavioral test. Remote main
now calls it, and the bots contract matches that call, which fixes the
runtime-subagents failure from be96c7b.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes since the prior Pullfrog review at be96c7b, covering the two new commits and their integration with the complete PR.

  • Documented degraded revocation. Added the content-free revoke-bot-notices-unavailable event to the MCP log inventory.
  • Shared Bot notice policy. Extracted MCP best-effort versus paired-device strict cleanup into revokeBotNoticeAudience, added focused behavioral coverage, and updated the production wiring contract.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using GPT Sol | 𝕏

aidenMcpTokenEnvName gives every app its own AIDEN_MCP_TOKEN_<NAME>_<ID>
variable, so the desktop Settings sheet and aiden apps connect can print the
same setup commands and two apps in one shell profile keep separate tokens.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ No new issues found.

Reviewed changes since the prior Pullfrog review at 27e6113, covering the per-app token-variable update in b8ae294.

  • Added shared token naming. Introduced aidenMcpTokenEnvName to derive shell-safe, app-specific environment variable names from each app's name and random device id.

  • Updated client setup commands. Switched the Claude Code and Codex examples to environment-backed bearer tokens using syntax supported by each client's saved MCP configuration.

  • Registered behavioral coverage. Added a real-shell test for valid, independent exports and included it in the Remote test suite and CI registry.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | View workflow run | Using GPT Sol | 𝕏

A turn an app starts follows the workspace's approval policy (Ask, Auto,
Never ask and Allowed in this workspace grants) exactly like the person's
own and a phone's. The guide, the threat model and aiden_chat_start's
description now say what runs without a card in each mode, and that
toolPermission is the phone tier (full whenever anything can run
without a card).

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Important

The new approval-mode guidance overstates what toolPermission: "ask" guarantees, so a Supervised app can still run a tool unattended while following the documented recommendation.

Reviewed changes since the prior Pullfrog review at b8ae294, including the current-main merge and the approval-mode documentation update.

  • Clarified approval inheritance. Documented that MCP-started turns use the workspace's global or customized Ask, Auto, or Never ask policy and its Mac grants.

  • Updated tool disclosure. Expanded aiden_chat_start to tell clients that the workspace policy governs which calls still require the person.

  • Reconciled current main. Preserved MCP test registration while merging the latest base changes.

Pullfrog  | ⚠️ this action is pinned to a commit SHA, which freezes the cleanup step — switch to @v0 or keep the SHA fresh with Dependabot | Fix all ➔ | Fix 👍s ➔ | View workflow run | Using GPT Sol | 𝕏

Comment thread docs/aiden-mcp-server.md
- **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.

Copy link
Copy Markdown
Contributor

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, while legacyWorkspaceTier considers 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
# Do not present the legacy tier as an unattended-execution boundary

## Affected sites
- `docs/aiden-mcp-server.md:71` — recommends `toolPermission: "ask"` to apps that must not run tools unattended.
- `renderer/shared/approval-mode.ts:272-278` — computes that tier from mode and Mac grants only.
- `main/services/approval-gate/workspace-tool-approval.test.ts:141-145` — proves an Always allow connector rule runs a send in Ask.

## Required outcome
- The MCP guidance must not imply that `toolPermission: "ask"` excludes every unattended tool path unless the implementation actually enforces that invariant.

@sambitcreate
sambitcreate merged commit 98e4aaa into main Nov 17, 2026
55 of 60 checks passed
@sambitcreate
sambitcreate deleted the claude/aiden-mcp-server-core branch November 17, 2026 17:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant