Skip to main content
Glama
ttpears

GitLab MCP Server

by ttpears

Custom GraphQL Query

execute_custom_query

Execute custom GraphQL queries to filter GitLab issues, merge requests, and other data by assignee, author, labels, or other criteria when standard search tools return no results.

Instructions

Execute custom GraphQL queries for complex filtering (e.g., issues with assigneeUsernames: ["user"], labelName: ["bug"]). Use this for structured filtering by assignee/author/labels when search tools return 0 results. Use pagination and limit complexity to avoid timeouts.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesGraphQL query string. Example: query { issues(assigneeUsernames: ["cdhanlon"], state: opened, first: 50) { nodes { iid title webUrl } } }
variablesNoVariables for the GraphQL query
requiresWriteNoSet to true if this is a mutation that requires write permissions
userCredentialsNoYour GitLab credentials (optional - uses shared token if not provided)

Implementation Reference

  • Handler function that executes the custom GraphQL query. It validates user credentials, checks if write operations require authentication, and calls the client.query() method with the provided query string, variables, credentials, and write flag.
    handler: async (input, client, userConfig) => {
      const credentials = input.userCredentials ? validateUserConfig(input.userCredentials) : userConfig;
      if (input.requiresWrite && !credentials) {
        throw new Error('User authentication is required for write operations. Please provide your GitLab credentials.');
      }
      return await client.query(input.query, input.variables, credentials, input.requiresWrite);
    },
  • Complete tool definition including input schema with user authentication support. Defines the tool name 'execute_custom_query', description, input schema (query string, optional variables, requiresWrite flag), and handler.
    const executeCustomQueryTool: Tool = {
      name: 'execute_custom_query',
      title: 'Custom GraphQL Query',
      description: 'Execute custom GraphQL queries for complex filtering (e.g., issues with assigneeUsernames: ["user"], labelName: ["bug"]). Use this for structured filtering by assignee/author/labels when search tools return 0 results. Use pagination and limit complexity to avoid timeouts.',
      requiresAuth: false,
      requiresWrite: false,
      annotations: {
        readOnlyHint: false,
        destructiveHint: false,
        idempotentHint: false,
      },
      inputSchema: withUserAuth(z.object({
        query: z.string().describe('GraphQL query string. Example: query { issues(assigneeUsernames: ["cdhanlon"], state: opened, first: 50) { nodes { iid title webUrl } } }'),
        variables: z.record(z.any()).optional().describe('Variables for the GraphQL query'),
        requiresWrite: z.boolean().default(false).describe('Set to true if this is a mutation that requires write permissions'),
      })),
      handler: async (input, client, userConfig) => {
        const credentials = input.userCredentials ? validateUserConfig(input.userCredentials) : userConfig;
        if (input.requiresWrite && !credentials) {
          throw new Error('User authentication is required for write operations. Please provide your GitLab credentials.');
        }
        return await client.query(input.query, input.variables, credentials, input.requiresWrite);
      },
    };
  • src/tools.ts:1294-1310 (registration)
    The tool is registered in the readOnlyTools export array, which makes it available as a read-only tool in the MCP server.
    export const readOnlyTools: Tool[] = [
      getProjectTool,
      getIssuesTool,
      getMergeRequestsTool,
      executeCustomQueryTool,
      getAvailableQueriesTools,
      getMergeRequestPipelinesTool,
      getPipelineJobsTool,
      getMergeRequestDiffsTool,
      getMergeRequestCommitsTool,
      getNotesTool,
      listMilestonesTool,
      listIterationsTool,
      getTimeTrackingTool,
      getMergeRequestReviewersTool,
      getProjectStatisticsTool,
    ];
  • src/tools.ts:1339-1349 (registration)
    The tool is also included in the main tools export array that aggregates all tool categories (readOnlyTools, userAuthTools, writeTools, and searchTools).
    export const tools: Tool[] = [
      ...readOnlyTools,
      ...userAuthTools,
      ...writeTools,
      updateIssueTool,
      updateMergeRequestTool,
      resolvePathTool,
      getGroupProjectsTool,
      getTypeFieldsTool,
      ...searchTools,
    ];
  • The client.query method that actually executes GraphQL queries with retry logic. It gets the appropriate GraphQL client (user-specific or shared) and executes the query with exponential backoff retry for reliability.
    async query<T = any>(query: string, variables?: any, userConfig?: UserConfig, requiresWrite = false): Promise<T> {
      const client = this.getClient(userConfig, requiresWrite);
      return this.executeWithRetry(
        () => client.request<T>(query, variables),
        'GraphQL query'
      );
    }
Behavior4/5

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

The description adds valuable behavioral context beyond annotations: it warns about timeouts and recommends limiting complexity, mentions pagination requirements, and explains the fallback use case when search tools fail. While annotations cover basic safety (readOnlyHint: false, destructiveHint: false), the description provides practical operational guidance that helps the agent use the tool effectively.

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 efficiently structured in three sentences: purpose statement with examples, usage guidelines with alternatives, and operational warnings. Every sentence adds value with zero wasted words, making it easy for an agent to parse quickly.

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

Completeness4/5

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

For a complex GraphQL execution tool with no output schema, the description provides good context about when to use it, operational constraints, and relationship to other tools. It could be more complete by mentioning authentication requirements or response format, but given the rich schema coverage and clear purpose/guidelines, it's mostly adequate.

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?

With 100% schema description coverage, the schema already documents all parameters thoroughly. The description doesn't add significant parameter semantics beyond what's in the schema, though it provides example query syntax that illustrates how parameters work together. This meets the baseline for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/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 'Execute custom GraphQL queries for complex filtering' with specific examples like filtering by assignee/author/labels. It distinguishes itself from siblings like search_issues and search_gitlab by emphasizing complex filtering capabilities when standard search tools return 0 results.

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

Usage Guidelines5/5

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

The description provides explicit guidance on when to use this tool ('when search tools return 0 results') and when not to use it (implied: for simple queries, use standard search tools). It mentions specific use cases like structured filtering by assignee/author/labels and warns about complexity/timeout trade-offs.

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

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