Supabase MCP Server: Tables, Queries, Edge Functions
Manage data with Supabase MCP server: create tables, run queries, and deploy edge functions for scalable, real-time apps.
npx -y @supabase-community/supabase-mcpOverview
The Supabase MCP Server implements a Model Context Protocol (MCP) back-end on top of Supabase (Postgres + Realtime + Edge Functions). It exposes a minimal set of HTTP endpoints and utilities to create/manage tables, run SQL/parameterized queries, and deploy server-side Edge Functions that provide scalable, low-latency context for LLMs or other model-driven applications.
This server is designed for developers who need a persistent, queryable context layer for stateful AI applications, chat history, personalization, or analytics. By combining Supabase storage and real-time features with MCP-style APIs and edge functions, this project makes it straightforward to store contextual data, retrieve it with controlled queries, and run bespoke logic at the edge.
Features
- Create and manage Postgres tables via a small HTTP API
- Run parameterized and raw SQL queries programmatically
- Deploy and invoke Edge Functions for server-side logic and model orchestration
- Support for real-time updates through Supabase Realtime (WebSocket)
- Simple authentication via Supabase service key or JWTs
- Local development and Docker-ready deployment patterns
Installation / Configuration
- Clone the repository
- Create a .env file (example)
# .env
SUPABASE_URL=https://your-project.supabase.co
SUPABASE_SERVICE_KEY=your-service-role-key
PORT=3000
NODE_ENV=development
- Install dependencies (Node example)
# or
- Run locally
# Start the MCP server
# or with Node directly
- Docker (optional) — example docker-compose snippet
version: '3.8'
services:
mcp-server:
build: .
ports:
- "3000:3000"
environment:
- SUPABASE_URL=${SUPABASE_URL}
- SUPABASE_SERVICE_KEY=${SUPABASE_SERVICE_KEY}
- Deploy Edge Functions with the Supabase CLI
# install supabase cli if needed
# deploy an edge function folder named 'mcp-handler'
Available Resources
- GitHub repository: https://github.com/supabase-community/supabase-mcp
- Supabase docs (for configuring Postgres, auth, and edge functions): https://supabase.com/docs
- MCP-style endpoints exposed by the server (typical paths)
| Endpoint | Method | Description |
|---|---|---|
| /tables | POST | Create a new table definition |
| /tables/:name | GET | Get table schema or metadata |
| /queries | POST | Run a parameterized or raw SQL query |
| /functions/:name | POST | Invoke a deployed edge function |
| /realtime | GET/WS | Connect to realtime updates (WebSocket) |
(Exact endpoint paths may vary by release — check the repo README for the current API surface.)
Examples
Create a table (API)
Run a parameterized query
Invoke an edge function
Use Cases
- Chatbots and conversational AI: Store user messages, system prompts, and model outputs in a table; query recent turns as model context before each completion.
- Personalization: Keep user preferences and interaction events in a queryable store; run edge functions to compute features or transforms for model inputs.
- Analytics and telemetry: Log events, run aggregated queries for dashboards, and push real-time changes to front-end via Supabase Realtime.
- Moderation and filtering pipelines: Use edge functions to apply policy checks to incoming messages or content before persisting or forwarding to a model.
Concrete example — session context for a chat app:
- Create a chat_history table (as shown above).
- On each user message, insert a row via /queries or direct Postgres insert.
- Before calling the LLM, run a /queries call to fetch the last N messages for that user and pass them to the model.
- Optionally, run an edge function to sanitize or enrich messages (e.g., embedding, metadata extraction) before storage.
Best Practices and Notes
- Use a Supabase service role key on trusted backends only; never expose it to client-side code.
- Prefer parameterized queries to avoid SQL injection when executing dynamic SQL.
- Use edge functions for CPU- or policy-sensitive logic rather than embedding heavy logic in the MCP server process.
- Monitor your Supabase Postgres limits and plan for indexing hot tables (e.g., chat history by user_id + created_at).
For more details, configuration options, and the exact API schema, see the project repository: https://github.com/supabase-community/supabase-mcp