-- 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");