项目简介

Neon MCP Server 是一个基于 Model Context Protocol (MCP) 构建的服务器,旨在连接大型语言模型 (LLM) 与 Neon 数据库。通过此服务器,用户可以使用自然语言指令,让 LLM 客户端(如 Claude Desktop)操作和管理 Neon 数据库资源,例如创建项目、管理分支、执行 SQL 查询以及进行数据库迁移等。

主要功能点

  • Neon 数据库资源管理: 支持通过自然语言指令管理 Neon 数据库项目和分支,例如列出项目、创建项目、删除项目、创建分支、删除分支等。
  • SQL 查询执行: 允许 LLM 客户端通过自然语言指令在 Neon 数据库上执行 SQL 查询和事务。
  • 数据库 Schema 探索: 提供工具让 LLM 客户端了解数据库的表结构和模式信息。
  • 数据库迁移: 支持通过自然语言指令安全地进行数据库 Schema 迁移,包括创建临时分支进行测试和最终提交迁移。
  • 连接信息获取: 可以为 LLM 客户端提供连接 Neon 数据库所需的连接字符串。

安装步骤

前提条件

  • 确保已安装 Node.js v18.0.0 或更高版本
  • 已安装 Claude Desktop 客户端。
  • 拥有 Neon API Key,可以在 Neon 控制台 中创建。

安装方式

通过 Smithery 自动安装 (推荐 Claude Desktop 用户)

打开终端,运行以下命令,即可自动为 Claude Desktop 安装 Neon MCP Server:

npx -y @smithery/cli install neon --client claude

本地手动安装

  1. 初始化配置: 打开终端,运行以下命令,将 Neon MCP Server 配置到 Claude Desktop,需要替换 '$NEON_API_KEY' 为你的 Neon API Key。

    npx @neondatabase/mcp-server-neon init $NEON_API_KEY
  2. 重启 Claude Desktop: 完成初始化配置后,重启 Claude Desktop 客户端。

服务器配置

对于 MCP 客户端(例如 Claude Desktop),需要配置 MCP 服务器的启动信息才能连接到 Neon MCP Server。以下是针对 Neon MCP Server 的配置信息,通常 Claude Desktop 会自动完成配置,手动配置可参考以下 JSON 格式:

{
  "mcpServers": {
    "neon": {  // 服务器名称,客户端用此名称标识 Neon MCP Server
      "command": "npx", // 启动服务器的命令,这里使用 npx 运行 npm 包
      "args": [      // 启动参数
        "-y",         // npx 参数,自动确认安装包
        "@neondatabase/mcp-server-neon", // Neon MCP Server 的 npm 包名
        "start",      // 服务器启动命令
        "YOUR_NEON_API_KEY" // 你的 Neon API Key,请替换为实际的 API Key
      ]
    }
  }
}

注意: 'YOUR_NEON_API_KEY' 务必替换 为你自己的 Neon API Key。

基本使用方法

安装并配置完成后,重启 Claude Desktop。现在你可以通过自然语言指令与 Neon 数据库进行交互了。

示例指令

  • 'List me all my Neon projects' (列出所有 Neon 项目)
  • 'Let's create a new Postgres database, and call it "my-database". Let's then create a table called users with the following columns: id, name, email, and password.' (创建一个名为 "my-database" 的 Postgres 数据库,并在其中创建一个名为 users 的表)
  • 'I want to run a migration on my project called "my-project" that alters the users table to add a new column called "created_at".' (在 "my-project" 项目上运行迁移,为 users 表添加 "created_at" 列)
  • 'Can you give me a summary of all of my Neon projects and what data is in each one?' (总结我的所有 Neon 项目以及每个项目中的数据)

更多使用指南,请参考仓库 README.md 中提供的链接。

信息

分类

数据库与文件