Skip to main content
Glama
husamabusafa

Advanced Hasura GraphQL MCP Server

by husamabusafa

list_root_fields

Retrieve available top-level query, mutation, or subscription fields for a Hasura GraphQL endpoint to enable schema discovery and dynamic interaction with the API.

Instructions

Lists the available top-level query, mutation, or subscription fields...

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
fieldTypeNoOptional. Filter by 'QUERY'...

Implementation Reference

  • src/index.ts:247-280 (registration)
    Registers the MCP tool 'list_root_fields' with description, input schema, and handler function.
    server.tool(
      "list_root_fields",
      "Lists the available top-level query, mutation, or subscription fields...",
      {
        fieldType: z.enum(["QUERY", "MUTATION", "SUBSCRIPTION"]).optional().describe("Optional. Filter by 'QUERY'...")
      },
      async ({ fieldType }) => {
        console.log(`[INFO] Executing tool 'list_root_fields', filtering by: ${fieldType || 'ALL'}`);
        try {
          const schema = await getIntrospectionSchema();
          let fields: IntrospectionField[] = [];
          if ((!fieldType || fieldType === "QUERY") && schema.queryType) {
              const queryRoot = schema.types.find(t => t.name === schema.queryType?.name) as IntrospectionObjectType | undefined;
              fields = fields.concat(queryRoot?.fields || []);
          }
          if ((!fieldType || fieldType === "MUTATION") && schema.mutationType) {
              const mutationRoot = schema.types.find(t => t.name === schema.mutationType?.name) as IntrospectionObjectType | undefined;
              fields = fields.concat(mutationRoot?.fields || []);
          }
          if ((!fieldType || fieldType === "SUBSCRIPTION") && schema.subscriptionType) {
              const subscriptionRoot = schema.types.find(t => t.name === schema.subscriptionType?.name) as IntrospectionObjectType | undefined;
              fields = fields.concat(subscriptionRoot?.fields || []);
          }
          const fieldInfo = fields.map(f => ({
              name: f.name,
              description: f.description || "No description.",
          })).sort((a, b) => a.name.localeCompare(b.name));
          return { content: [{ type: "text", text: JSON.stringify(fieldInfo, null, 2) }] };
        } catch (error: any) {
          console.error(`[ERROR] Tool 'list_root_fields' failed: ${error.message}`);
          throw error;
        }
      }
    );
  • Executes the tool by fetching the GraphQL introspection schema, collecting fields from query/mutation/subscription root types based on optional fieldType filter, formats name and description, sorts, and returns as JSON.
    async ({ fieldType }) => {
      console.log(`[INFO] Executing tool 'list_root_fields', filtering by: ${fieldType || 'ALL'}`);
      try {
        const schema = await getIntrospectionSchema();
        let fields: IntrospectionField[] = [];
        if ((!fieldType || fieldType === "QUERY") && schema.queryType) {
            const queryRoot = schema.types.find(t => t.name === schema.queryType?.name) as IntrospectionObjectType | undefined;
            fields = fields.concat(queryRoot?.fields || []);
        }
        if ((!fieldType || fieldType === "MUTATION") && schema.mutationType) {
            const mutationRoot = schema.types.find(t => t.name === schema.mutationType?.name) as IntrospectionObjectType | undefined;
            fields = fields.concat(mutationRoot?.fields || []);
        }
        if ((!fieldType || fieldType === "SUBSCRIPTION") && schema.subscriptionType) {
            const subscriptionRoot = schema.types.find(t => t.name === schema.subscriptionType?.name) as IntrospectionObjectType | undefined;
            fields = fields.concat(subscriptionRoot?.fields || []);
        }
        const fieldInfo = fields.map(f => ({
            name: f.name,
            description: f.description || "No description.",
        })).sort((a, b) => a.name.localeCompare(b.name));
        return { content: [{ type: "text", text: JSON.stringify(fieldInfo, null, 2) }] };
      } catch (error: any) {
        console.error(`[ERROR] Tool 'list_root_fields' failed: ${error.message}`);
        throw error;
      }
    }
  • Zod schema for input parameters: optional 'fieldType' enum to filter by QUERY, MUTATION, or SUBSCRIPTION.
    {
      fieldType: z.enum(["QUERY", "MUTATION", "SUBSCRIPTION"]).optional().describe("Optional. Filter by 'QUERY'...")
    },
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions listing fields but doesn't disclose behavioral traits such as whether this is a read-only operation, if it requires authentication, rate limits, or what the output format looks like (e.g., list of strings, structured data). This is a significant gap for a tool with zero annotation coverage.

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 directly states the tool's purpose without unnecessary words. It is appropriately sized and front-loaded, making it easy to parse quickly.

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 GraphQL operations and lack of annotations or output schema, the description is incomplete. It doesn't explain what 'available' means (e.g., based on permissions), how results are returned, or provide context for the sibling tools, leaving gaps in understanding the tool's full behavior.

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 the single optional parameter 'fieldType' with its enum values. The description implies filtering by field type but doesn't add any syntax, format, or usage details beyond what the schema provides, resulting in a baseline score of 3.

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 ('Lists') and the resource ('available top-level query, mutation, or subscription fields'), making the purpose understandable. However, it doesn't explicitly differentiate from siblings like 'describe_graphql_type' or 'run_graphql_query', which might also involve GraphQL operations, so it misses full sibling 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. It doesn't mention scenarios like exploring GraphQL schema, comparing to 'describe_graphql_type' for detailed field info, or using 'run_graphql_query' for actual queries, leaving the agent with no 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/husamabusafa/hasura_mcp'

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