自然语言查询服务器

BlazeSQL MCP Server是一个安全的自然语言查询API服务器和命令行工具,支持MCP协议客户端和直接查询功能。

  • by arjshiv
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 arjshiv/blaze-sql-mcp-server

使用说明

BlazeSQL MCP服务器

blaze-sql-server 是BlazeSQL自然语言查询API的安全默认MCP服务器和CLI。

它支持两种模式:

  • serve:作为用于Cursor、Claude Desktop、Codex和其他MCP客户端的MCP stdio服务器运行
  • query:直接从shell执行单个BlazeSQL请求

亮点

  • MCP工具:暴露 blazesql_query
  • CLI命令: serve, query, doctor, help, version
  • 安全默认值:仅HTTPS远程端点、有界超时、编辑日志记录、上限格式化输出
  • 验证:运行时配置验证和BlazeSQL响应形状验证
  • 工具: pnpm、CI、自动化测试和项目级 mcporter 配置

需求

  • Node.js >=20.11.0
  • pnpm >=10
  • BlazeSQL API密钥

安装

pnpm install
cp .env.sample .env

至少设置:

BLAZE_API_KEY=YOUR_API_KEY_HERE

可选环境变量:

  • BLAZE_API_ENDPOINT
  • BLAZE_REQUEST_TIMEOUT_MS
  • BLAZE_MAX_RESPONSE_CHARS
  • BLAZE_LOG_LEVEL
  • BLAZE_ALLOW_INSECURE_ENDPOINT

构建

pnpm build

作为MCP服务器运行

为了向后兼容,运行不带参数的二进制文件会启动stdio服务器:

node build/index.js

明确地:

node build/index.js serve

暴露的MCP工具是:

  • blazesql_query
  • db_id:BlazeSQL数据库ID
  • natural_language_request:发送到BlazeSQL的提示

与MCPorter一起使用

MCPorter 可以通过以下位置的项目级配置自动发现此服务器 config/mcporter.json.

从项目根:

npx mcporter list
npx mcporter call blazesql.blazesql_query db_id:"your_db_id" natural_language_request:"show me total users"

随时随地临时使用:

npx mcporter call --stdio "node /path/to/blaze-sql-mcp-server/build/index.js" --name blazesql blazesql.blazesql_query db_id:"your_db_id" natural_language_request:"total sales last month"

以CLI运行

打印帮助:

node build/index.js --help

运行直接查询:

node build/index.js query --db-id db_demo --request "show me total users by city"

使用位置参数:

node build/index.js query db_demo "show me total users by city"

从stdin读取请求:

printf 'show me total users by city\n' | node build/index.js query db_demo --stdin

可用输出格式:

node build/index.js query db_demo "show me total users by city" --format markdown
node build/index.js query db_demo "show me total users by city" --format text
node build/index.js query db_demo "show me total users by city" --format json

诊断

检查运行时配置:

node build/index.js doctor
node build/index.js doctor --json

doctor 在共享终端中运行是安全的:它从不打印原始API密钥。

验证

pnpm typecheck
pnpm test
pnpm check

MCP客户端配置

stdio命令示例:

/absolute/path/to/node /absolute/path/to/blaze-sql-mcp-server/build/index.js

因为二进制默认为 serve,MCP客户端不需要额外的子命令。

设计说明

CLI形状有意遵循由以下工具推广的单一用途命令模式 mcporter:一个可预测的命令界面,直接使用shell,以及一个明显的机器可读模式。