数据库API生成工具

CentralMind Gateway是一款自动为结构化数据库生成AI优化API的工具,支持多种协议和数据库类型,适用于AI代理和LLM应用的数据访问需求。

  • by centralmind
  • Go
  • 本地部署
  • 548 星标
  • 更新于
在 GitHub 查看 centralmind/gateway

使用说明

CentralMind Gateway: Create API or MCP Server in Minutes

🚀 交互式演示可在此处查看:https://centralmind.ai

什么是Centralmind/Gateway

通过MCP或OpenAPI 3.1协议将数据库暴露给AI Agent的简单方法。

docker run --platform linux/amd64 -p 9090:9090 \
  ghcr.io/centralmind/gateway:v0.2.18 start \
  --connection-string "postgres://db-user:db-password@db-host/db-name?sslmode=require"

这将为您运行API:

INFO Gateway server started successfully!         
INFO MCP SSE server for AI agents is running at: http://localhost:9090/sse 
INFO REST API with Swagger UI is available at: http://localhost:9090/ 

您可以在AI代理中使用:

网关将生成人工智能优化的API。

为什么选择Centralmind/Gateway

人工智能代理和LLM驱动的应用程序需要快速、安全地访问数据。我们正在构建一个API层,该层可自动为您的结构化数据生成安全、LLM优化的API。

  • 快速从MCP或OpenAPI开始,或使用直接/原始SQL API
  • 过滤PII和敏感数据,以确保符合GDPR、CPRA、SOC 2和其他法规
  • 添加可追溯性和审计功能,确保人工智能应用程序不是黑匣子,并允许安全团队保持控制
  • 针对AI工作负载进行了优化:支持具有增强元数据的模型上下文协议(MCP),以帮助AI代理理解API,以及内置的缓存和安全功能

在开发过程中,当LLM需要从数据库中创建、调整或查询数据时,它可能很有用。 在分析场景中,它使您能够与数据库或数据仓库聊天。 使用远程函数/工具调用,用数据库中的数据丰富您的AI代理。

特性

原理

1.连接和发现

Gateway连接到PostgreSQL等结构化数据库,并自动分析模式和数据样本 根据提示生成优化的API结构。LLM仅在发现阶段用于生成API配置。 该工具使用 AI提供商 在确保安全性的同时生成API配置 通过PII检测。

2.部署

Gateway支持从独立二进制、docker或 库贝内特斯. 查看我们的 发射指南 详细 说明。该系统使用YAML配置和插件进行轻松定制。

3.使用和集成

通过REST API或具有内置安全功能的模型上下文协议(MCP)访问您的数据。 Gateway与AI模型和应用程序无缝集成,如 LangChain, OpenAI 和 克劳德桌面 使用函数调用 或 光标 通过MCP。你也可以 设置遥测 以otel格式发送到本地或远程目的地。

文档

入门指南

额外资源

如何构建

# Clone the repository
git clone https://github.com/centralmind/gateway.git

# Navigate to project directory
cd gateway

# Install dependencies
go mod download

# Build the project
go build .

API生成

Gateway使用LLM模型生成您的API配置。请按照以下步骤操作:

选择我们支持的AI提供商之一:

谷歌双子座提供了一个慷慨的 免费层级.您可以访问Google AI Studio获取API密钥:

登录后,您可以在AI Studio的API部分创建一个API密钥。免费级别包括每月慷慨的代币分配,使其可用于开发和测试目的。

配置AI提供者授权。对于Google Gemini,设置一个API密钥。

export GEMINI_API_KEY='yourkey'
  1. 运行查找命令:
./gateway discover \
  --ai-provider gemini \
  --connection-string "postgresql://neondb_owner:MY_PASSWORD@MY_HOST.neon.tech/neondb?sslmode=require" \
  --prompt "Generate for me awesome readonly API"
  1. 享受生成过程:
INFO 🚀 API Discovery Process
INFO Step 1: Read configs
INFO ✅ Step 1 completed. Done.

INFO Step 2: Discover data
INFO Discovered Tables:
INFO   - payment_dim: 3 columns, 39 rows
INFO   - fact_table: 9 columns, 1000000 rows
INFO ✅ Step 2 completed. Done.

# Additional steps and output...

INFO ✅ All steps completed. Done.

INFO --- Execution Statistics ---
INFO Total time taken: 1m10s
INFO Tokens used: 16543 (Estimated cost: $0.0616)
INFO Tables processed: 6
INFO API methods created: 18
INFO Total number of columns with PII data: 2
  1. 查看中生成的配置 gateway.yaml:
api:
  name: Awesome Readonly API
  description: ''
  version: '1.0'
database:
  type: postgres
  connection: YOUR_CONNECTION_INFO
  tables:
    - name: payment_dim
      columns: # Table columns
      endpoints:
        - http_method: GET
          http_path: /some_path
          mcp_method: some_method
          summary: Some readable summary
          description: 'Some description'
          query: SQL Query with params
          params: # Query parameters

运行API

在本地运行

./gateway start --config gateway.yaml

Docker Compose

docker compose -f ./example/simple/docker-compose.yml up

MCP协议集成

Gateway实现了MCP协议,与Claude和其他工具无缝集成。有关详细的设置说明,请参阅我们的 Claude集成指南.

要将MCP工具添加到Claude Desktop,只需调整Claude的配置:

{
  "mcpServers": {
    "gateway": {
      "command": "PATH_TO_GATEWAY_BINARY",
      "args": ["start", "--config", "PATH_TO_GATEWAY_YAML_CONFIG", "mcp-stdio"]
    }
  }
}

路线图

它总是会发生变化,路线图在很大程度上取决于用户的反馈。此时, 我们正在计划以下功能:

数据库和连接

  • 🗄️ 扩展数据库集成 -Rancher、Redshift、S3(冰山和拼花)、Oracle数据库、Microsoft SQL Server、Elasticsearch
  • 🔑 SSH隧道 -能够使用jumphost或ssh堡垒来隧道连接

增强功能

  • 🔍 高级查询功能 -复杂的过滤语法和聚合函数作为参数
  • 🔐 增强的MCP安全性 -API密钥和OAuth身份验证

平台改进

  • 📦 模式管理 -自动化架构演进和API版本控制
  • 🚦 高级交通管理 -智能限速,请求节流
  • ✍️ 写入操作支持 -插入、更新操作

MCP注册表中的数据库网关

  • https://mcpreview.com/mcp-servers/centralmind/gateway
  • https://mcp.so/server/gateway/centralmind
  • https://smithery.ai/server/@中心地带/网关
  • https://www.pulsemcp.com/servers/centralmind-database-gateway