The hub as an MCP server (OAuth 2.1, the consent page, /mcp, Settings → AI
apps) is the `hub-mcp` live plugin now (ai-agent-plugins). Core keeps nothing
about MCP: four generic plugin contracts replace backend/mcpserver/.
Gabriel's picks: form move-the-hub-mcp-server-into-a-plugin_2od10i.
New contracts (docs/plugins.md → "HTTP endpoints, the hub's API and asks"):
- `endpoints[]` (plugins/endpoints.py): HTTP a plugin answers on the hub's own
address — under /x/<pluginId>/… or a protocol path (/mcp, /oauth/…,
/.well-known/…). The request goes to the endpoint's action with what the
host vouches for (client address, surface, and `caller`: who the browser is
signed in as, by the gate's own rules — core/auth.identify); the answer
comes back through header and type allowlists, and HTML never runs a script
(forced CSP). Body cap, per-address rate, 16 runs at once on their own
threads. An endpoint's action answers HTTP only: the action routes refuse it
and the manifest can't wire it to anything else — its payload is the host's
word on who is asking.
- `hub.api` (plugins/hubapi.py, plugins/actas.py): the hub's API for the
plugin's handlers, as the owner or — `X-AIA-As-User`, the `cli` scope — as a
guest the plugin is granted to. The CLI is its library (AIA_CLI_DIR; the
names a plugin leans on are pinned by cli/test_library_surface.py).
`hub/via` stamps meta.via = {kind: "plugin", …}: the "via Claude.ai" pill.
- `notify.ask` and `security.record` (plugins/hubsignals.py): a tappable
question to the owner and its answer; a `plugin_event` Security log line.
Removed: backend/mcpserver/, schemas/mcp.py, cli/mcp_tools.py + mcp_server.py,
the frontend's business/aiApps (Settings → AI apps, /connect/<id> — both old
addresses redirect), /api/mcp*, /api/me/ai-apps, the `mcp` SSE event, the
mcp.connect / mcp.manage permissions and the per-guest AI apps switch (the
plugin's managed grant). A retired permission still in a record reads without
it and is never refused (authz/catalog.RETIRED).
Carry-over (carryover.hub_mcp, at start and after the plugin's install):
/data/mcp.json → the plugin's store, same shape, so connected apps keep
working — minus the connections bound to a worker, which are dropped with
their tokens rather than left as plain owner connections; every guest who
held mcp.connect gets the grant; whoever was pushed about mcp_connected is
pushed about plugin events.
Workers: the `ai-agent` CLI switch gains Full — the lab's CLI as the owner
(every command but worktrees, any machine, the plugins' commands), what the
EVOX2's unbound MCP connection gave. The worker-side CLI no longer filters
commands: the hub's switch decides. "Acts as" is gone; workers/bound.py stays
as the CLI's narrowing.
Until the plugin is installed after a deploy, /mcp and /oauth/* answer 404.
Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
59 lines
2.7 KiB
Python
59 lines
2.7 KiB
Python
"""Who a plugin's ``hub.api`` call is, inside the hub.
|
|
|
|
The ``hub.api`` bridge (plugins/hubapi.py) reaches this backend's own API
|
|
over loopback — the owner, to the gate. A call **for a guest** adds
|
|
:data:`AS_USER_HEADER` (their id) and :data:`VIA_PLUGIN_HEADER` (the plugin
|
|
acting for them), and the gate (``core/auth.py``) answers it as that guest: a
|
|
downgrade of a caller already trusted, never an upgrade, exactly like the
|
|
guest CLI's ``X-AIA-As-Session`` (``users/cli.py``). The routes are the CLI's
|
|
(the ``cli`` credential scope, authz/scopes.py), and the handlers filter by
|
|
ownership as for their browser.
|
|
|
|
Until 2026-11-28 this was ``mcpserver/caller.py`` (``X-AIA-MCP-User``, the
|
|
``mcp.connect`` permission): the MCP server is the ``hub-mcp`` plugin now, and
|
|
"may this guest connect AI apps" is "is that plugin theirs" — its managed
|
|
grant.
|
|
"""
|
|
|
|
from __future__ import annotations
|
|
|
|
import re
|
|
|
|
from core.i18n import tr
|
|
from users.caller import OWNER, OWNER_ID, Caller, guest_from_record
|
|
from users.cli import Refused
|
|
|
|
AS_USER_HEADER = "x-aia-as-user"
|
|
VIA_PLUGIN_HEADER = "x-aia-via-plugin"
|
|
_PID_RE = re.compile(r"^[a-z][a-z0-9-]{0,63}$")
|
|
|
|
|
|
def plugin_user_caller(deps, uid: str, pid: str) -> Caller:
|
|
"""The caller plugin ``pid`` acts for when it names ``uid``.
|
|
:class:`Refused` (``kind``: ``guest_gone`` — deleted for good —,
|
|
``guest_disabled``, ``guests_locked``, ``not_granted``) when that guest is
|
|
gone, disabled or locked out, or the plugin isn't theirs (any more)."""
|
|
uid, pid = (uid or "").strip(), (pid or "").strip()
|
|
if uid == OWNER_ID:
|
|
return OWNER
|
|
if not uid: # a call for nobody is nobody's — never the owner's
|
|
raise Refused(403, {"message": "this call names no user", "kind": "guest_gone"})
|
|
if not _PID_RE.match(pid):
|
|
raise Refused(400, {"message": "which plugin is acting?", "kind": "bad_request"})
|
|
u = deps.users.active(uid)
|
|
if not u:
|
|
# disabled may come back; gone never does (the id is retired)
|
|
if deps.users.get(uid):
|
|
raise Refused(403, {"message": "this guest is disabled", "kind": "guest_disabled"})
|
|
raise Refused(403, {"message": "this guest is gone", "kind": "guest_gone"})
|
|
guest = guest_from_record(u)
|
|
if deps.security_state.guests_locked():
|
|
raise Refused(403, {"message": tr(guest.lang, "guest access is paused for now"),
|
|
"kind": "guests_locked"})
|
|
rec, _grant, _managed = deps.plugin_store.resolve_active_for_caller(uid, pid)
|
|
if not rec:
|
|
raise Refused(403, {"message": tr(guest.lang, "this isn't open to you — "
|
|
"the owner can switch it on"),
|
|
"kind": "not_granted"})
|
|
return guest
|