Skip to main content
Glama
blurrah

mcp-graphql

query-graphql

Execute GraphQL queries with specified variables and headers using a configurable endpoint. Simplifies interaction with GraphQL servers for data retrieval and manipulation.

Instructions

Query a GraphQL endpoint with the given query and variables

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
endpointNoOptional: Override the default endpoint, the already used endpoint is: http://localhost:3000/graphql
headersNoOptional: Add additional headers, the already used headers are: {}
queryYes
variablesNo

Implementation Reference

  • Executes the GraphQL query: parses the query to check for mutations (disabled by default), sends a POST request to the configured endpoint with query and variables, handles HTTP/GraphQL errors, and returns formatted JSON response.
    async ({ query, variables }) => {
    	try {
    		const parsedQuery = parse(query);
    
    		// Check if the query is a mutation
    		const isMutation = parsedQuery.definitions.some(
    			(def) =>
    				def.kind === "OperationDefinition" && def.operation === "mutation",
    		);
    
    		if (isMutation && !env.ALLOW_MUTATIONS) {
    			return {
    				isError: true,
    				content: [
    					{
    						type: "text",
    						text: "Mutations are not allowed unless you enable them in the configuration. Please use a query operation instead.",
    					},
    				],
    			};
    		}
    	} catch (error) {
    		return {
    			isError: true,
    			content: [
    				{
    					type: "text",
    					text: `Invalid GraphQL query: ${error}`,
    				},
    			],
    		};
    	}
    
    	try {
    		const response = await fetch(env.ENDPOINT, {
    			method: "POST",
    			headers: {
    				"Content-Type": "application/json",
    				...env.HEADERS,
    			},
    			body: JSON.stringify({
    				query,
    				variables,
    			}),
    		});
    
    		if (!response.ok) {
    			const responseText = await response.text();
    
    			return {
    				isError: true,
    				content: [
    					{
    						type: "text",
    						text: `GraphQL request failed: ${response.statusText}\n${responseText}`,
    					},
    				],
    			};
    		}
    
    		const data = await response.json();
    
    		if (data.errors && data.errors.length > 0) {
    			// Contains GraphQL errors
    			return {
    				isError: true,
    				content: [
    					{
    						type: "text",
    						text: `The GraphQL response has errors, please fix the query: ${JSON.stringify(
    							data,
    							null,
    							2,
    						)}`,
    					},
    				],
    			};
    		}
    
    		return {
    			content: [
    				{
    					type: "text",
    					text: JSON.stringify(data, null, 2),
    				},
    			],
    		};
    	} catch (error) {
    		throw new Error(`Failed to execute GraphQL query: ${error}`);
    	}
    },
  • Input schema using Zod: 'query' (required string) and 'variables' (optional string).
    {
    	query: z.string(),
    	variables: z.string().optional(),
    },
  • src/index.ts:117-119 (registration)
    Registers the 'query-graphql' tool with McpServer.tool(), providing name, description, input schema, and handler function.
    server.tool(
    	"query-graphql",
    	"Query a GraphQL endpoint with the given query and variables",
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the action but lacks details on permissions, rate limits, error handling, or response format. This is inadequate for a tool that interacts with an external endpoint, leaving significant gaps in understanding its behavior.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence with zero waste. It is appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of querying a GraphQL endpoint, no annotations, no output schema, and incomplete parameter documentation, the description is insufficient. It fails to address critical aspects like authentication, response structure, or error scenarios, making it incomplete for effective tool use.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 50% (2 out of 4 parameters have descriptions). The description adds minimal value beyond the schema, as it only mentions 'query and variables' without explaining their formats or relationships. It doesn't compensate for the undocumented parameters (query and variables lack schema descriptions), resulting in a baseline score due to partial coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb ('Query') and resource ('a GraphQL endpoint'), specifying what the tool does. It distinguishes from the sibling 'introspect-schema' by focusing on general query execution rather than schema introspection, though it doesn't explicitly mention this distinction.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus alternatives. The description doesn't mention the sibling tool 'introspect-schema' or any other context for selection. It simply states the action without usage context.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

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/blurrah/mcp-graphql'

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