Skip to content

feat(connector): per-agent MCP connector — playbooks as tools (ent#46, PR1) - #1355

Closed
dolho wants to merge 1 commit into
devfrom
feature/ent46-mcp-connector
Closed

dolho wants to merge 1 commit into
devfrom
feature/ent46-mcp-connector

Conversation

@dolho

@dolho dolho commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Summary

PR1 (backend + MCP) of the per-agent MCP connector (trinity-enterprise#46): expose a single agent as an MCP connector an end user adds to their AI client (Claude Code, Cursor, Claude Desktop) in one line, turning the agent's user_invocable playbooks (.claude/skills/) into MCP tools. The agent holds credentials server-side; only a scoped, revocable key reaches the client. A new client-sharing channel alongside Slack/Telegram/WhatsApp/VoIP/public links.

Decisions (confirmed up front): OSS core (the #847 entitlement seam can wrap it behind requires_entitlement('mcp_connector') later with a ~1-line diff); first PR is backend + key + MCP tools (Sharing-tab UI is PR2). The per-user SSO/RFC-8693 tier is a separate enterprise epic, out of scope.

What's in this PR

Backend

  • agent_connectors table (config: enabled + exposed-playbook allow-list) — dual-track migration (SQLite agent_connectors_table + Alembic 0006_agent_connectors) + db/tables.py; cascade/rename registered in AGENT_REFS.
  • mcp_api_keys.scope='connector': a separate, owner-bound, SHA-256-hashed, independently-revocable key with regenerate (revoke-old → mint-new) so a leaked copy-paste snippet is cut off. Distinct from the auto-minted scope='agent' key.
  • routers/connectors.py: owner CRUD (GET status / PUT config / POST key / DELETE key) + connector-key-readable GET /connector/playbooks. services/connector_service.py (pure) builds per-client copy-paste snippets with the key pre-embedded (Claude Code claude mcp add + .mcp.json, Cursor mcpServers, Claude Desktop) and resolves exposed = allow-list ∩ user_invocable (a user_invocable:false playbook is never exposed). Raw key returned once.
  • Auth boundary (security-critical): a connector key resolves to the owner but is consumption-only — _enforce_connector_scope fences it to its bound agent on read/chat and refuses owner ops (OwnedAgent* → 403); _reject_connector_principal blocks every role-gated endpoint (require_role/require_admin). A leaked snippet can chat its one agent and nothing else.

MCP server

  • scope='connector' added; connector.ts tools list_playbooks / run_playbook / ask gated by FastMCP canAccess so connector keys see ONLY these and operator keys never do. The agent comes from the bound key, never a tool arg; run_playbook re-checks exposure server-side before dispatching via chat.

Three-surface sync (Invariant #13): backend router + DB, MCP server tools; no agent-server change (reuses the existing /api/skills playbook list + chat).

Testing

  • tests/unit/test_connectors.py — 21 (config CRUD, key lifecycle incl. regenerate-invalidates-old, playbook resolution + user_invocable exclusion, snippet builder, auth boundary).
  • src/mcp-server/src/connector.test.ts — 5 (tool shape, bound-agent enforcement, run_playbook exposure refusal); full MCP suite 36 pass, tsc build clean.
  • schema-parity + alembic-parity + agent-cleanup-parity + migrations + postgres-schema green; auth/dependency regression (173) green.

Deferred (fast-follow)

  • automation: gated approval routing — only the 5s file-based operator queue exists (no synchronous approval primitive); a gated playbook would need create-item-then-poll.
  • ChatGPT connector polish.
  • Sharing-tab connector UI (PR2) — the per-client copy-paste panel + regenerate/revoke button (the backend already returns the snippets).

Docs

architecture.md (subsystem block + MCP tool row + endpoints + agent_connectors DDL + scope='connector') and requirements.md §44.

Related to Abilityai/trinity-enterprise#46

🤖 Generated with Claude Code

…, PR1)

Exposes a single agent as a per-agent MCP connector: an end user adds it to
their AI client (Claude Code, Cursor, Claude Desktop) in one line, turning the
agent's user_invocable playbooks into MCP tools. The agent holds credentials
server-side; only a scoped, revocable key reaches the client. New client-sharing
channel alongside Slack/Telegram/WhatsApp/VoIP/public link.

OSS core (the #847 entitlement seam can wrap it later with a one-line diff). The
per-user SSO/RFC-8693 tier is a separate enterprise epic, out of scope.

Backend:
- agent_connectors table (config: enabled + exposed-playbook allow-list) with
  dual-track migration (SQLite + Alembic 0006) + db/tables.py; cascade/rename
  via AGENT_REFS.
- mcp_api_keys gains scope='connector': a separate, owner-bound, SHA-256-hashed,
  independently-revocable key with regenerate (revoke-old-mint-new) so a leaked
  snippet is cut off. Distinct from the auto-minted scope='agent' key.
- routers/connectors.py: owner CRUD (status / config / mint-regenerate key /
  revoke) + a connector-key-readable /playbooks; services/connector_service.py
  (pure) builds per-client copy-paste snippets with the key embedded and
  resolves exposed = allow-list ∩ user_invocable (user_invocable:false never
  exposed).
- Auth boundary: connector keys are consumption-only — _enforce_connector_scope
  fences them to their bound agent and refuses owner ops; _reject_connector_
  principal blocks every role-gated endpoint.

MCP server:
- scope 'connector' added; connector.ts tools (list_playbooks/run_playbook/ask)
  gated by FastMCP canAccess so connector keys see ONLY these and operator keys
  never do; the agent comes from the bound key, never a tool arg; run_playbook
  re-checks exposure server-side before dispatch.

Tests: test_connectors.py (config CRUD, key lifecycle incl. regenerate-
invalidates-old, playbook resolution, snippet builder, auth boundary) — 21;
connector.test.ts — 5; schema/alembic/cleanup parity green.

Deferred (fast-follow): automation:gated approval routing, ChatGPT polish,
Sharing-tab UI (PR2).

Related to Abilityai/trinity-enterprise#46

Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
@dolho

dolho commented Jun 26, 2026

Copy link
Copy Markdown
Contributor Author

Closing per re-scoping: this should be an enterprise feature, not OSS core. My earlier 'OSS core' framing was wrong — the issue is in the enterprise tracker and ent#45 requires paid-module schema/implementation to live in the private trinity-enterprise repo.

Re-splitting into two PRs:

  1. OSS (public): only the edition-agnostic security primitive — connector-scope recognition + the consumption-only auth fence (the 'core-primitive + enterprise-knob' pattern, like users.suspended_at Enterprise: User & Organization Management (Org/Team + advanced RBAC) on the #847 seam #995), plus the thin MCP proxy tools (public MCP server, dormant without an entitled backend).
  2. Private trinity-enterprise: the feature — enterprise_connectors table on the private runner, CRUD router gated by requires_entitlement('mcp_connector'), snippet generation, key minting, and the UI.

Will link both here.

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