supabase/supabase
AI Assistant
The in-product LLM assistant. Helps users write SQL, generate RLS policies, debug errors, explore the schema, and answer documentation questions. Integrates Model Context Protocol so it can call tools.
Studio surfaces involved
| Folder | Purpose |
|---|---|
apps/studio/components/interfaces/Docs/ |
The docked Assistant panel. |
apps/studio/components/interfaces/SQLEditor/ |
Inline AI completions and "explain this query." |
apps/studio/components/interfaces/Auth/Policies/ |
AI-generated RLS policy suggestions. |
apps/studio/components/interfaces/Advisors/ |
LLM-summarized advisor findings. |
Data layer
Under apps/studio/data/ai/. The Assistant uses Vercel's AI SDK (ai, @ai-sdk/openai, @ai-sdk/amazon-bedrock, @ai-sdk/react) plus the streaming functions in packages/ai-commands/edge.
MCP
Studio bundles @modelcontextprotocol/sdk and @supabase/mcp-server-supabase. This lets the Assistant call typed tools (e.g. "list tables", "run SQL") backed by Studio's existing data layer. @supabase/mcp-utils provides shared helpers for those tool implementations.
How a chat turn works
sequenceDiagram
participant UI as Docs / Assistant panel
participant Hook as data/ai/* hook
participant Edge as ai-commands/edge
participant LLM as OpenAI / Bedrock
participant Tools as MCP tools (Studio data)
UI->>Hook: user message
Hook->>Edge: streaming command
Edge->>LLM: prompt + context
LLM-->>Edge: response stream (may include tool calls)
Edge-->>Tools: dispatch tool calls
Tools-->>Edge: tool results
Edge-->>Hook: streamed tokens
Hook-->>UI: renderStreaming runs on the edge runtime so first-token latency stays low; non-streaming flows use 'ai-commands' directly.
Evaluation
apps/studio/evals/ contains the Braintrust eval harness for the Assistant:
pnpm --filter studio evals:run— run locally.pnpm --filter studio evals:upload— upload runs.pnpm --filter studio scorers:deploy— deploy online scorers.
CI workflows: braintrust-evals.yml, braintrust-preview-scorers-deploy.yml, braintrust-preview-scorers-cleanup.yml, braintrust-scorers-deploy.yml.
Integration points
packages/ai-commands— prompt logic and streaming.- AI SDK from Vercel for client-side wiring.
- MCP SDK +
@supabase/mcp-server-supabasefor tools. - Sentry for prompt error tracking.
Entry points for modification
- Tweak a prompt →
packages/ai-commands/src/. - Add a new MCP tool → register a tool that calls existing data hooks; expose it through the Assistant.
- Tune evaluation →
apps/studio/evals/assistant.eval.ts. - Inline AI in a different surface → reuse the
data/ai/hooks; mount a streaming UI component.
Built by Factory AutoWiki from public repository content. It is a generated preview for codebase exploration, not source-maintained documentation.