Skip to content

GitLab

The GitLab MCP Server connects your ADK agent directly to GitLab.com or your self-managed GitLab instance. This integration gives your agent the ability to manage issues and merge requests, inspect CI/CD pipelines, perform semantic code searches, and automate development workflows using natural language.

GitLab MCP 服务器 将您的 ADK 智能体直接连接到 GitLab.com 或您的自托管 GitLab 实例。此集成使您的智能体能够管理问题和合并请求,检查 CI/CD 管道,执行语义代码搜索,并使用自然语言自动化开发工作流。

Use cases

用例

  • Semantic Code Exploration: Navigate your codebase using natural language. Unlike standard text search, you can query the logic and intent of your code to quickly understand complex implementations. 语义代码探索:使用自然语言浏览您的代码库。与标准文本搜索不同,您可以查询代码的逻辑和意图,以快速理解复杂的实现。

  • Accelerate Merge Request Reviews: Get up to speed on code changes instantly. Retrieve full merge request contexts, analyze specific diffs, and review commit history to provide faster, more meaningful feedback to your team. 加速合并请求审查:立即了解代码更改。检索完整的合并请求上下文,分析特定的差异,并审查提交历史,以为您的团队提供更快、更有意义的反馈。

  • Troubleshoot CI/CD Pipelines: Diagnose build failures without leaving your chat. Inspect pipeline statuses and retrieve detailed job logs to pinpoint exactly why a specific merge request or commit failed its checks. 排查 CI/CD 管道故障:在不离开聊天的情况下诊断构建失败。检查管道状态并检索详细的作业日志,以精确定位特定合并请求或提交未通过检查的确切原因。

Prerequisites

先决条件

Use with agent

与智能体一起使用

from google.adk.agents import Agent
from google.adk.tools.mcp_tool import McpToolset
from google.adk.tools.mcp_tool.mcp_session_manager import StdioConnectionParams
from mcp import StdioServerParameters

# Replace with your instance URL if self-hosted (e.g., "gitlab.example.com")
# 如果自托管,请替换为您的实例 URL(例如,"gitlab.example.com")
GITLAB_INSTANCE_URL = "gitlab.com"

root_agent = Agent(
    model="gemini-2.5-pro",
    name="gitlab_agent",
    instruction="Help users get information from GitLab",
    tools=[
        McpToolset(
            connection_params=StdioConnectionParams(
                server_params = StdioServerParameters(
                    command="npx",
                    args=[
                        "-y",
                        "mcp-remote",
                        f"https://{GITLAB_INSTANCE_URL}/api/v4/mcp",
                        "--static-oauth-client-metadata",
                        "{\"scope\": \"mcp\"}",
                    ],
                ),
                timeout=30,
            ),
        )
    ],
)

Note

When you run this agent for the first time, a browser window will open automatically (and an authorization URL will be printed) requesting OAuth permissions. You must approve this request to allow the agent to access your GitLab data.

当您第一次运行此智能体时,浏览器窗口将自动打开(并且将打印授权 URL)请求 OAuth 权限。您必须批准此请求以允许智能体访问您的 GitLab 数据。

Available tools

可用的工具

Tool | Description 工具 | 描述 ---- | ----------- get_mcp_server_version | Returns the current version of the GitLab MCP server get_mcp_server_version | 返回 GitLab MCP 服务器的当前版本 get_projects | Retrieve a list of projects accessible to the authenticated user get_projects | 检索经过身份验证的用户可访问的项目列表 get_project | Retrieve a specific project by ID get_project | 通过 ID 检索特定项目 get_merge_requests | Retrieve merge requests for a project get_merge_requests | 检索项目的合并请求 get_merge_request | Retrieve a specific merge request by IID get_merge_request | 通过 IID 检索特定的合并请求 get_issues | Retrieve issues for a project get_issues | 检索项目的问题 get_issue | Retrieve a specific issue by IID get_issue | 通过 IID 检索特定问题 search_code | Perform semantic search across project code search_code | 在项目代码中执行语义搜索 get_pipelines | Retrieve CI/CD pipelines for a project get_pipelines | 检索项目的 CI/CD 管道 get_pipeline | Retrieve a specific pipeline by ID get_pipeline | 通过 ID 检索特定管道 get_pipeline_jobs | Retrieve jobs for a pipeline get_pipeline_jobs | 检索管道的作业 get_job | Retrieve a specific job by ID get_job | 通过 ID 检索特定作业 get_job_trace | Retrieve the trace for a job get_job_trace | 检索作业的跟踪 get_file_content | Retrieve file content from a repository get_file_content | 从仓库检索文件内容 create_issue | Create a new issue create_issue | 创建新问题 create_note | Create a note on a merge request or issue create_note | 在合并请求或问题上创建注释 update_issue | Update an existing issue update_issue | 更新现有问题 close_issue | Close an issue close_issue | 关闭问题 reopen_issue | Reopen a closed issue reopen_issue | 重新打开已关闭的问题 get_file_tree | Retrieve the file tree for a repository get_file_tree | 检索仓库的文件树 get_commit | Retrieve a specific commit get_commit | 检索特定提交 get_branches | Retrieve branches for a project get_branches | 检索项目的分支 get_tags | Retrieve tags for a project get_tags | 检索项目的标签 get_diff | Retrieve the diff between two commits or branches get_diff | 检索两个提交或分支之间的差异

Configuration

配置

Connection Parameters

连接参数

| Parameter | Type | Required | Default | Description 参数 | 类型 | 必需 | 默认值 | 描述 ---------- | ------ | -------- | -------- | ----------- server_params | StdioServerParameters | Yes | - | Server parameters including command and args server_params | StdioServerParameters | 是 | - | 包括命令和参数的服务器参数 timeout | int | No | 30 | Connection timeout in seconds timeout | int | 否 | 30 | 连接超时时间(以秒为单位)

Server Parameters

服务器参数

| Parameter | Type | Description 参数 | 类型 | 描述 ---------- | ------ | ----------- command | string | Command to run the MCP server (e.g., "npx") command | string | 运行 MCP 服务器的命令(例如,"npx") args | list | Arguments for the command args | list | 命令的参数

OAuth Configuration

OAuth 配置

When running locally, the agent will initiate an OAuth flow:

本地运行时,智能体将启动 OAuth 流程:

  1. A browser window opens automatically 浏览器窗口自动打开
  2. You authorize the agent to access your GitLab account 您授权智能体访问您的 GitLab 帐户
  3. The agent receives an OAuth token and stores it for future use 智能体接收 OAuth 令牌并将其存储以供将来使用

The --static-oauth-client-metadata argument provides the OAuth client configuration needed for GitLab Duo integration.

--static-oauth-client-metadata 参数提供了 GitLab Duo 集成所需的 OAuth 客户端配置。

Self-Hosted Instances

自托管实例

For self-hosted GitLab instances, modify the GITLAB_INSTANCE_URL:

对于自托管的 GitLab 实例,请修改 GITLAB_INSTANCE_URL:

GITLAB_INSTANCE_URL = "gitlab.yourcompany.com"

Ensure your GitLab instance has the MCP API enabled and GitLab Duo configured.

确保您的 GitLab 实例已启用 MCP API 并配置了 GitLab Duo。

Security Considerations

安全考虑

  • GitLab Duo is required for MCP server access 访问 MCP 服务器需要 GitLab Duo
  • OAuth tokens are scoped to specific permissions requested during authorization OAuth 令牌限于授权期间请求的特定权限
  • Regularly review authorized applications in your GitLab settings 定期在 GitLab 设置中审查已授权的应用程序
  • For self-hosted instances, ensure proper HTTPS/TLS configuration 对于自托管实例,确保正确的 HTTPS/TLS 配置