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'...")
    },
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