MCP Gateway
Allows connecting to MySQL databases as read-only data sources for AI-driven queries, with parameterized SQL, column whitelisting, row limits, timeouts, department-based filtering, and sensitive-data masking.
Allows connecting to PostgreSQL databases as read-only data sources for AI-driven queries, with parameterized SQL, column whitelisting, row limits, timeouts, department-based filtering, and sensitive-data masking.
Allows connecting to SQLite databases as read-only data sources for AI-driven queries, with parameterized SQL, column whitelisting, row limits, timeouts, department-based filtering, and sensitive-data masking.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
MCP Gateway
中文 | English
把零散的业务接口与数据库,变成 AI 可发现、可鉴权、可审计的统一能力入口
快速开始 · 项目目标 · 整体架构 · 核心逻辑 · 文档索引
💡 为什么需要它
企业里 AI 要用数据,通常卡在三件事上:
痛点 | 现实表现 |
接口分散 | AI 每接入一个业务系统,就要在 Prompt/代码里硬编码一套接口与参数 |
权限失控 | 谁能访问什么系统、什么接口,散落在各系统里,没有统一入口可管 |
数据裸奔 | 让 AI 直连数据库 → SQL 注入、跨部门越权、无审计、结果撑爆上下文 |
MCP Gateway 的做法:AI 只连一个 MCP 端点,由网关统一完成身份识别、权限判定、请求转发或只读查询、结果裁剪与审计留痕。
Related MCP server: Laravel MCP Gateway
🎯 项目目标
flowchart TB
subgraph PAIN["现状:AI 直连,能力散落"]
direction LR
A1["AI / Skill"] -->|"逐个适配"| B1["订单系统"]
A1 -->|"明文凭证"| B2["用户系统"]
A1 -->|"裸连数据库"| B3["分析库"]
B1 & B2 & B3 -.-> X1["越权 · 注入 · 无审计 · 上下文溢出"]
end
subgraph GOAL["目标:统一网关,一次接入"]
direction LR
A2["AI / Skill"] -->|"一个 MCP 端点<br/>一把 API Key"| G["MCP Gateway"]
G -->|"按权限转发"| C1["业务接口服务"]
G -->|"只读 + 部门过滤"| C2["业务数据库"]
G -.->|"全量留痕"| C3["审计日志"]
end
PAIN ==>|"收敛为单一入口"| GOAL一句话目标:让 AI 天然知道自己能做什么(权限内服务自动发现),并且只能做被允许的事(服务级 + 操作级双层管控),所有数据访问可追溯、可隔离、不裸奔。
🏗 整体架构
flowchart LR
subgraph CONSUMER["消费方"]
AI["AI / Skill / Agent"]
ADMIN["管理后台<br/>React + Ant Design"]
end
subgraph GATEWAY["MCP Gateway"]
direction TB
AUTH["① 认证<br/>API Key → 用户身份<br/>(库中仅存 SHA-256 指纹)"]
DISC["② 能力发现<br/>tools · resources · prompts<br/>只返回权限内清单"]
PERM["③ 权限判定<br/>allow / deny + 操作级 scopes"]
PROXY["④-a HTTP 代理<br/>call_service"]
ENGINE["④-b 数据查询引擎<br/>参数化 · 部门过滤 · 脱敏 · 限流限行"]
AUDIT["⑤ 审计与可观测<br/>行数/字节/耗时/状态 + 健康探针"]
end
subgraph BACKEND["业务后端"]
SVC["业务接口服务<br/>REST API"]
DB[("只读数据库<br/>SQLite / MySQL / PG")]
end
AI -->|"Bearer mcg_..."| AUTH
AUTH --> DISC --> PERM
PERM --> PROXY
PERM --> ENGINE
PROXY --> SVC
ENGINE --> DB
PROXY --> AUDIT
ENGINE --> AUDIT
ADMIN -->|"JWT"| GATEWAY⚙️ 核心逻辑:一次调用发生了什么
flowchart TD
START(["AI 发起 tools/call"]) --> A{"API Key 有效?<br/>用户为 active?"}
A -->|否| E1["401 / 403 拒绝"]
A -->|是| B{"对该服务有 allow 授权?<br/>scopes 包含该操作?"}
B -->|否| E2["拒绝并回传「你可用哪些操作」"]
B -->|是| C{"服务类型"}
C -->|"api<br/>HTTP 接口"| D1["校验端点 method + path<br/>拒绝路径穿越"]
D1 --> D2["转发上游<br/>超时控制 + 响应截断"]
C -->|"database<br/>数据查询"| Q1["列白名单 + 标识符合法性校验"]
Q1 --> Q2["强制注入部门过滤<br/>dept_id + 组织子树"]
Q2 --> Q3["参数化执行<br/>只读连接 · 行数上限 · 超时"]
Q3 --> Q4["敏感列脱敏 mask / hash"]
Q4 --> R{"结果规模"}
R -->|"≤1000 行 且 ≤1MB"| R1["直返 JSON<br/>total · returned · has_more"]
R -->|"超阈值"| R2["落盘 data/query-results/<br/>返回 file_path"]
R2 -.-> R3["read_query_result<br/>按审计归属校验后取回"]
D2 --> AUD["写入审计<br/>用户 · 部门 · 服务 · 行数 · 耗时 · 状态"]
R1 --> AUD
R2 --> AUD关键设计:AI 永远不需要知道接口地址、SQL、部门 ID。它只表达"我要什么",网关负责"能不能给、给多少、怎么给"。
✨ 核心能力
能力 | 说明 |
MCP 三件套 | Tools(服务发现/调用/查询)+ Resources(指南/清单/能力索引)+ Prompts(查数据/发布服务/排障) |
双层权限 | 服务级 |
AI 友好发现 |
|
HTTP 接口代理 | 维护 |
只读数据查询 | 参数化 SQL · 列白名单 · 行数上限 · 超时 · 只读连接 · 组织树部门过滤 · 敏感列脱敏 |
结果智能分流 | 小结果直返 JSON,大结果落盘返回路径(防上下文溢出),可安全取回 |
审计与观测 | 每次查询留痕 + 导出;三级健康探针 |
开箱即用 |
|
可选数据中台 | ODS/DWD/DWS/ADS 四层 + 数据字典 + 质量规则; |
数据源开箱即用 | MySQL / PostgreSQL / SQLite 驱动内置;填主机/端口/账号/库名即可接入,无需手写连接串;界面一键「测试连接」并给出分类错误提示 |
对外集成 API |
|
🚀 快速开始
# 1) 安装并构建(一键脚本会自动完成:检测 Node → 装依赖 → 构建 → 初始化 → 启动)
./start.sh # Linux / macOS
.\start.ps1 # Windows PowerShell
# 2) 或手动执行
npm run setup # 安装前后端依赖 + 构建
npm run db:demo # 生成演示分析库(只读查询用)
npm run db:seed # 初始化用户/服务/权限/API Key
npm run dp:demo #(可选)落地数据中台:建库→采集→建视图→质量→注册查询工具
npm start # 启动(内置 --experimental-sqlite,含启动前自检)
npm run dev # 开发模式(源码热重载,无需构建)
npm run check # 一致性检查(文档链接 / 命令 / 双语配对 / 环境变量)启动后:
入口 | 地址 | 说明 |
管理后台 |
| 默认 |
MCP 端点 |
| AI 用 |
健康诊断 |
| 深度检查报告 |
接入 AI 客户端
{
"mcpServers": {
"mcp-gateway": {
"url": "http://localhost:3100/mcp",
"headers": { "Authorization": "Bearer mcg_你的APIKey" }
}
}
}客户端需在
Accept头同时允许application/json与text/event-stream(MCP 协议要求,主流客户端自动处理)。
👥 两种角色,两条上手路径
角色 | 你要做的事 | 看这里 |
业务人员(想用 AI 查数据) | 装 AI 客户端 → 粘贴管理员给的连接配置 → 放入 | |
开发 / 运维(要部署与授权) | 部署服务 → 配数据源与查询工具 → 建组织与用户 → 签发 API Key 并授权 → 把上述三样交付给业务 |
业务侧无需数据库账号;数据范围、脱敏、审计全部由网关强制执行。
🧪 测试与自检
npm test # 150 项测试:权限模型 / 注入防护 / 部门过滤 / 分页 / 落盘 / 脱敏 / 限流
npm run doctor # 环境自检:Node 版本 / 依赖 / 构建 / 数据库 / 端口,并给出修复建议覆盖要点:只读语句白名单、SQL 注入不可绕过、跨部门数据不可见、API Key 指纹不可反向冒用、大结果落盘与归属校验、配置非法值阻断启动。
📚 文档索引
文档 | 内容 |
5 分钟上手:三种启动方式、拿 API Key、接 AI、常见问题 | |
开发人员部署指南:部署形态、数据中台对接、进程守护、Nginx/HTTPS、运维与安全检查清单 | |
业务人员使用教程:四步安装、能问什么、结果怎么读、合规注意、FAQ | |
可直接分发的技能包:面向业务的数据查询技能(只读、部门隔离、脱敏) | |
技能目录说明与自定义技能编写规范 | |
架构设计、权限模型、数据查询安全链路、数据模型与目录结构 | |
完整接口文档:MCP 协议、管理 API、知识库 API、健康探针、错误码 | |
全部环境变量、默认值与调优建议 | |
可选数据中台方案:采集/存储/计算/服务/治理五能力轻量选型、模块协作、部署要求、对接方式、运维负担评估 | |
对外集成 API 文档:认证与权限、数据源 CRUD、连接测试错误码、数据记录增删改查、Python/Node 示例 | |
中英双语编写规范:文件配对、语言切换行、术语表、提交检查清单 | |
本页英文版(其余文档均提供同名 | |
首次使用体验三轮审查:认知障碍、缺失内容、自洽性问题与行动清单 | |
功能完整性审查与补齐记录(含缺陷修复清单) | |
安全与正确性审计报告 |
以上文档均提供同名
.en.md英文版,页面顶部可一键切换;双语规则见 docs/I18N.md。 | .env.example | 配置模板(复制为.env即生效) | | examples/order-skill | 示例 Skill:如何编写提示词调用本网关 |
🧱 技术栈
后端:TypeScript · Node.js ≥ 22.5(内置 node:sqlite,零原生编译依赖)· Express · @modelcontextprotocol/sdk
前端:React 18 · Ant Design 5 · Vite 6
存储:SQLite(网关元数据)· SQLite / MySQL / PostgreSQL(业务只读数据源)
测试:Node 内置 node:test(零额外依赖)
📄 许可
MIT © MCP Gateway Contributors
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
MCP gateway: one connection for your AI apps, with tool policies, PII redaction and audit logs.
Discover and call 10,000+ production APIs from one MCP server. Pay-per-call billing for AI agents.
Zero-setup MCP gateway securely connecting AI to your tools with authentication and workflows
Zero-secret MCP gateway for AI agents: risk-scored, audited calls with human-in-the-loop approval.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceProvides a secure MCP gateway for AI agents to access APIs without exposing raw credentials, with scoped access, audit logging, and OAuth support.MIT
- AlicenseNot gradedqualityCmaintenanceProvides an OAuth-protected, scoped, and audited MCP server that lets AI assistants safely query business data through a fixed set of tools without direct database access.1MIT
- AlicenseNot gradedqualityBmaintenanceTurns existing REST/OpenAPI APIs into governed MCP tools for AI agents without modifying the APIs themselves, generating agent-friendly tools from specs, Postman collections, HAR files or cURL commands. Owners enable tools and set policies, while every call injects upstream credentials, redacts PII, projects responses to fit context limits, and produces a full audit trail.46 npm5Apache 2.0

Civic MCP Gatewayofficial
AlicenseNot gradedqualityDmaintenanceEnables AI agents to connect to tools and data through a governed MCP endpoint with agent identity, scoped permissions, guardrails, and full audit trails. Access is user-controlled and can be revoked instantly, with every tool call logged by agent identity and timestamp.MIT