Files
superbrain/db/migrations/018_mcp_connections.sql
T
Andrew S Erwin 9cfd6efa38 Outbound MCP connections: Notion-style client integrations (Settings -> MCP)
Superbrain dials external MCP servers as a client (official
modelcontextprotocol/go-sdk): Streamable HTTP or SSE, none/bearer/header
auth. Management surface /api/mcp/connections (CRUD + test) with the house
disciplines:

- secrets encrypted at rest (internal/crypto), masked in every response,
  write-only (mask or omission keeps the stored value); authKind none
  clears them
- mutating PATCH carries version (409 on stale); mask-only PATCH is a
  documented no-op returning the current projection
- dials netguard-pinned (public ranges, ports 80/443 outside tests), no
  redirect following, header names restricted to RFC 7230 tokens
- test endpoint: per-user limiter + shared outbound budget; 502 with an
  error class on dial/auth failure, never a silent ok; returns the tool
  list for the UI
- cap of 10 connections per user under the user lock

UI: Settings -> MCP tab (components/mcp-settings.tsx) — list with enable
switch, add/edit dialog (secret never prefilled), Test showing the live
tool list or the server's error verbatim.

Migration 018 + schema.sql; integration test drives a go-sdk fake MCP
server (incl. a Bearer-secured one) end to end. Tool USE by the assistant
is phase 2.
2026-11-09 11:26:48 -06:00

36 lines
1.6 KiB
SQL

-- 018_mcp_connections.sql — user-registered outbound MCP servers.
--
-- Additive and idempotent; schema.sql carries the identical table, so this
-- is a structural no-op on a fresh database (db-converge proves both paths
-- land the same).
--
-- Superbrain as an MCP CLIENT (Notion-style connections): a user registers
-- external MCP servers (Streamable HTTP or SSE) and the assistant can use
-- their tools. The mirror image of 017_api_keys.sql, which made Superbrain
-- an MCP SERVER for the house gateway.
--
-- Secrets follow the house credential discipline: encrypted at rest via
-- internal/crypto (same versioned format as IMAP passwords and notification
-- channel secrets), masked in every response, write-only (a PATCH echoing
-- the mask keeps the stored value). Dials go through internal/netguard —
-- user-supplied hosts get no trusted-range exemption.
--
-- Mutations carry the row version (409 on stale), like channels/collections.
CREATE TABLE IF NOT EXISTS "McpConnection" (
id text PRIMARY KEY,
"ownerId" text NOT NULL REFERENCES "User"(id) ON DELETE CASCADE,
name text NOT NULL,
url text NOT NULL,
transport text NOT NULL CHECK (transport IN ('streamable-http','sse')),
"authKind" text NOT NULL CHECK ("authKind" IN ('none','bearer','header')),
"headerName" text NOT NULL DEFAULT '',
secret text NOT NULL DEFAULT '',
enabled boolean NOT NULL DEFAULT true,
version integer NOT NULL DEFAULT 1,
"createdAt" timestamptz NOT NULL DEFAULT now(),
"updatedAt" timestamptz NOT NULL DEFAULT now()
);
CREATE INDEX IF NOT EXISTS "McpConnection_ownerId_idx" ON "McpConnection"("ownerId");