Skip to main content
Glama

@supabase/mcp-server-postgrest

这是PostgREST的 MCP 服务器。它允许 LLM 通过 REST API 在你的应用上执行 CRUD 操作。

该服务器可与 Supabase 项目(运行 PostgREST)和任何独立的 PostgREST 服务器配合使用。

工具

可以使用以下工具:

postgrestRequest

已配置的PostgREST 服务器执行 HTTP 请求。它接受以下参数:

  • method :要使用的 HTTP 方法(例如GETPOSTPATCHDELETE

  • path :查询的路径(例如/todos?id=eq.1

  • body :请求主体(用于POSTPATCH请求)

它返回来自 PostgREST 服务器的 JSON 响应,包括GET请求的选定行以及POSTPATCH请求的更新行。

sqlToRest

将 SQL 查询转换为等效的 PostgREST 语法(作为方法和路径)。这对于 LLM 难以转换为有效 PostgREST 语法的复杂查询非常有用。

请注意,PostgREST 仅支持 SQL 的子集,因此并非所有查询都会转换。有关更多详细信息,请参阅sql-to-rest

它接受以下参数:

  • sql :要转换的 SQL 查询。

它返回一个包含请求的methodpath属性的对象。然后,LLM 可以使用postgrestRequest工具来执行该请求。

Related MCP server: Supabase MCP Server

用法

使用 Claude Desktop

Claude Desktop是一款流行的 LLM 客户端,支持模型上下文协议 (MCP)。您可以将 PostgREST 服务器连接到 Claude Desktop,以便通过自然语言命令查询数据库。

您可以通过以下配置文件将 MCP 服务器添加到 Claude Desktop:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows: %APPDATA%\Claude\claude_desktop_config.json

要将您的 Supabase 项目*(或任何 PostgREST 服务器)*添加到 Claude Desktop,请将以下配置添加到配置文件中的mcpServers对象:

{
  "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 :PostgREST 端点的基本 URL

  • apiKey :用于身份验证的 API 密钥*(可选)*

  • schema :用于提供 API 的 Postgres 模式(例如public )。请注意,任何非公共模式都必须从 PostgREST 手动公开。

以编程方式(自定义 MCP 客户端)

如果您正在构建自己的 MCP 客户端,可以使用您首选的传输方式以编程方式连接到 PostgREST 服务器。MCP SDK提供内置的stdioSSE传输方式。如果您希望直接连接到内存中的 MCP 服务器,或者通过您自己的基于流的传输方式进行管道传输,我们还提供StreamTransport接口。

安装

npm i @supabase/mcp-server-postgrest
yarn add @supabase/mcp-server-postgrest
pnpm add @supabase/mcp-server-postgrest

例子

以下示例使用StreamTransport直接连接 MCP 客户端和服务器。

import { Client } from '@modelcontextprotocol/sdk/client/index.js';
import { StreamTransport } from '@supabase/mcp-utils';
import { createPostgrestMcpServer } from '@supabase/mcp-server-postgrest';

// Create a stream transport for both client and server
const clientTransport = new StreamTransport();
const serverTransport = new StreamTransport();

// Connect the streams together
clientTransport.readable.pipeTo(serverTransport.writable);
serverTransport.readable.pipeTo(clientTransport.writable);

const client = new Client(
  {
    name: 'MyClient',
    version: '0.1.0',
  },
  {
    capabilities: {},
  }
);

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 the client and server to their respective transports
await server.connect(serverTransport);
await client.connect(clientTransport);

// Call tools, etc
const output = await client.callTool({
  name: 'postgrestRequest',
  arguments: {
    method: 'GET',
    path: '/todos',
  },
});
-
security - not tested
A
license - permissive license
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/supabase-community/mcp-supabase'

If you have feedback or need assistance with the MCP directory API, please join our Discord server