The PostgREST MCP server provides integration between LLMs and your database, allowing AI models to interact with your data through a REST API. This enables natural language-driven CRUD operations on your PostgreSQL database without requiring direct database access.
This tool performs HTTP requests to your PostgREST server with these parameters:
method
: HTTP method (GET
, POST
, PATCH
, DELETE
)path
: The endpoint path (e.g., /todos?id=eq.1
)body
: Request payload (for POST
/PATCH
requests)The tool returns JSON responses from the server, including rows for GET
requests and updated data for POST
/PATCH
operations.
Converts SQL queries to equivalent PostgREST syntax, returning an object with method
and path
properties that can be used with the postgrestRequest
tool. This is particularly useful for complex queries that LLMs might struggle to express in PostgREST format.
Note that only a subset of SQL syntax is supported by PostgREST.
To connect your PostgREST server to Claude Desktop:
Locate the Claude Desktop configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
Add your PostgREST server configuration to the mcpServers
object:
{
"mcpServers": {
"todos": {
"command": "npx",
"args": [
"-y",
"@supabase/mcp-server-postgrest@latest",
"--apiUrl",
"https://your-project-ref.supabase.co/rest/v1",
"--apiKey",
"your-anon-key",
"--schema",
"public"
]
}
}
}
apiUrl
: Base URL of your PostgREST endpointapiKey
: Authentication API key (optional)schema
: PostgreSQL schema to use (default: public
)For custom MCP clients, you can use the server programmatically:
npm i @supabase/mcp-server-postgrest
or
yarn add @supabase/mcp-server-postgrest
or
pnpm add @supabase/mcp-server-postgrest
Here's how to connect a client and server using StreamTransport
:
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamTransport } from '@supabase/mcp-utils';
import { createPostgrestMcpServer } from '@supabase/mcp-server-postgrest';
// Create transport streams
const clientTransport = new StreamTransport();
const serverTransport = new StreamTransport();
// Connect the streams together
clientTransport.readable.pipeTo(serverTransport.writable);
serverTransport.readable.pipeTo(clientTransport.writable);
// Initialize client
const client = new Client(
{
name: 'MyClient',
version: '0.1.0',
},
{
capabilities: {},
}
);
// Configure server
const supabaseUrl = 'https://your-project-ref.supabase.co'; // http://127.0.0.1:54321 for local
const apiKey = 'your-anon-key'; // or service role, or user JWT
const schema = 'public'; // or any other exposed schema
const server = createPostgrestMcpServer({
apiUrl: `${supabaseUrl}/rest/v1`,
apiKey,
schema,
});
// Connect client and server to transports
await server.connect(serverTransport);
await client.connect(clientTransport);
// Make tool calls
const output = await client.callTool({
name: 'postgrestRequest',
arguments: {
method: 'GET',
path: '/todos',
},
});
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "todos" '{"command":"npx","args":["-y","@supabase/mcp-server-postgrest@latest","--apiUrl","https://your-project-ref.supabase.co/rest/v1","--apiKey","your-anon-key","--schema","public"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"todos": {
"command": "npx",
"args": [
"-y",
"@supabase/mcp-server-postgrest@latest",
"--apiUrl",
"https://your-project-ref.supabase.co/rest/v1",
"--apiKey",
"your-anon-key",
"--schema",
"public"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"todos": {
"command": "npx",
"args": [
"-y",
"@supabase/mcp-server-postgrest@latest",
"--apiUrl",
"https://your-project-ref.supabase.co/rest/v1",
"--apiKey",
"your-anon-key",
"--schema",
"public"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect