PostgREST (Supabase) MCP server

Connects to Supabase projects using PostgREST, or standalone PostgREST servers, enabling natural language querying and management of PostgreSQL data.
Back to servers
Setup instructions
Provider
Supabase
Release date
Jan 08, 2025
Language
TypeScript
Package
Stats
11.4K downloads
1.9K stars

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.

Available Tools

postgrestRequest

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.

sqlToRest

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.

Installation and Setup

Using Claude Desktop

To connect your PostgREST server to Claude Desktop:

  1. Locate the Claude Desktop configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%\Claude\claude_desktop_config.json
  2. 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"
      ]
    }
  }
}

Configuration Options

  • apiUrl: Base URL of your PostgREST endpoint
  • apiKey: Authentication API key (optional)
  • schema: PostgreSQL schema to use (default: public)

Programmatic Usage

For custom MCP clients, you can use the server programmatically:

Package Installation

npm i @supabase/mcp-server-postgrest

or

yarn add @supabase/mcp-server-postgrest

or

pnpm add @supabase/mcp-server-postgrest

Integration Example

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',
  },
});

How to install this MCP server

For Claude Code

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.

For Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later