Skip to main content
Glama
husamabusafa

Advanced Hasura GraphQL MCP Server

by husamabusafa

run_graphql_query

Execute read-only GraphQL queries on a Hasura endpoint, providing a query string and optional variables to retrieve data efficiently.

Instructions

Executes a read-only GraphQL query against the Hasura endpoint...

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe GraphQL query string (must be a read-only operation).
variablesNoOptional. An object containing variables...

Implementation Reference

  • The main execution logic for the 'run_graphql_query' tool: logs execution, checks for mutation, executes the query using makeGqlRequest helper, returns formatted JSON result or throws error.
    async ({ query, variables }) => {
      console.log(`[INFO] Executing tool 'run_graphql_query'`);
      if (query.trim().toLowerCase().startsWith('mutation')) {
          throw new Error("This tool only supports read-only queries...");
      }
      try {
        const result = await makeGqlRequest(query, variables);
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      } catch (error: any) {
         console.error(`[ERROR] Tool 'run_graphql_query' failed: ${error.message}`);
         throw error;
      }
    }
  • Zod input schema defining the tool parameters: required 'query' (string) and optional 'variables' (object).
    {
      query: z.string().describe("The GraphQL query string (must be a read-only operation)."),
      variables: z.record(z.unknown()).optional().describe("Optional. An object containing variables..."),
    },
  • src/index.ts:123-143 (registration)
    The MCP server.tool() registration call for 'run_graphql_query', including description, input schema, and inline handler function.
    server.tool(
      "run_graphql_query",
      "Executes a read-only GraphQL query against the Hasura endpoint...",
      {
        query: z.string().describe("The GraphQL query string (must be a read-only operation)."),
        variables: z.record(z.unknown()).optional().describe("Optional. An object containing variables..."),
      },
      async ({ query, variables }) => {
        console.log(`[INFO] Executing tool 'run_graphql_query'`);
        if (query.trim().toLowerCase().startsWith('mutation')) {
            throw new Error("This tool only supports read-only queries...");
        }
        try {
          const result = await makeGqlRequest(query, variables);
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        } catch (error: any) {
           console.error(`[ERROR] Tool 'run_graphql_query' failed: ${error.message}`);
           throw error;
        }
      }
    );
  • Supporting utility function that performs the actual GraphQL request using GraphQLClient, merges headers (including admin secret), and handles ClientError with GraphQL-specific error messages.
    async function makeGqlRequest<
        T = any,
        V extends Record<string, any> = Record<string, any>
    >(
      query: string,
      variables?: V,
      requestHeaders?: Record<string, string>
    ): Promise<T> {
      try {
        const combinedHeaders = { ...headers, ...requestHeaders };
        return await gqlClient.request<T>(query, variables, combinedHeaders);
      } catch (error) {
        if (error instanceof ClientError) {
          const gqlErrors = error.response?.errors?.map(e => e.message).join(', ') || 'Unknown GraphQL error';
          console.error(`[ERROR] GraphQL Request Failed: ${gqlErrors}`, error.response);
          throw new Error(`GraphQL operation failed: ${gqlErrors}`);
        }
        console.error("[ERROR] Unexpected error during GraphQL request:", error);
        throw error;
      }
    }
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses the 'read-only' behavioral trait, which is crucial for safety, but lacks details on rate limits, authentication needs, error handling, or response format. The description adds some value but doesn't fully compensate for the missing annotations.

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 that front-loads key information ('Executes a read-only GraphQL query'). It wastes no words and clearly communicates the core purpose without unnecessary elaboration.

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

Completeness3/5

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

Given no annotations, no output schema, and a mutation sibling, the description is adequate but has clear gaps. It covers the read-only constraint and endpoint, but doesn't explain return values, error cases, or how it differs from 'run_graphql_mutation'. For a tool with behavioral complexity and sibling tools, more context would be helpful.

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 100%, so the schema already documents both parameters thoroughly. The description doesn't add any meaning beyond what's in the schema (e.g., no examples or constraints on query structure). Baseline 3 is appropriate when the schema does the heavy lifting.

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 'executes' and resource 'GraphQL query' with the specific constraint 'read-only' and target 'Hasura endpoint'. However, it doesn't explicitly distinguish this from its sibling 'run_graphql_mutation', which is a notable gap since both tools involve GraphQL operations against the same endpoint.

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

Usage Guidelines3/5

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

The description implies usage through the 'read-only' constraint, suggesting this tool is for queries rather than mutations, but it doesn't explicitly state when to use this vs. 'run_graphql_mutation' or other siblings like 'list_tables'. No explicit alternatives, exclusions, or prerequisites are mentioned.

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/husamabusafa/hasura_mcp'

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