Skip to main content
Glama
FabrWill

GraphQL MCP Server

by FabrWill

query

Execute GraphQL queries with specified variables to retrieve or modify data from GraphQL APIs through the MCP server.

Instructions

Query a GraphQL endpoint with the given query and variables

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes
variablesNo

Implementation Reference

  • The main execution logic for the 'query' tool: validates and parses the GraphQL query, blocks mutations unless allowed, performs a POST fetch to the GraphQL endpoint, handles parsing/network/GraphQL errors, and returns formatted JSON response or error messages.
    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()) as any;
    
        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}`);
      }
    }
  • Zod input schema defining 'query' as a required string and 'variables' as an optional string.
    {
      query: z.string(),
      variables: z.string().optional(),
    },
  • src/index.ts:115-117 (registration)
    Registers the 'query' tool on the MCP server with its name, description, input schema, and handler function.
    server.tool(
      "query",
      "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 states the tool queries a GraphQL endpoint but lacks critical details: authentication requirements, rate limits, error handling, response format, or whether it's read-only or mutative. This leaves significant gaps for an agent to understand operational 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 front-loads the core purpose ('Query a GraphQL endpoint') and succinctly specifies inputs, making it easy to parse and understand quickly 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 a GraphQL query tool with 2 parameters, 0% schema coverage, no annotations, and no output schema, the description is incomplete. It lacks details on authentication, error handling, response structure, and usage distinctions from siblings, leaving the agent under-informed for reliable tool invocation.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate. It mentions 'query' and 'variables' as inputs, aligning with the schema's two parameters, but adds no semantic context—such as what constitutes a valid GraphQL query, how variables should be formatted (e.g., JSON string), or examples. This minimal addition fails to adequately clarify parameter usage beyond naming them.

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 action ('Query') and target ('a GraphQL endpoint'), specifying the required inputs ('with the given query and variables'). It distinguishes from sibling tools 'inspect' and 'introspect' by focusing on execution rather than schema exploration. However, it doesn't explicitly contrast with those siblings, preventing a perfect score.

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 the sibling tools 'inspect' or 'introspect'. The description implies usage for executing GraphQL queries but offers no context about alternatives, prerequisites, or constraints, leaving the agent to infer appropriate usage scenarios.

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

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/FabrWill/gql-mcp'

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