数据库API生成工具

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

  • by andreagroferreira
  • 本地部署
  • 更新于
在 GitHub 查看 andreagroferreira/gateway

使用说明

CentralMind Gateway: Create API or MCP Server in Minutes

🚀 通过GitHub Codespace进行交互式演示

什么是Centralmind/Gateway

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

docker run --platform linux/amd64 -p 9090:9090 \
  ghcr.io/centralmind/gateway:v0.2.6 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和数据库并不是为此目的而构建的。我们正在构建一个API层,该层可自动为您的结构化数据生成安全、LLM优化的API。

我们的解决方案:

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

我们的主要用户是部署人工智能代理进行客户支持、分析的公司,他们需要模型来访问数据,而无需直接SQL访问数据库,这会增加安全性、合规性和性能风险。

特性

它是如何工作的

1.连接和发现

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

2.部署

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

3.使用和集成

通过REST API或具有内置安全功能的模型上下文协议(MCP)访问您的数据。 Gateway与AI模型和应用程序无缝集成,如 LangChain, 开放人工智能 和 克劳德桌面版 使用函数调用 或 光标 通过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配置。请按照以下步骤操作:

  1. 选择我们支持的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 rest

Docker Compose

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

MCP协议集成

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

  1. 构建网关二进制文件:
go build .
  1. 配置Claude Desktop工具配置:
{
  "mcpServers": {
    "gateway": {
      "command": "PATH_TO_GATEWAY_BINARY",
      "args": ["start", "--config", "PATH_TO_GATEWAY_YAML_CONFIG", "mcp-stdio"]
    }
  }
}

路线图

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

数据库和连接

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

增强功能

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

平台改进

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