MCP server for text-to-graphql, integrates with Claude Desktop and Cursor.
Transform natural language queries into GraphQL queries using an MCP (Model Context Protocol) server that integrates seamlessly with AI assistants like Claude Desktop and Cursor.
The Text-to-GraphQL MCP Server converts natural language descriptions into valid GraphQL queries using an AI agent built with LangGraph. It provides a bridge between human language and GraphQL APIs, making database and API interactions more intuitive for developers and non-technical users alike.
UV is a fast Python package installer and resolver. Install it first:
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Windows:
powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
Find your UV installation path:
# Find where uv is installed
which uv
# Common locations:
# macOS/Linux: ~/.local/bin/uv
# Windows: %APPDATA%\uv\bin\uv.exe
Important: You'll need the UV path for MCP configuration. The typical path is
~/.local/bin
on macOS/Linux, which translates to/Users/yourusername/.local/bin
(replaceyourusername
with your actual username).
# Clone the repository
git clone https://github.com/yourusername/text-to-graphql-mcp.git
cd text-to-graphql-mcp
# Install dependencies (UV automatically creates virtual environment)
uv sync
# Test the installation
uv run text-to-graphql-mcp --help
Note: The
uv run
pattern automatically handles virtual environments, making MCP configuration cleaner and more reliable than traditional pip installations.
From PyPI (when published):
pip install text-to-graphql-mcp
Development Setup:
# For contributing to the project
uv sync --dev
Add to your .cursor/mcp.json
:
{
"text-to-graphql": {
"command": "uv",
"args": [
"--directory",
"/path/to/text-to-graphql-mcp",
"run",
"text-to-graphql-mcp"
],
"env": {
"PATH": "/path/to/uv/bin:/usr/bin:/bin",
"OPENAI_API_KEY": "your_openai_api_key_here",
"GRAPHQL_ENDPOINT": "https://your-graphql-api.com/graphql",
"GRAPHQL_API_KEY": "your_api_key_here",
"GRAPHQL_AUTH_TYPE": "bearer"
}
}
}
Important Setup Notes:
- Replace
/path/to/text-to-graphql-mcp
with the actual path to your cloned repository- Replace
/path/to/uv/bin
with your actual UV installation path (typically/Users/yourusername/.local/bin
on macOS)- The
PATH
environment variable is required for MCP clients to find theuv
command
Add to your Claude Desktop MCP configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"text-to-graphql": {
"command": "uv",
"args": [
"--directory",
"/path/to/text-to-graphql-mcp",
"run",
"text-to-graphql-mcp"
],
"env": {
"PATH": "/path/to/uv/bin:/usr/bin:/bin",
"OPENAI_API_KEY": "your_openai_api_key_here",
"GRAPHQL_ENDPOINT": "https://your-graphql-api.com/graphql",
"GRAPHQL_API_KEY": "your_api_key_here",
"GRAPHQL_AUTH_TYPE": "bearer"
}
}
}
}
Setup Instructions:
- Find your UV path: Run
which uv
in terminal (typically/Users/yourusername/.local/bin/uv
)- Set the PATH: Use the directory containing
uv
(e.g.,/Users/yourusername/.local/bin
)- Replace paths: Update both the
--directory
argument andPATH
environment variable with your actual paths- Add your API keys: Replace the placeholder values with your actual API keys
# Find your UV installation
which uv
# Common paths by OS:
# macOS: /Users/yourusername/.local/bin/uv
# Linux: /home/yourusername/.local/bin/uv
# Windows: C:\Users\yourusername\AppData\Roaming\uv\bin\uv.exe
# For MCP config, use the directory path:
# macOS: /Users/yourusername/.local/bin
# Linux: /home/yourusername/.local/bin
# Windows: C:\Users\yourusername\AppData\Roaming\uv\bin
If you prefer using a .env
file (useful for local development):
# Required
OPENAI_API_KEY=your_openai_api_key_here
GRAPHQL_ENDPOINT=https://your-graphql-api.com/graphql
GRAPHQL_API_KEY=your_api_key_here
# Optional - Authentication method (bearer|apikey|direct)
GRAPHQL_AUTH_TYPE=bearer
# Optional - Model settings
MODEL_NAME=gpt-4o
MODEL_TEMPERATURE=0
Then use a simplified MCP configuration (still requires PATH):
{
"text-to-graphql": {
"command": "uv",
"args": [
"--directory",
"/path/to/text-to-graphql-mcp",
"run",
"text-to-graphql-mcp"
],
"env": {
"PATH": "/path/to/uv/bin:/usr/bin:/bin"
}
}
}
# Run the server directly for testing
text-to-graphql-mcp
# Or run as a module
python -m text_to_graphql_mcp.mcp_server
generate_graphql_query
Convert natural language to GraphQL queries.
Input: "Get all users with their names and emails"
Output: query { users { id name email } }
validate_graphql_query
Validate GraphQL queries against the loaded schema.
execute_graphql_query
Execute GraphQL queries and return formatted results.
get_query_history
Retrieve the history of all queries in the current session.
get_query_examples
Get example queries to understand the system's capabilities.
Natural Language Input:
"Show me all blog posts from the last week with their authors and comment counts"
Generated GraphQL:
query {
posts(where: { createdAt: { gte: "2024-06-05T00:00:00Z" } }) {
id
title
content
createdAt
author {
id
name
email
}
comments {
id
}
_count {
comments
}
}
}
The system uses a multi-agent architecture built with LangGraph:
Variable | Description | Default |
---|---|---|
OPENAI_API_KEY | OpenAI API key for LLM operations | Required |
GRAPHQL_ENDPOINT | GraphQL API endpoint URL | Required |
GRAPHQL_API_KEY | API key for your GraphQL service | Required |
GRAPHQL_AUTH_TYPE | Authentication method: bearer , apikey , or direct | bearer |
GRAPHQL_HEADERS | Custom headers as JSON (overrides auto-auth) | {} |
MODEL_NAME | OpenAI model to use | gpt-4o |
MODEL_TEMPERATURE | Model temperature for responses | 0 |
API_HOST | Server host address | 127.0.0.1 |
API_PORT | Server port | 8000 |
RECURSION_LIMIT | Max recursion for agent workflow | 10 |
bearer
(default): Uses Authorization: Bearer <token>
- standard for most GraphQL APIsapikey
: Uses X-API-Key: <key>
- used by some APIs like Arizedirect
: Uses Authorization: <token>
- direct token without Bearer prefixGRAPHQL_HEADERS
to override with any custom authentication formatGitHub GraphQL API:
GRAPHQL_ENDPOINT=https://api.github.com/graphql
GRAPHQL_API_KEY=ghp_your_github_personal_access_token
GRAPHQL_AUTH_TYPE=bearer
Shopify GraphQL API:
GRAPHQL_ENDPOINT=https://your-shop.myshopify.com/admin/api/2023-10/graphql.json
GRAPHQL_API_KEY=your_shopify_access_token
GRAPHQL_AUTH_TYPE=bearer
Arize GraphQL API:
GRAPHQL_ENDPOINT=https://app.arize.com/graphql
GRAPHQL_API_KEY=your_arize_developer_api_key
# Auth type auto-detected for Arize
Hasura:
GRAPHQL_ENDPOINT=https://your-app.hasura.app/v1/graphql
GRAPHQL_HEADERS={"x-hasura-admin-secret": "your_admin_secret"}
Want to build better AI agents quickly? Check out Arize Phoenix - an open-source observability platform specifically designed for LLM applications and agents. Phoenix provides:
Phoenix integrates seamlessly with LangChain and LangGraph (which this project uses) and can help you:
Get started with Phoenix:
pip install arize-phoenix
phoenix serve
Visit docs.arize.com/phoenix for comprehensive guides on agent observability and development best practices.
# Install development dependencies
uv pip install -e ".[dev]"
# Run tests
pytest
# Format code
black .
isort .
# Type checking
mypy src/
text-to-graphql-mcp/
βββ src/text_to_graphql_mcp/ # Main package
β βββ mcp_server.py # MCP server implementation
β βββ agent.py # LangGraph agent logic
β βββ config.py # Configuration management
β βββ logger.py # Logging utilities
β βββ tools/ # Agent tools
β βββ ...
βββ tests/ # Test suite
βββ docs/ # Documentation
βββ pyproject.toml # Package configuration
βββ README.md
We welcome contributions! Please see our contributing guidelines for details.
git checkout -b feature/amazing-feature
)git commit -m 'Add some amazing feature'
)git push origin feature/amazing-feature
)This project is licensed under the Elastic License 2.0 (ELv2) - see the LICENSE file for details.
"No module named 'text_to_graphql_mcp'"
pip install text-to-graphql-mcp
"OpenAI API key not found"
OPENAI_API_KEY
environment variable.env
file configuration"GraphQL endpoint not reachable"
GRAPHQL_ENDPOINT
URL"Schema introspection failed"
Reference / test server with prompts, resources, and tools
Create crafted UI components inspired by the best 21st.dev design engineers.
ALAPI MCP Tools,Call hundreds of API interfaces via MCP
AI-powered SVG animation generator that transforms static files into animated SVG components using the Allyson platform
APIMatic MCP Server is used to validate OpenAPI specifications using APIMatic. The server processes OpenAPI files and returns validation summaries by leveraging APIMaticβs API.
Enable AI agents to interact with the Atla API for state-of-the-art LLMJ evaluation.
Generate images using Amazon Nova Canvas with text prompts and color guidance.
Bring the full power of BrowserStackβs Test Platform to your AI tools, making testing faster and easier for every developer and tester on your team.
Flag features, manage company data, and control feature access using Bucket.
Official MCP server for Buildable AI-powered development platform. Enables AI assistants to manage tasks, track progress, get project context, and collaborate with humans on software projects.