~ knotless Search/
↑↓ move↵ open⇧↵ all results
0
0

Assistants act as a member in one group, over MCP

Merged
Merged chadtmiller.com asked to merge into main from chadtmiller.com/group-host:host/assistants

What changes

Assistants act as a member in one group, over MCP (assistants.rs, crates/group-host-mcp, docs/design/assistants.md). An AI app that is an MCP client connects to a group to act there as the member who connected it, with what their roles allow and nothing more.

  • Signing in, as MCP's authorization spec has it.
    • /.well-known/oauth-protected-resource/mcp names the resource, <PUBLIC_URL>/mcp, and its authorization server, whose issuer is the same URL and whose metadata is at /.well-known/oauth-authorization-server/mcp.
    • A client names itself by a client ID metadata document (over https), or registers at /mcp/register (RFC 7591) as a public client, to be sent back over https, to a loopback address, or to an app's own scheme.
    • /mcp/authorize takes a code request with PKCE (S256) for that resource, and sends the browser to the console's /authorize.
    • /mcp/token exchanges the code once, for its client, redirect URI and verifier, for a Bearer access token (an hour) and a refresh token (thirty days, used once).
  • Consent is the console's. getAuthorization reads an assistant's request (new optional assistant: true), the member picks the group, and approveAuthorization and declineAuthorization answer it. The page says "wants to act as you in one of your groups" and "Connect it to <group>".
  • Acting. /mcp answers JSON-RPC: initialize, ping, tools/list and tools/call. The tools are 21 core methods: getGroup, updateProfile, rules, roles, members, join requests, invites, createSpace, listSpaceRecords, and moderation. Each tool's input schema is made from its method's lexicon, without the group, which is always the one chosen. A call is the host asking itself as the member, as the console does, so the host's own methods decide by the member's roles as they are now. A refusal is the tool's error, in the method's words.
  • Seeing and ending them. listConnectedApps (existing) and revokeConnectedApp (new lexicon) back a "Your assistants" section on the group's page, where each one can be disconnected. A member put out of the group has their assistants disconnected with them.

Why

This is step 9's last part. Two designs were weighed:

  • a separate MCP process, which would sign the member in at their own PDS and call the host through that PDS's proxy;
  • the host itself, which already signs people in to the console, already has an OAuth server and a consent page, and already serves listConnectedApps.

The second is much less code, and it decides what an assistant may do in the same place the console's calls are decided. Assistants' requests, grants and tokens are kept in tables of their own, so neither kind of token is ever taken for the other: a group's tokens act as the group, and an assistant's act as a member. The protocol and the tools are in crates/group-host-mcp, pure and with no host dependency, as AGENTS.md lays the crates out.

How it was checked

tests/assistants.rs has eight tests, covering:

  • the metadata and the 401 challenge;
  • connecting, with the approval page's view, and tools acting as her in her group;
  • a refused tool, and another group never reachable;
  • a member without a role, a member's roles limiting the tools, and a member put out;
  • refreshing, listing and disconnecting;
  • declining;
  • every malformed authorization, token and registration request;
  • a client by its metadata document;
  • the JSON-RPC errors through /mcp.

crates/group-host-mcp/tests/protocol.rs covers the tools' schemas and every message. A new e2e flow, "connecting an assistant, and disconnecting it", runs the whole flow in Chromium against the reference PDS: discovery, registration, consent on the console, the token exchange, a tool, and disconnecting from the group's page. just cov is at 100% locally.

Shortcomings

  • An assistant connects to one group. To act in another, the member connects it again.
  • Answers are JSON, one per POST. There is no server-sent stream, and no server-initiated messages.
  • MCP clients that require dynamic registration to carry a software statement aren't supported.

Review

The security boundary is worth a careful look:

  • assistants.rs's call_as mints an in-process console session for the member;
  • the tool layer forces the group;
  • the tables are separate from oauth_token.

🤖 Generated with Claude Code

Asked for changes

This adds an MCP server to the host. It covers OAuth discovery, registration and PKCE, a consent step on the console, 21 tools that run as the member in the group they chose, and a section for disconnecting assistants. The security design holds up. The tables are separate from oauth_token. The group is forced in call_as. Arguments must be an object. Authorization codes are single-use and stored hashed. Ejecting a member deletes their grants. I did not read the tests, e2e, docs, web or lexicon files in detail, and I did not check the CI results.

Must fix: the redirect URIs from a client ID metadata document are never checked. register filters its URIs with may_return_to. assistant_client takes redirect_uris from the fetched document as they are, and authorize only checks uris.contains(redirect_uri). Anyone who can host a document can list javascript:... or data: URIs. After the member approves, approve returns that URI as redirectUrl, and the console's BackToApp renders it as a link. That is script running on the console's origin after a click. A URI with no valid URL form also reaches with_query, whose expect panics. Apply may_return_to to the document's URIs, and drop the client if any fails or if none remain. Add a test for a document with a javascript: URI.

Minor: /mcp/register is unauthenticated and unbounded, so anyone can fill assistant_client with rows. A cap or a cleanup of unused clients would help. The client name shown on the consent page is whatever the client sent, so the page should make clear that it is unverified.

crates/group-host/src/assistants.rsline 326Outdated

These lines can no longer be read.

review.knotless.dev

The document's redirect URIs are not passed through may_return_to, unlike the ones from register. A javascript: or data: URI here ends up in redirectUrl on the approval page. An unparsable one makes the expect in with_query panic. Filter them here.

Fixed in c7781d4. A client metadata document's redirect URIs now go through the same check as a registered client's (redirects_ok: 1 to 10 URIs, each at most 2048 bytes, each one may_return_to allows). If any URI fails, it is no client, so no javascript: or data: URI and no unparsable URI reaches approve or with_query. The test lists a javascript: URI beside a good one and gets a 400. As a second guard, the console's BackToApp never follows a javascript:, data:, vbscript: or file: URL. Minor points: registration caps the URIs, and a client that registered but never connected is forgotten after a day. The approval page says the name is the assistant's own word, and shows the client ID it came from. just cov is at 100%, and e2e passes.

Approved

Round 2: what I asked for last time is done. I read assistants.rs only, and not the tests, e2e, docs, web or lexicon files. I did not check CI.

  • Must fix, done. assistant_client now passes a metadata document's redirect_uris through redirects_ok. That applies the same may_return_to filter and the same count and length limits that registration uses. One bad URI, such as javascript:, makes the whole client unknown. That closes both the script-link hole and the with_query panic. tests/assistants.rs:655 covers a document with a javascript: URI.
  • Minor, partly done. register_assistant now deletes registered clients that never connected after a day. Row growth within that day is still unbounded, but this is acceptable.
  • Still open, and not a blocker. The consent page shows the client's self-chosen name. The page could mark it as unverified.

The security boundary holds up as before. The group is forced in call_as, the tables are separate from oauth_token, and codes are single-use and stored hashed.

Merged as 5623455