mcpField
M
mcpolyglot

mcpolyglot

本地服务
github.com/ishay60数据库12 天前更新

关于 mcpolyglot

mcpolyglot 是面向 Agent 的数据库与 REST API MCP 服务,可连接 Postgres、MySQL、SQLite、MongoDB 和 OpenAPI API。它通过策略、审计及按 Agent 配置的令牌和权限控制数据访问。

主要功能

  1. 01连接多种数据库与 REST API
  2. 02按策略限制表级访问
  3. 03为 Agent 配置令牌与权限范围
  4. 04提供连接检查和工具列表
  5. 05通过 stdio 或 Streamable HTTP 服务

适用场景

  1. 01按 Agent 隔离数据库访问
  2. 02限制可读写的表和操作范围
  3. 03检查配置、数据源连接和可用工具

MCP 相关

它向 MCP 客户端提供按配置和权限范围生成的工具。服务可通过 stdio 或带 bearer auth 的 Streamable HTTP 运行。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"ishay60-mcpolyglot": {
"command": "npx",
"args": [
"-y",
"@mcpolyglot/cli"
]
}
}
}
启动命令npx -y @mcpolyglot/cli

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@mcpolyglot/cli0.4.3

工具

还没有获取到工具列表

本地服务需要在你的电脑上运行后才能读取工具,维护者暂未提供工具列表。

详细介绍

@mcpolyglot/cli

mcpolyglot 命令行界面。用于搭建配置、验证连接、列出工具,并通过 stdio 或 Streamable HTTP 提供 MCP 服务。

npx @mcpolyglot/cli init       # interactive wizard
npx @mcpolyglot/cli doctor     # validate config, ping sources, list tools
npx @mcpolyglot/cli tools      # list tools mcpolyglot would expose
npx @mcpolyglot/cli serve      # start the MCP server (stdio)
npx @mcpolyglot/cli serve --http --port 7337   # start over Streamable HTTP

命令

命令用途
init以交互方式在当前目录搭建 mcpolyglot.config.ts。
doctor加载并验证配置、解析密钥、ping 每个来源并列出工具。
tools输出当前配置下 mcpolyglot 将公开的所有工具。
serve启动服务。--http 切换到带有 bearer 身份验证的 Streamable HTTP。
tokentoken create <agentId> 生成 Agent 专属令牌;token hash 对令牌进行哈希处理。

serve --http 会在 stderr 上输出 bearer 令牌、MCP URL 和 /healthz URL。将令牌固定在配置中(transport.auth.token),以便稳定部署;省略该项则每次启动都会生成新令牌。

通过 HTTP 服务多个 Agent

为每个 Agent 配置独立的令牌、来源和作用域。令牌仅以 sha256 哈希形式存储:

mcpolyglot token create analyst       # prints the token once, its hash, and a config snippet
echo -n "$TOKEN" | mcpolyglot token hash
agents: [
  {
    id: 'analyst',
    tokens: [{ hash: '<sha256 hex>', label: '2026-09' }],
    scopes: ['schema:read', 'tables:read', 'query:raw'],
    sources: { 'pg.main': { policy: { tables: { users: 'none' } } } },
  },
],
  • Agent 只能看到其名下所列来源的工具,且仅限其作用域完全覆盖的工具。scopes 默认为这些来源作用域的并集,且不会超出该并集。
  • 每个 Agent 的 policy 只能收窄来源的 policy:对每个表采用限制最严格的访问权限,合并拒绝列表,并取较小的上限。Agent 无法重新开放来源隐藏的表,也无法获得来源未授予的写入权限。反之亦然:如果 Agent 的策略未列出某个表,该表将采用其 defaultAccess(最多为 read),因此,若要保留来源的写入权限,Agent 必须再次将该表列为 write。Agent 会使用自己的连接器,因此也使用自己的数据库连接;未配置策略的来源则共用主连接。
  • 令牌决定审计记录中的 agentId;设置了 agents 时,x-mcpolyglot-agent 标头会被忽略。未知或已撤销的令牌会返回 401。
  • 轮换令牌:添加新哈希,将客户端切换到新令牌,为旧令牌设置 revoked: true(或将其删除),然后重启 serve。不支持热重载。
  • agents 需要 bearer 身份验证(不支持 OAuth),在 stdio 模式下会被忽略(单一本地用户)。doctor 会列出每个 Agent 可以和不可以使用的内容。

stdio 服务必须保持 stdout 清洁,因此所有 CLI 输出都会发送到 stderr。

文档

采用 MIT 许可证。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。