Skip to main content
Glama
ttpears

GitLab MCP Server

by ttpears

get_available_queries

Retrieve available GraphQL queries and mutations from a GitLab schema to understand what operations are supported for API interaction.

Instructions

Get list of available GraphQL queries and mutations from the GitLab schema

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
userCredentialsNoYour GitLab credentials (optional - uses shared token if not provided)

Implementation Reference

  • Tool definition for 'get_available_queries' - defines the tool metadata, input schema (empty object with optional user credentials), and handler function that calls the GitLab client to introspect the schema and return available queries and mutations
    const getAvailableQueriesTools: Tool = {
      name: 'get_available_queries',
      title: 'Available Queries',
      description: 'Get list of available GraphQL queries and mutations from the GitLab schema',
      requiresAuth: false,
      requiresWrite: false,
      annotations: {
        readOnlyHint: true,
        destructiveHint: false,
        idempotentHint: true,
      },
      inputSchema: withUserAuth(z.object({}).strict()),
      handler: async (input, client, userConfig) => {
        const credentials = input.userCredentials ? validateUserConfig(input.userCredentials) : userConfig;
        await client.introspectSchema(credentials);
        return {
          queries: client.getAvailableQueries(),
          mutations: client.getAvailableMutations(),
        };
      },
    };
  • Implementation of getAvailableQueries() and getAvailableMutations() methods that retrieve field names from the introspected GraphQL schema's Query and Mutation types
    getAvailableQueries(): string[] {
      if (!this.schema) return [];
      
      const queryType = this.schema.getQueryType();
      if (!queryType) return [];
      
      return Object.keys(queryType.getFields());
    }
    
    getAvailableMutations(): string[] {
      if (!this.schema) return [];
      
      const mutationType = this.schema.getMutationType();
      if (!mutationType) return [];
      
      return Object.keys(mutationType.getFields());
    }
  • The introspectSchema() method that fetches and builds the GitLab GraphQL schema using GraphQL introspection query, storing it in this.schema for later use by getAvailableQueries() and getAvailableMutations()
    async introspectSchema(userConfig?: UserConfig): Promise<void> {
      if (this.schema) return;
    
      try {
        const client = this.getClient(userConfig);
        const introspectionResult = await client.request<IntrospectionQuery>(
          getIntrospectionQuery()
        );
        this.schema = buildClientSchema(introspectionResult);
      } catch (error) {
        throw new Error(`Failed to introspect GitLab GraphQL schema: ${error}`);
      }
    }
  • src/tools.ts:1294-1310 (registration)
    Tool registration - getAvailableQueriesTools is exported as part of readOnlyTools array, which is then included in the main tools array that gets registered with the MCP server
    export const readOnlyTools: Tool[] = [
      getProjectTool,
      getIssuesTool,
      getMergeRequestsTool,
      executeCustomQueryTool,
      getAvailableQueriesTools,
      getMergeRequestPipelinesTool,
      getPipelineJobsTool,
      getMergeRequestDiffsTool,
      getMergeRequestCommitsTool,
      getNotesTool,
      listMilestonesTool,
      listIterationsTool,
      getTimeTrackingTool,
      getMergeRequestReviewersTool,
      getProjectStatisticsTool,
    ];
  • Input schema definition - uses withUserAuth helper to create an empty object schema that optionally accepts user credentials for authentication
    inputSchema: withUserAuth(z.object({}).strict()),

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/ttpears/gitlab-mcp'

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