Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# mcpx investigation — research corpus

The research corpus behind the mcpx programme investigation (#13264), gathered 2026-11-23: the state of mcpx, its designs and issue landscape — plus the mcpx door build notes (mcpx-door-20261123/) from the same day's door work (#13657).

## Provenance

Migrated 2026-11-23 from hatch-personal (`workspace/`) under the DOCS-MIGRATION programme (#5983): code-project research and design material lives in this repo's `doc/` area; the hatch repos keep only hatch-operational material. This is a dated research record — it states what was known when the research was done and is not rewritten later.

## Contents

- `mcpx-door-20261123/EXECUTOR-BRIEF.md`
- `mcpx-door-20261123/README.md`
- `mcpx-program-investigation-prompt.md`
- `research-mcpx-designs.md`
- `research-mcpx-issues.md`
- `research-mcpx-state.md`
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# mcpx Worker (W1, #13657) — continuation brief

## State already reached (verified from tool read-backs, 2026-11-23 ~13:50 CST)

- Laptop primary clone `~/git/code` was on `main`, CLEAN at fetch time
(the dirt named in the original brief — modified
`doc/fleet-schedule-registry.md`, untracked `pkgs/id/examples/` —
was NOT present; nothing was touched/stashed/committed by this lane).
- Worktree created: `~/git/code-mcpx-door-20261123`, branch
`lane-mcpx-door-20261123`, off `origin/main` @ `0a6ca03ccca`
(Merge PR #13538).
- Copied into the worktree (unadapted, byte copies):
`pkgs/desktop-commander/worker/.` → `pkgs/mcpx/worker/`
(node_modules excluded; 18 files incl. package-lock.json), and the
three workflows → `.github/workflows/mcpx-worker-{publish,promote,tests}.yml`.

## Why this lane stopped

The `git worktree add` exec result tripped a platform execution-risk
flag on the checkout content. Per the task rule, the operation was
retried via the Desktop Commander endpoint
(`https://commander.security.cab/mcp`, bearer by name
`desktop-commander.machine-bearer` via `fleet secrets get`, in-memory
only): attempt 1 got Cloudflare error 1010 (browser signature banned,
Python UA); attempt 2 (browser UA) got a connection closed without
response. DC route from the sandbox is therefore not working this
session. Remaining build steps must run in a venue that does not trip
the flag — Drew's standing route: a laptop-local OpenCode session
working in the worktree in-session, evidence recorded on #13657,
Archer/parent finishes (merge) via `gh` from the record.

## Remaining steps for the executor (in the laptop worktree)

1. Get `adapt.py`, `filter.ts`, `README.md` from the sandbox workspace
`~/workspace/mcpx-door-20261123/` to the laptop (they are
hand-authored lane assets, not repo content).
2. Run `python3 adapt.py` from `~/git/code-mcpx-door-20261123`
(it performs all Commander→mcpx swaps, the index.ts bare-path +
selector restructure, writes `src/filter.ts`, appends the
bare-path/selector tests to `test/proxy.test.ts`, fixes the
package-lock name, and asserts the final config/AUD/KV/scope
values). Then copy the companion `README.md` over
`pkgs/mcpx/worker/README.md` (adapt.py deliberately excludes it).
3. Sanity greps: no `desktop-commander` left outside README's
historical mention; workflows reference `MCPX_WORKER_*`,
environment `mcpx-production`, concurrency `mcpx-worker-lifecycle`,
artifact `mcpx-worker-upload-<run_id>-<run_attempt>`, tag prefix
`mcpx-`.
4. In `pkgs/mcpx/worker`: `npm ci --no-audit --no-fund`, `npm test`,
`npm run typecheck` — all green before PR. (Node v24.21.0 / npm
11.19.0 verified present on the laptop.)
5. Commit (only `pkgs/mcpx/worker/**` + the three workflow files),
push `lane-mcpx-door-20261123`, open PR: description covers the
door, the adaptations, bare-path equivalence, the filtering seam;
"Part of #13657" — NO closing keywords (#13657 stays open until
live verification). Re-read PR comments immediately before merging;
merge once green.
6. Filtering enforcement: DO NOT invent semantics. `src/filter.ts`
ships architecture-only (selector `ns` parsed once in the router,
`DEFAULT_FILTER_PROFILE = "conservative"`, pass-through
`filterMcpResponse`). The enforcement spec arrives as a follow-up
from the parent; if it lands before the PR merges, implement it in
`filter.ts` + tests in the same PR.

## Key adaptation values (already encoded in adapt.py)

- Worker `mcpx`, package `mcpx-worker`, routes `["mcpx.security.cab"]`,
workersDev false, compatibilityDate `2025-09-15` (unchanged).
- ISSUER `https://mcpx.security.cab`, RESOURCE
`https://mcpx.security.cab/mcp`, SCOPE `mcpx`, OWNER_EMAIL unchanged.
- BRIDGE_BASE `https://mcpx-link.security.cab`, ACCESS_TEAM_DOMAIN
`snowy-sun-58a9.cloudflareaccess.com` (unchanged), ACCESS_AUD
`b34b9764fb317774bf5c0ff0ac9cbd8a2ab80ed346d06f08d74967011bac640e`,
KV OAUTH_KV id `11eb93dc9fa24087ae57b12483dc6172`.
- devDeps unchanged: cf 1.0.0-beta.20, wrangler 4.152.0,
@cloudflare/workers-types ^5.20261019.1.
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
# mcpx Worker — public MCP endpoint (#13657)

The public front door for mcpx at `mcpx.security.cab`, mirroring the
proven desktop-commander Worker build (#13404). Hosted MCP clients
(Claude, ChatGPT) and the owner's own tooling reach the laptop's mcpx
daemon through this Worker; nothing else on the laptop is exposed.

## Path of a request

```
AI client
-> POST https://mcpx.security.cab/mcp (bare https://mcpx.security.cab/ is identical)
Guarded by this Worker's OAuth 2.1 authorization server
(src/oauth.ts). Hosted clients connect from their own servers
and cannot pass a Cloudflare Access login, so /mcp takes a
Bearer token instead — or the machine bearer for the owner's
own tooling.
-> this Worker (src/index.ts): checks the Bearer, computes the
filter selector (src/filter.ts), then proxies the streamable-HTTP
MCP request, swapping the caller's credentials for its own
bridge egress token.
-> https://mcpx-link.security.cab/mcp
Access app "mcpx link (bridge)": service-token-only policy.
-> sandbox-link Cloudflare Tunnel -> http://localhost:8932 on amd
-> the mcpx bridge proxy on 127.0.0.1:8932
-> the mcpx daemon's /mcp endpoint, discovered via the daemon's
state descriptor
```

`workers_dev` is off; `mcpx.security.cab` (a Worker route) is the
only public door.

## Origin lockdown

The mcpx daemon listens on loopback only and is unauthenticated —
it trusts its only caller, the local bridge proxy. This door is the
security boundary: it exposes `/mcp` (and its bare-path twin `/`)
only, behind OAuth/machine-bearer auth. The daemon's `/v1/*` API is
never proxied and has no public path.

## OAuth front door (src/oauth.ts)

Standard MCP authorization shape, so Claude and ChatGPT can connect:

- `GET /.well-known/oauth-protected-resource` (and `.../mcp`) and
`GET /.well-known/oauth-authorization-server` — public discovery.
- `POST /register` — dynamic client registration (RFC 7591); public
clients only (`token_endpoint_auth_method: "none"`), redirect URIs
must be https or loopback http. Clients live in the `OAUTH_KV`
namespace under `client:<id>`.
- `GET /authorize` — the approval page, and the ONE path still behind
Cloudflare Access: the "mcpx" Access app is scoped to
`mcpx.security.cab/authorize` with the owner-email policy only
(Google SSO identity). The Worker also verifies the Access JWT
itself (RS256 against the team JWKS, audience, owner email) before
rendering. Approving issues a single-use code (10 min, PKCE S256
bound) via the form's POST back to `/authorize`.
- `POST /token` — authorization-code exchange (PKCE verified, code
consumed on any attempt) issuing an opaque access token (1 h) and
a rotating refresh token (30 d). Codes and tokens are stored in KV
under their SHA-256 (`code:<hash>`, `at:<hash>`, `rt:<hash>`),
never in the clear. Revoke a client by deleting its `at:`/`rt:`
entries (and its `client:` record) from the namespace.
- `/mcp` (and `/`) without a valid Bearer returns 401 with
`WWW-Authenticate: Bearer resource_metadata="https://mcpx.security.cab/.well-known/oauth-protected-resource"`,
which is what sends hosted clients into the OAuth flow.

## Filtering (src/filter.ts)

Architecture in place; enforcement spec pending on #13657.

- A per-request selector is parsed from the `ns` query parameter in
exactly one place (`resolveFilterSelector` in src/filter.ts),
computed by the router and passed to the proxy/filter layer.
- No selector means the named conservative default profile
(`DEFAULT_FILTER_PROFILE = "conservative"`).
- `ns` is consumed by this door and stripped before proxying; all
other query parameters pass through untouched.
- Until the enforcement spec lands, `filterMcpResponse` is a
pass-through: the selector is threaded end to end so enforcement
can be added in src/filter.ts without touching the router.

## Secrets — by name only, never values

| Where | Name |
| --- | --- |
| fleet secrets (Bitwarden) | `cloudflare.access.mcpx-link-client-id` / `-client-secret` — bridge-door token the Worker presents |
| fleet secrets (Bitwarden) | `cloudflare.api-token-mcpx-worker` — scoped deploy token |
| fleet secrets (Bitwarden) | `mcpx.machine-bearer` — the /mcp machine bearer |
| fleet secrets (Bitwarden) | `cloudflare.tunnel.sandbox-link-token` — the sandbox-link tunnel the bridge door rides |
| GitHub environment `mcpx-production` | `MCPX_WORKER_CF_TOKEN` (same deploy token), `BRIDGE_ACCESS_CLIENT_ID`, `BRIDGE_ACCESS_CLIENT_SECRET`, `MACHINE_BEARER` |
| Worker version secrets | `ACCESS_CLIENT_ID`, `ACCESS_CLIENT_SECRET`, `MACHINE_BEARER` — uploaded per version by the publish workflow from the environment secrets |

## Deploys — cf version deployments via GitHub Actions

Modeled on the desktop-commander / id-mail publisher-promoter pair:

1. **Publish** (`mcpx-worker-publish.yml`, manual dispatch on main,
`confirm_upload`): tests, a credential-free dry run, then
`upload-version.mjs` runs `cf workers versions create` with the
Worker secrets file. Uploading changes no traffic. The run emits
a provenance artifact (`mcpx-worker-upload-<run_id>-<run_attempt>`)
naming the exact version, tag (`mcpx-<sha12>-run-<id>-attempt-<n>`),
and baseline.
2. **Promote** (`mcpx-worker-promote.yml`, manual dispatch with the
publish run id + attempt, `confirm_promotion`):
`verify-upload-run.mjs` vouches the run was a successful manual
publish on main, then `promote.mjs` checks the live deployment
still matches the manifest baseline (or already serves exactly
this version — an idempotent no-op) and creates a deployment with
exactly that version at 100%.

Tests (`mcpx-worker-tests.yml`) run on pushes and PRs touching this
directory.

## Client setup

- Hosted clients (Claude, ChatGPT): add the custom connector
`https://mcpx.security.cab/mcp`; the client registers itself and
sends the owner through the Access sign-in + approval page on
first connection.
- Header-capable clients (Claude Code, Cursor, other mcpx clients):
send `Authorization: Bearer <machine bearer>` (fleet secrets:
`mcpx.machine-bearer`).
Loading