返回市场
网关

网关

作者:centralmind503 星标更新:2025-07-19

项目介绍

<div align="center">

构建二进制文件   <a href="https://discord.gg/XFhaUG4F5x"><img src="https://dcbadge.limes.pink/api/server/https://discord.gg/XFhaUG4F5x" height="20"></a>   <a href="https://t.me/+TM3T1SikjzA4ZWVi"><img src="https://img.shields.io/badge/telegram-%E2%9D%A4%EF%B8%8F-252850?style=plastic&logo=telegram" height=20></a>    <a href="https://docs.centralmind.ai"><img src="https://img.shields.io/badge/完整文档-blue?style=for-the-badge&logo=rocket&logoColor=white" height="20"></a>   <a href="https://cursor.com/install-mcp?name=CentralMind%20Database%20Gateway&config=eyJjb21tYW5kIjoiZG9ja2VyIHJ1biAtaSAtLXBsYXRmb3JtIGxpbnV4L2FtZDY0IGdoY3IuaW8vY2VudHJhbG1pbmQvZ2F0ZXdheTp2MC4yLjE4IC0tY29ubmVjdGlvbi1zdHJpbmcgcG9zdGdyZXNxbDovL215X3VzZXI6bXlfcGFzc0Bsb2NhbGhvc3Q6NTQzMi9teWRiIHN0YXJ0IHN0ZGlvIn0%3D"><img height="21" src="https://cursor.com/deeplink/mcp-install-dark.svg"></a>

</div> <h2 align="center">CentralMind 网关:几分钟内创建API或MCP服务器</h2>

🚀 互动演示在这里:https://centralmind.ai

Centralmind/Gateway 是什么

一种简单的方法,通过MCP或OpenAPI 3.1协议将您的数据库暴露给AI代理。

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 网关服务器启动成功!         
INFO AI代理的MCP SSE服务器正在运行于:http://localhost:9090/sse 
INFO 带有Swagger UI的REST API可用于:http://localhost:9090/

您可以在您的AI代理中使用它:

mcp-raw-cursor-setup.png

网关将生成优化的AI API。

为什么选择 Centralmind/Gateway

AI代理和LLM驱动的应用程序需要快速、安全的数据访问。我们正在构建一个API层,该层可以自动生成针对您的结构化数据进行优化的安全API。

  • 快速开始使用MCP或OpenAPI,或者使用Direct/Raw SQL API
  • 过滤掉个人身份信息(PII)和敏感数据,确保符合GDPR、CPRA、SOC 2和其他法规
  • 添加可追溯性和审计能力,确保AI应用程序不是黑盒,并允许安全团队维持控制
  • 优化用于AI工作负载:支持带有增强元数据的模型上下文协议(MCP),以帮助AI代理理解API,以及内置缓存和安全特性

在开发过程中非常有用,当LLM需要从您的数据库创建、调整或查询数据时。 在分析场景中,它使您可以与数据库或数据仓库进行对话。 使用远程函数/工具调用丰富您的AI代理,从您的数据库获取数据。

演示

功能

  • 自动API生成 – 使用基于LLM的表模式和采样数据自动生成API
  • 🗄️ 结构化数据库支持 – 支持 <a href="https://docs.centralmind.ai/connectors/postgres/">PostgreSQL</a><a href="https://docs.centralmind.ai/connectors/mysql/">MySQL</a><a href="https://docs.centralmind.ai/connectors/clickhouse/">ClickHouse</a><a href="https://docs.centralmind.ai/connectors/snowflake/">Snowflake</a><a href="https[://docs.centralmind.ai/connectors/mssql/">MSSQL</a><a href="https://docs.centralmind.ai/connectors/bigquery/">BigQuery</a><a href="https://docs.centralmind.ai/connectors/oracle/">Oracle Database</a><a href="https://docs.centralmind.ai/connectors/sqlite/">SQLite</a><a href="https://docs.centralmind.ai/connectors/elasticsearch/">ElasticSearch</a>
  • 🌍 多种协议支持 – 提供作为REST或MCP服务器的API,包括SSE模式
  • 🔐 认证选项 – 内置支持 <a href="https://docs.centralmind.ai/plugins/api_keys/">API密钥</a><a href="https://docs.centralmind.ai/plugins/oauth/">OAuth</a>
  • 🔒 PII保护 – 实现 <a href="https://docs.centralmind.ai/plugins/pii_remover/">正则插件</a><a href="https://docs.centralmind.ai/plugins/presidio_anonymizer/">Microsoft Presidio插件</a> 对PII和敏感数据进行红处理
  • 👀 全面监控 – 集成 <a href="https://docs.centralmind.ai/plugins/otel/">OpenTelemetry (OTel)</a> 进行请求跟踪和审计轨迹
  • 📦 本地及内部部署 – 支持 <a href="https://docs.centralmind.ai/providers/local-models/">自托管LLM</a> 通过可配置的AI端点和模型
  • 🤖 多个AI提供商支持 - 支持 OpenAIAnthropicAmazon BedrockGoogle Gemini & Google VertexAI
  • 灵活配置 – 通过YAML配置和插件系统轻松扩展
  • 📜 API文档 – 自动生成Swagger文档和OpenAPI 3.1.0规范
  • 🔑 行级安全性(RLS) – 使用 <a href="https://docs.centralmind.ai/plugins/lua_rls/">Lua脚本</a> 进行细粒度数据访问控制
  • 🏎️ 性能优化 – 实现基于时间的和 <a href="https://docs.centralmind.ai/plugins/lru_cache/">LRU缓存</a> 策略

它是如何工作的

<div align="center">

img.png

</div>

1. 连接与发现

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

2. 部署

网关支持多种部署选项,包括独立二进制文件、Docker或 <a href="https://docs.centralmind.ai/example/k8s/">Kubernetes</a>。 查看我们的 <a href="https://docs.centralmind.ai/docs/content/getting-started/launching-api/">启动指南</a> 获取详细说明。系统使用YAML配置和插件进行轻松定制。

3. 使用与集成

通过REST API或带有内置安全特性的模型上下文协议(MCP)访问您的数据。 网关无缝集成到AI模型和应用中,如 <a href="https://docs.centralmind.ai/docs/content/integration/langchain/">LangChain</a><a href="https://docs.centralmind.ai/docs/content/integration/chatgpt/">OpenAI</a><a href="https://docs.centralmind.ai/docs/content/integration/claude-desktop/">Claude Desktop</a> 使用函数调用 或 <a href="https://docs.centralmind.ai/docs/content/integration/cursor/">Cursor</a> 通过MCP。您还可以 <a href="https://docs.centralmind.ai/plugins/otel/">设置遥测</a> 到本地或远程目的地,格式为otel。

文档

入门

  • <a href="https://docs.centralmind.ai/docs/content/getting-started/quickstart/">快速入门指南</a>
  • <a href="https://docs.centralmind.ai/docs/content/getting-started/installation/">安装说明</a>
  • <a href="https://docs.centralmind.ai/docs/content/getting-started/generating-api/">API生成指南</a>
  • <a href="https://docs.centralmind.ai/docs/content/getting-started/launching-api/">API启动指南</a>

额外资源

  • <a href="https://docs.centralmind.ai/docs/content/integration/chatgpt/">ChatGPT集成指南</a>
  • <a href="https://docs.centralmind.ai/connectors/">数据库连接器文档</a>
  • <a href="https://docs.centralmind.ai/plugins/">插件文档</a>

如何构建

# 克隆存储库
git clone https://github.com/centralmind/gateway.git

# 导航到项目目录
cd gateway

# 安装依赖项
go mod download

# 构建项目
go build .

API生成

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

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

Google Gemini 提供了慷慨的 免费层级。您可以通过访问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 "为我生成一个很棒的只读API"
  1. 享受生成过程:
INFO 🚀 API发现过程
INFO 第一步:读取配置
INFO ✅ 第一步完成。完成。

INFO 第二步:发现数据
INFO 发现的表:
INFO   - payment_dim: 3列,39行
INFO   - fact_table: 9列,1000000行
INFO ✅ 第二步完成。完成。

# 更多步骤和输出...

INFO ✅ 所有步骤完成。完成。

INFO --- 执行统计 ---
INFO 总耗时:1分10秒
INFO 使用的令牌数:16543(估计成本:$0.0616)
INFO 处理的表数:6
INFO 创建的API方法数:18
INFO 包含PII数据的总列数:2
  1. 查看生成的配置在 gateway.yaml 中:
api:
  name: 棒极了的只读API
  description: ''
  version: '1.0'
database:
  type: postgres
  connection: YOUR_CONNECTION_INFO
  tables:
    - name: payment_dim
      columns: # 表列
      endpoints:
        - http_method: GET
          http_path: /some_path
          mcp_method: some_method
          summary: 一些可读的摘要
          description: '一些描述'
          query: SQL查询带参数
          params: # 查询参数

运行API

本地运行

./gateway start --config gateway.yaml

Docker Compose

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

MCP协议集成

网关实现了MCP协议,以便与Claude和其他工具无缝集成。有关详细的设置说明,请参阅我们的 <a href="https://docs.centralmind.ai/docs/content/integration/claude-desktop/">Claude集成指南</a>

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

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

路线图

它始终会有所变化,路线图将高度依赖于用户反馈。目前,我们计划以下功能:

数据库和连接性

  • 🗄️ 扩展数据库集成 - Databricks, Redshift, S3 (Iceberg和Parquet), Oracle DB, Microsoft SQL Server, Elasticsearch
  • 🔑 SSH隧道 - 使用跳转主机或SSH堡垒机进行隧道连接的能力

增强功能

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

平台改进

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

数据库网关在MCP注册表中