Skip to main content
Glama

https://github.com/owayo/gitlab-mcp-server

get_pipeline_failed_jobs

Retrieve failed job console outputs from GitLab pipelines using the Model Context Protocol (MCP) server to analyze and address pipeline issues efficiently.

Instructions

GitLabパイプラインで失敗したジョブのコンソール出力を取得

Input Schema

NameRequiredDescriptionDefault

No arguments

Input Schema (JSON Schema)

{ "properties": {}, "title": "get_pipeline_failed_jobsArguments", "type": "object" }

Implementation Reference

  • main.py:46-61 (handler)
    The handler function for the 'get_pipeline_failed_jobs' tool. It is registered with @mcp.tool(), retrieves the current MR ID, fetches the failed jobs output using the helper, and formats a response string.
    @mcp.tool() def get_pipeline_failed_jobs() -> str: """GitLabパイプラインで失敗したジョブのコンソール出力を取得""" mr_id = get_current_mr_id() failed_jobs_output = get_failed_jobs_output(mr_id=mr_id) if failed_jobs_output: return f""" パイプラインで以下のエラーが出ています。 プロダクトコードの修正で対応が可能な場合は修正を行ってください。 {failed_jobs_output} """ else: return "パイプラインで失敗したジョブが見つかりません。"
  • main.py:46-46 (registration)
    Registration of the tool using the FastMCP @mcp.tool() decorator.
    @mcp.tool()
  • Core helper function that implements the logic to retrieve console outputs from failed jobs in the latest pipeline of the specified Merge Request.
    def get_failed_jobs_output(mr_id: int) -> str: """ 指定したMR IDに関連する最後のパイプラインで失敗したジョブのコンソール出力を取得します。 最後のパイプラインに失敗したジョブがなければ、空の文字列を返します。 Args: mr_id (int): Merge Request ID Returns: str: 失敗したジョブのコンソール出力、または空文字列 Raises: ValueError: ジョブ出力の取得に失敗した場合 """ try: project = get_gitlab_project() # MRを取得 mr = project.mergerequests.get(mr_id) # パイプライン情報を取得 if not hasattr(mr, "pipelines") or not mr.pipelines: return "" # パイプラインを取得し、最新のものを選択 pipelines = mr.pipelines.list() if not pipelines: return "" # 最新のパイプラインを取得 (GitLabのAPIはデフォルトで降順) latest_pipeline = pipelines[0] pipeline_detail = project.pipelines.get(latest_pipeline.id) # 失敗したジョブを検索 failed_jobs = [ job for job in pipeline_detail.jobs.list() if job.status == "failed" ] if not failed_jobs: return "" # 失敗したジョブがない場合は空文字列を返す # 失敗したジョブのコンソール出力を取得 outputs = [] for job in failed_jobs: job_detail = project.jobs.get(job.id) job_output = job_detail.trace() outputs.append( f"# ジョブ: {job.name}\n- ステータス: {job.status}\n- 出力:\n```\n{job_output}\n```" ) return "\n\n".join(outputs) except gitlab.exceptions.GitlabGetError: raise ValueError(f"MR ID #{mr_id} が見つかりません。") except Exception as e: raise ValueError(f"失敗したジョブの出力取得に失敗しました: {str(e)}")
  • main.py:31-44 (helper)
    Helper function to retrieve the IID of the Merge Request associated with the current branch.
    def get_current_mr_id() -> int: """ 現在のブランチのMRIDを取得します。 Returns: int: 現在のブランチのMRID """ branch_name = get_current_branch() mr = get_merge_request(branch_name) if mr: return mr.iid else: return "現在のブランチに関連するMerge Requestが見つかりません。"

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

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