Skip to main content
Glama

格奇

graphql → ai

gqai是一个轻量级代理,它将 GraphQL 操作公开为 Claude、Cursor 和 ChatGPT 等 AI 的模型上下文协议 (MCP)工具。
使用针对 GraphQL 后端的常规 GraphQL 查询/变异定义工具,gqai 会自动为您生成 MCP 服务器。

🔌 由您的 GraphQL 后端提供支持
⚙️ 由.graphqlrc.yml + 普通.graphql文件驱动


✨ 特点

  • 🧰 使用 GraphQL 操作定义工具

  • 🗂 自动从.graphqlrc.yml中发现操作

  • 🧾 与 OpenAI 函数调用 / MCP 兼容的工具元数据


Related MCP server: tavily-search

🛠️ 安装

go install github.com/fotoetienne/gqai@latest

🚀 快速入门

  1. 创建一个.graphqlrc.yml:

schema: https://graphql.org/graphql/
documents: .

该文件告诉 gqai 在哪里找到您的 GraphQL 模式和操作。

注意:

  1. 添加 GraphQL 操作

get_all_films.graphql

# Get all Star Wars films
query get_all_films {
  allFilms {
    films {
      title
      episodeID
    }
  }
}
  1. 将 gqai 添加到您的mcp.json文件中:

  "gqai": {
    "command": "gqai",
    "args": [
      "run",
      "--config"
      ".graphqlrc.yml"
    ]
  }

就这样!你的 AI 模型现在可以调用get_all_films工具了。

用法

配置

GraphQL 配置

graphql 配置文件是一个 YAML 文件,它定义了 GraphQL 端点以及你想要作为工具公开的操作。它应该被命名为.graphqlrc.yml并放置在项目的根目录中。

schema: https://graphql.org/graphql/
documents: operations

schema字段指定 GraphQL 端点, documents字段指定 GraphQL 操作所在的目录。

在此示例中, operations目录包含您想要作为工具公开的所有 GraphQL 操作。这些操作在.graphql文件中定义,gqai 会自动发现它们。

标题

您还可以指定每次向 GraphQL 端点发送请求时使用的标头。这对于身份验证或其他自定义标头非常有用。

schema:
  - https://graphql.org/graphql/:
      headers:
        Authorization: Bearer YOUR_TOKEN
        X-Custom-Header: CustomValue
documents: .

MCP 配置

克劳德桌面

要将 gqai 与 Claude Desktop 一起使用,您需要将以下配置添加到mcp.json文件中:

{
  "gqai": {
    "command": "gqai",
    "args": [
      "run",
      "--config",
      ".graphqlrc.yml"
    ]
  }
}

🧪 CLI 测试

通过 CLI 调用工具进行测试:

gqai tools/call get_all_films

这将执行get_all_films工具并打印结果。

{
  "data": {
    "allFilms": {
      "films": [
        {
          "id": 4,
          "title": "A New Hope"
        },
        {
          "id": 5,
          "title": "The Empire Strikes Back"
        },
        {
          "id": 6,
          "title": "Return of the Jedi"
        },
        ...
      ]
    }
  }
}

调用带参数的工具:

创建一个接受参数的 GraphQL 操作,这些将是工具输入:

get_film_by_id.graphql

query get_film_by_id($id: ID!) {
  film(filmID: $id) {
    episodeID
    title
    director
    releaseDate
  }
}

使用参数调用该工具:

gqai tools/call get_film_by_id '{"id": "1"}'

这将使用提供的参数执行get_film_by_id工具。

{
  "data": {
    "film": {
      "episodeID": 1,
      "title": "A New Hope",
      "director": "George Lucas",
      "releaseDate": "1977-05-25"
    }
  }
}

发展

先决条件

  • Go 1.20+

建造

go build -o gqai main.go

测试

go test ./...

格式

go fmt ./...

运行 MCP 服务器

./gqai run --config .graphqlrc.yml

运行 CLI

./gqai tools/call get_all_films

关于GQAI

🤖 为什么是 gqai?

gqai 可轻松将您的 GraphQL 后端转变为模型就绪的工具层——无需代码,无需额外基础设施。只需定义您的操作,然后让 AI 调用即可。

📜 许可证

MIT — 对其进行分叉,在此基础上进行构建,所有一切。

👋 作者

由 Stephen Spalding && <your-name-here>用 ❤️ 和 🤖 氛围制作

-
security - not tested
A
license - permissive license
-
quality - not tested

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/fotoetienne/gqai'

If you have feedback or need assistance with the MCP directory API, please join our Discord server