Skip to content

Commit ce930ed

Browse files
blurrahclaude
andcommitted
feat: add GraphQL Config support for operation loading
Replace manual file discovery with standard GraphQL Config format: - Support .graphqlrc.{yml,json} and graphql.config.js files - Use 'documents' field with glob patterns for operation discovery - Add multi-project support with namespaced tool names - Map config fields to existing environment variables for compatibility - Maintain backward compatibility with GRAPHQL_DIR env var - Include example config files in multiple formats Benefits: - Standard format used by GraphQL ecosystem tools - Better IDE integration and validation capabilities - Environment variable interpolation support - Simplified configuration management Original introspect-schema and query-graphql tools remain unchanged. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
1 parent f432e45 commit ce930ed

File tree

8 files changed

+735
-17
lines changed

8 files changed

+735
-17
lines changed

.graphqlrc.example.json

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"schema": "http://localhost:4000/graphql",
3+
"documents": [
4+
"./graphql/**/*.graphql",
5+
"./graphql/**/*.gql"
6+
],
7+
"extensions": {
8+
"endpoints": {
9+
"default": {
10+
"url": "http://localhost:4000/graphql",
11+
"headers": {
12+
"Authorization": "Bearer ${API_TOKEN}",
13+
"Content-Type": "application/json"
14+
}
15+
}
16+
}
17+
}
18+
}

.graphqlrc.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# GraphQL Config for mcp-graphql
2+
# This file configures GraphQL operations and schema for the MCP server
3+
4+
# Schema location - can be:
5+
# - Local file: ./schema.graphql
6+
# - URL: https://api.example.com/graphql
7+
# - Introspection endpoint: http://localhost:4000/graphql
8+
schema: ${SCHEMA:-http://localhost:4000/graphql}
9+
10+
# Documents - GraphQL operations to load as MCP tools
11+
# Supports glob patterns
12+
documents:
13+
- './graphql/**/*.graphql'
14+
- './graphql/**/*.gql'
15+
- './operations/**/*.graphql'
16+
17+
# Extensions for additional configuration
18+
extensions:
19+
# Endpoint configuration
20+
endpoints:
21+
default:
22+
# GraphQL endpoint URL
23+
url: ${ENDPOINT:-http://localhost:4000/graphql}
24+
# Headers for requests (supports environment variables)
25+
headers:
26+
Authorization: Bearer ${API_TOKEN}
27+
Content-Type: application/json
28+
29+
# Multi-project example (commented out)
30+
# Uncomment to use multiple projects with different configurations
31+
# projects:
32+
# # Production API
33+
# production:
34+
# schema: https://api.example.com/graphql
35+
# documents: './graphql/production/**/*.graphql'
36+
# extensions:
37+
# endpoints:
38+
# default:
39+
# url: https://api.example.com/graphql
40+
# headers:
41+
# Authorization: Bearer ${PROD_TOKEN}
42+
#
43+
# # Development API
44+
# development:
45+
# schema: http://localhost:4000/graphql
46+
# documents: './graphql/dev/**/*.graphql'
47+
# extensions:
48+
# endpoints:
49+
# default:
50+
# url: http://localhost:4000/graphql
51+
# headers:
52+
# Authorization: Bearer ${DEV_TOKEN}

README.md

Lines changed: 91 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,42 @@ A Model Context Protocol server that enables LLMs to interact with GraphQL APIs.
88

99
## Usage
1010

11-
Run `mcp-graphql` with the correct endpoint, it will automatically try to introspect your queries.
11+
Run `mcp-graphql` with either a GraphQL Config file or environment variables. The server will automatically load your GraphQL operations as MCP tools.
1212

13-
### Environment Variables (Breaking change in 1.0.0)
13+
### Configuration Methods
1414

15-
> **Note:** As of version 1.0.0, command line arguments have been replaced with environment variables.
15+
The server supports two configuration methods (in priority order):
16+
17+
1. **GraphQL Config File** (Recommended) - Standard `.graphqlrc.yml`, `.graphqlrc.json`, or `graphql.config.js`
18+
2. **Environment Variables** - For backward compatibility and simple setups
19+
20+
### GraphQL Config (Recommended)
21+
22+
Create a `.graphqlrc.yml` file in your project root:
23+
24+
```yaml
25+
schema: http://localhost:4000/graphql
26+
documents:
27+
- './graphql/**/*.graphql'
28+
- './operations/**/*.gql'
29+
extensions:
30+
endpoints:
31+
default:
32+
url: http://localhost:4000/graphql
33+
headers:
34+
Authorization: Bearer ${API_TOKEN}
35+
```
36+
37+
Supported config formats:
38+
- `.graphqlrc.yml` / `.graphqlrc.yaml`
39+
- `.graphqlrc.json`
40+
- `graphql.config.js` / `graphql.config.ts`
41+
- `.graphqlrc` (JSON or YAML)
42+
- `package.json` (under `graphql` key)
43+
44+
### Environment Variables
45+
46+
> **Note:** Environment variables are used as fallbacks when GraphQL Config is not present.
1647

1748
| Environment Variable | Description | Default |
1849
|----------|-------------|---------|
@@ -41,8 +72,11 @@ ENDPOINT=http://localhost:3000/graphql SCHEMA=./schema.graphql npx mcp-graphql
4172
# Using a schema file hosted at a URL
4273
ENDPOINT=http://localhost:3000/graphql SCHEMA=https://example.com/schema.graphql npx mcp-graphql
4374
44-
# Using GraphQL files from a custom directory
75+
# Using GraphQL files from a custom directory (without config file)
4576
ENDPOINT=http://localhost:3000/graphql GRAPHQL_DIR=./my-queries npx mcp-graphql
77+
78+
# Using GraphQL Config file (recommended)
79+
npx mcp-graphql # Automatically loads .graphqlrc.yml or other config formats
4680
```
4781

4882
## Resources
@@ -60,6 +94,19 @@ This uses either the local schema file, a schema file hosted at a URL, or an int
6094

6195
3. **Dynamic tools from .graphql files**: Any GraphQL operations defined in `.graphql` or `.gql` files within the `GRAPHQL_DIR` directory are automatically registered as MCP tools. Tool names follow the pattern `gql-{operation-name}` (e.g., `gql-get-user`, `gql-create-post`).
6296

97+
## Migration from Environment Variables
98+
99+
To migrate from environment variables to GraphQL Config:
100+
101+
1. Create a `.graphqlrc.yml` file
102+
2. Map your environment variables:
103+
- `ENDPOINT` → `extensions.endpoints.default.url`
104+
- `HEADERS` → `extensions.endpoints.default.headers`
105+
- `SCHEMA` → `schema`
106+
- `GRAPHQL_DIR` → `documents` (as glob patterns)
107+
3. Remove `GRAPHQL_DIR` from your environment
108+
4. Keep other env vars as fallbacks or use `${ENV_VAR}` in config
109+
63110
## Installation
64111

65112
### Installing via Smithery
@@ -87,15 +134,51 @@ It can be manually installed to Claude:
87134
}
88135
```
89136

90-
## GraphQL File Support
137+
## GraphQL Config Support
138+
139+
The server now supports [GraphQL Config](https://graphql-config.com/), the standard configuration format used by GraphQL tools. This provides:
91140

92-
You can define GraphQL operations in `.graphql` or `.gql` files, and they will be automatically registered as MCP tools. This allows you to:
141+
- **Standard format**: Works with existing GraphQL tooling (VSCode, GraphQL Playground, etc.)
142+
- **Documents field**: Define operation files using glob patterns
143+
- **Multi-project support**: Different configurations for different environments
144+
- **Environment interpolation**: Use `${ENV_VAR}` in config values
145+
- **Schema validation**: Validate operations against your schema
146+
147+
### Benefits of GraphQL Config
93148

94149
- Version control your GraphQL operations
150+
- Share configuration across tools (IDEs, linters, code generators)
95151
- Organize operations by type or domain
96-
- Reuse common queries across different contexts
97152
- Type-check operations against your schema
98153

154+
### Multi-Project Configuration
155+
156+
Support multiple GraphQL APIs in a single configuration:
157+
158+
```yaml
159+
# .graphqlrc.yml
160+
projects:
161+
production:
162+
schema: https://api.example.com/graphql
163+
documents: './graphql/production/**/*.graphql'
164+
extensions:
165+
endpoints:
166+
default:
167+
url: https://api.example.com/graphql
168+
headers:
169+
Authorization: Bearer ${PROD_TOKEN}
170+
171+
development:
172+
schema: http://localhost:4000/graphql
173+
documents: './graphql/dev/**/*.graphql'
174+
extensions:
175+
endpoints:
176+
default:
177+
url: http://localhost:4000/graphql
178+
```
179+
180+
Tools from multi-project configs are named: `gql-{project}-{operation}`
181+
99182
### File Structure Example
100183

101184
```
@@ -129,6 +212,7 @@ This operation will be available as the `gql-get-user` tool, accepting an `id` p
129212

130213
- Operations with explicit names use that name (e.g., `query GetUser``gql-get-user`)
131214
- Operations without names use the filename (e.g., `userProfile.graphql``gql-user-profile`)
215+
- Multi-project operations include project name (e.g., `gql-production-get-user`)
132216
- Names are converted to kebab-case for consistency
133217

134218
## Security Considerations

0 commit comments

Comments
 (0)