Skip to main content
Glama
husamabusafa

Advanced Hasura GraphQL MCP Server

by husamabusafa

run_graphql_mutation

Execute GraphQL mutations to insert, update, or delete data on Hasura GraphQL endpoints. Define the mutation string and optional variables for precise data manipulation.

Instructions

Executes a GraphQL mutation to insert, update, or delete data...

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
mutationYesThe GraphQL mutation string.
variablesNoOptional. An object containing variables...

Implementation Reference

  • src/index.ts:145-165 (registration)
    Registration of the 'run_graphql_mutation' tool with the MCP server, specifying name, description, input schema using Zod, and the handler function.
    server.tool(
      "run_graphql_mutation",
      "Executes a GraphQL mutation to insert, update, or delete data...",
      {
        mutation: z.string().describe("The GraphQL mutation string."),
        variables: z.record(z.unknown()).optional().describe("Optional. An object containing variables..."),
      },
      async ({ mutation, variables }) => {
        console.log(`[INFO] Executing tool 'run_graphql_mutation'`);
        if (!mutation.trim().toLowerCase().startsWith('mutation')) {
            throw new Error("The provided string does not appear to be a mutation...");
        }
        try {
          const result = await makeGqlRequest(mutation, variables);
          return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
        } catch (error: any) {
          console.error(`[ERROR] Tool 'run_graphql_mutation' failed: ${error.message}`);
          throw error;
        }
      }
    );
  • The core handler function that validates the mutation query, executes it via makeGqlRequest helper, returns formatted JSON result as MCP content, and propagates errors.
    async ({ mutation, variables }) => {
      console.log(`[INFO] Executing tool 'run_graphql_mutation'`);
      if (!mutation.trim().toLowerCase().startsWith('mutation')) {
          throw new Error("The provided string does not appear to be a mutation...");
      }
      try {
        const result = await makeGqlRequest(mutation, variables);
        return { content: [{ type: "text", text: JSON.stringify(result, null, 2) }] };
      } catch (error: any) {
        console.error(`[ERROR] Tool 'run_graphql_mutation' failed: ${error.message}`);
        throw error;
      }
    }
  • Input schema using Zod: required 'mutation' string parameter and optional 'variables' object for GraphQL variables.
    {
      mutation: z.string().describe("The GraphQL mutation string."),
      variables: z.record(z.unknown()).optional().describe("Optional. An object containing variables..."),
    },
  • Helper function to execute GraphQL requests with the configured gqlClient, merging headers, handling variables, and providing detailed error messages for GraphQL and client errors.
    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;
      }
    }
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 that the tool performs data modifications (insert, update, delete), which implies mutation operations, but fails to address critical aspects like authentication requirements, error handling, side effects, or response format. This leaves significant gaps for a tool that modifies data.

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

Conciseness4/5

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

The description is a single, efficient sentence that directly states the tool's function without unnecessary elaboration. It's appropriately sized for its purpose, though it could be slightly more structured by explicitly contrasting with the query sibling.

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 mutation tool with no annotations and no output schema, the description is insufficient. It doesn't explain what the tool returns, error conditions, or behavioral nuances, making it incomplete for safe and effective use by an AI agent.

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?

The schema description coverage is 100%, so the schema already documents both parameters ('mutation' and 'variables') adequately. The description adds no additional semantic context beyond what's in the schema, such as examples of mutation strings or variable usage, resulting in a baseline score.

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 tool's purpose as executing GraphQL mutations for data operations (insert, update, delete). It specifies the action ('executes') and resource ('GraphQL mutation'), though it doesn't explicitly differentiate from its sibling 'run_graphql_query' beyond the mutation vs query 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?

The description provides no guidance on when to use this tool versus alternatives like 'run_graphql_query' or other data manipulation tools. It lacks context about prerequisites, appropriate scenarios, or exclusions, leaving the agent to infer usage from the tool name alone.

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