GraphQL MCP Server
A generic MCP server that converts .graphql query files into tools for Claude, enabling interaction with any GraphQL API without coding.
README
GraphQL MCP Server
Turn any GraphQL API into Claude Code tools with zero coding
A generic Model Context Protocol (MCP) server that automatically converts your .graphql query files into tools Claude can use. Works with any GraphQL API - GitHub, Shopify, Hasura, or your own.
What It Does
- Point it at any GraphQL endpoint (GitHub, Shopify, Hasura, etc.)
- Drop
.graphqlquery files in a folder - Automatically exposes them as Claude Code tools
No MCP coding required - just write GraphQL queries and configure the endpoint.
Why Use This?
Token Savings
GraphQL lets you request only the fields you need, dramatically reducing response size:
| API Type | Response Size | Tokens Used | Savings |
|---|---|---|---|
| REST | 168 KB | ~42,000 | - |
| GraphQL (minimal) | 500 bytes | ~125 | 99.7% |
| GraphQL (targeted) | 5 KB | ~1,250 | 97% |
Convenience
Instead of writing custom MCP server code for each API, just:
- Configure the endpoint
- Write GraphQL queries
- Done
Installation
Clone and build from source:
git clone https://github.com/Chakit22/graphql-mcp-server.git
cd graphql-mcp-server
npm install
npm run build
Quick Start
1. Create a project directory
mkdir my-graphql-mcp
cd my-graphql-mcp
mkdir operations
2. Create config.json
{
"endpoint": "https://api.github.com/graphql",
"operationsDir": "./operations",
"headers": {
"Authorization": "Bearer YOUR_TOKEN_HERE"
},
"name": "my-mcp-server",
"version": "1.0.0"
}
3. Create GraphQL query files
Create operations/GetRepository.graphql:
# @description Get repository information
query GetRepository($owner: String!, $name: String!) {
repository(owner: $owner, name: $name) {
name
description
stargazerCount
url
}
}
4. Configure Claude Code
Add to ~/.config/claude-code/mcp_settings.json:
{
"mcpServers": {
"my-graphql-mcp": {
"command": "node",
"args": ["/path/to/graphql-mcp-server/dist/index.js"],
"env": {
"GRAPHQL_MCP_CONFIG": "/path/to/my-graphql-mcp/config.json"
}
}
}
}
5. Restart Claude Code
The MCP server will automatically load your GraphQL operations as tools.
Configuration Reference
config.json
| Field | Type | Required | Description |
|---|---|---|---|
endpoint |
string | Yes | GraphQL API endpoint URL |
operationsDir |
string | Yes | Path to directory containing .graphql files |
headers |
object | No | HTTP headers (e.g., Authorization) |
name |
string | No | MCP server name (default: "graphql-mcp-server") |
version |
string | No | MCP server version (default: "1.0.0") |
Environment Variables
GRAPHQL_MCP_CONFIG: Path to config file (default:./config.json)
Writing GraphQL Operations
Basic Query
# @description Brief description shown in Claude
query OperationName($param1: String!, $param2: Int) {
field1
field2
}
Features
@descriptioncomment: Appears in Claude's tool list- Variables: Automatically become tool parameters
- Type support: String, Int, Float, Boolean, ID, arrays
- Required params: Variables ending with
!are required
Example: Search Query
# @description Search repositories by keyword
query SearchRepos($query: String!, $limit: Int!) {
search(query: $query, type: REPOSITORY, first: $limit) {
repositoryCount
edges {
node {
... on Repository {
name
url
stargazerCount
}
}
}
}
}
Examples
SpaceX API (No Auth Required - Try This First!)
Perfect for testing - works immediately without API keys.
Config:
{
"endpoint": "https://spacex-production.up.railway.app/",
"operationsDir": "./operations",
"name": "spacex-mcp"
}
Available Operations:
GetRockets- Get all SpaceX rocketsGetLaunches- Get recent launches
📁 Full example: examples/spacex/
GitHub API
Config:
{
"endpoint": "https://api.github.com/graphql",
"operationsDir": "./operations",
"headers": {
"Authorization": "Bearer ghp_YOUR_TOKEN"
}
}
Available Operations:
GetRepository- Get repo detailsSearchRepositories- Search repos by keyword
📁 Full example: examples/github/
Shopify API
Config:
{
"endpoint": "https://YOUR_STORE.myshopify.com/admin/api/2024-01/graphql.json",
"operationsDir": "./operations",
"headers": {
"X-Shopify-Access-Token": "YOUR_TOKEN"
}
}
Available Operations:
GetProducts- Get products with pagination
📁 Full example: examples/shopify/
Hasura / Self-Hosted
Config:
{
"endpoint": "http://localhost:8080/v1/graphql",
"operationsDir": "./operations",
"headers": {
"x-hasura-admin-secret": "YOUR_SECRET"
}
}
How It Works
┌──────────┐ ┌──────────────┐ ┌────────────────┐
│ Claude │────▶│ MCP Server │────▶│ GraphQL API │
│ Code │ │ (this tool) │ │ (any endpoint) │
└──────────┘ └──────────────┘ └────────────────┘
│
▼
Loads *.graphql
from operations/
- MCP server reads all
.graphqlfiles fromoperationsDir - Registers each as a Claude Code tool
- When Claude calls a tool:
- Sends GraphQL query to configured endpoint
- Passes variables from Claude
- Returns response to Claude
Development
# Install dependencies
npm install
# Build TypeScript
npm run build
# Run in dev mode (with auto-reload)
npm run dev
# Run built version
npm start
Troubleshooting
"Configuration file not found"
- Check
GRAPHQL_MCP_CONFIGenvironment variable - Ensure
config.jsonexists in current directory or specified path
"No .graphql files found"
- Check
operationsDirpath in config - Ensure
.graphqlor.gqlfiles exist in that directory
"HTTP 401 Unauthorized"
- Check
headers.Authorizationin config - Verify your API token is valid
"GraphQL errors in response"
- Test your query directly against the API first
- Check variable types match the schema
- Verify required fields are present
Requirements
- Node.js 16+
- A GraphQL API endpoint
- Valid authentication credentials (if required by API)
License
MIT
Contributing
Contributions welcome! Please open an issue or PR.
Related Projects
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。