Skip to main content
Glama

gitlab_get_pipeline_jobs

Retrieve jobs from a specific GitLab pipeline to monitor execution status and identify issues in CI/CD workflows.

Instructions

Gets jobs for a specific pipeline.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
projectPathYesThe path of the GitLab project.
pipelineIdYesThe ID of the pipeline.

Implementation Reference

  • The core handler function implementing the gitlab_get_pipeline_jobs tool. It encodes the project path and calls the GitLab API to retrieve the list of jobs for the specified pipeline.
    async getPipelineJobs(projectPath: string, pipelineId: number): Promise<any[]> {
      const encodedProjectPath = encodeURIComponent(projectPath);
      return this.callGitLabApi<any[]>(
        `projects/${encodedProjectPath}/pipelines/${pipelineId}/jobs`,
      );
    }
  • src/index.ts:660-677 (registration)
    Registration of the 'gitlab_get_pipeline_jobs' tool in the MCP tools list, including its description and input schema definition.
    {
      name: 'gitlab_get_pipeline_jobs',
      description: 'Gets jobs for a specific pipeline.',
      inputSchema: {
        type: 'object',
        properties: {
          projectPath: {
            type: 'string',
            description: 'The path of the GitLab project.',
          },
          pipelineId: {
            type: 'number',
            description: 'The ID of the pipeline.',
          },
        },
        required: ['projectPath', 'pipelineId'],
      },
    },
  • MCP request handler case for 'gitlab_get_pipeline_jobs' that validates GitLab service availability, extracts arguments, calls the service method, and returns the JSON-formatted result.
    case 'gitlab_get_pipeline_jobs': {
      if (!gitlabService) {
        throw new Error('GitLab service is not initialized.');
      }
      const { projectPath, pipelineId } = args as { projectPath: string; pipelineId: number };
      const result = await gitlabService.getPipelineJobs(projectPath, pipelineId);
      return {
        content: [
          {
            type: 'text',
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • Helper method used by getPipelineJobs to make authenticated HTTP requests to the GitLab API, handling errors and JSON parsing.
    private async callGitLabApi<T>(
      endpoint: string,
      method: string = 'GET',
      body?: object,
    ): Promise<T> {
      const url = `${this.config.url}/api/v4/${endpoint}`;
      const headers = {
        'Private-Token': this.config.accessToken,
        'Content-Type': 'application/json',
      };
    
      const options: any = {
        method,
        headers,
        body: body ? JSON.stringify(body) : undefined,
      };
    
      try {
        const response = await fetch(url, options);
        if (!response.ok) {
          const errorText = await response.text();
          console.error(`GitLab API Error: ${response.status} - ${errorText}`);
          throw new Error(`GitLab API Error: ${response.status} - ${errorText}`);
        }
        return response.json() as Promise<T>;
      } catch (error) {
        console.error(`Failed to call GitLab API: ${error}`);
        throw error;
      }
    }

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

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