基本能力
产品定位
mcp-graphql 是一个用于连接大型语言模型(LLMs)和 GraphQL API 的中间件,旨在提供动态的 API 发现和查询执行能力。
核心功能
- 模式自省:通过
introspect-schema
工具自动获取 GraphQL 模式。 - 查询执行:通过
query-graphql
工具执行 GraphQL 查询。 - 资源暴露:将 GraphQL 模式作为资源暴露给客户端。
- 安全控制:默认禁用突变操作,以防止未经授权的数据修改。
适用场景
- 动态 API 集成:当 LLMs 需要动态发现和使用 GraphQL API 时。
- 开发测试:在开发过程中快速测试和验证 GraphQL 查询。
- 自动化工具:构建自动化工具,利用 LLMs 生成和执行 GraphQL 查询。
工具列表
- introspect-schema:获取 GraphQL 模式,支持本地模式文件或自省查询。
- query-graphql:执行 GraphQL 查询,默认禁用突变操作。
常见问题解答
- 突变操作禁用:默认禁用突变操作,需通过
--enable-mutations
参数启用。 - 安全考虑:在生产环境中启用突变操作前需仔细考虑安全风险。
使用教程
使用依赖
无特殊依赖,直接通过 npm 安装即可。
安装教程
通过 Smithery 安装
bash
npx -y @smithery/cli install mcp-graphql --client claude
手动安装
在 Claude 配置文件中添加以下内容:
json
{
"mcpServers": {
"mcp-graphql": {
"command": "npx",
"args": ["mcp-graphql", "--endpoint", "http://localhost:3000/graphql"]
}
}
}
调试方式
基本用法
bash
npx mcp-graphql --endpoint http://localhost:3000/graphql
使用自定义头部
bash
npx mcp-graphql --endpoint https://api.example.com/graphql --headers '{"Authorization":"Bearer token123"}'
启用突变操作
bash
npx mcp-graphql --endpoint http://localhost:3000/graphql --enable-mutations
使用本地模式文件
bash
npx mcp-graphql --endpoint http://localhost:3000/graphql --schema ./schema.graphql