PostgREST

Official
Apache 2.0
372
1,198
  • Apple

hybrid server

The server is able to function both locally and remotely, depending on the configuration or use case.

Integrations

  • Enables LLMs to perform database queries and operations on Supabase projects via PostgREST API

  • Offers TypeScript SDK support through the MCP SDK for programmatic integration with PostgREST servers

@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工具来执行该请求。

用法

使用 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

这是 PostgREST 的 MCP 服务器。它允许 LLM 通过 PostgREST 对 Postgres 数据库执行数据库查询和操作。该服务器既可以与使用 PostgREST 的 Supabase 项目配合使用,也可以与独立的 PostgREST 服务器配合使用。

  1. Tools
    1. postgrestRequest
    2. sqlToRest
  2. Usage
    1. With Claude Desktop
    2. Programmatically (custom MCP client)
ID: b4wipgdgar