Skip to content

ADK 的 GitLab MCP 工具

Supported in ADKPythonTypeScript

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

使用场景

  • 语义代码探索:使用自然语言浏览你的代码库。与标准文本搜索不同,你可以查询代码的逻辑和意图,快速理解复杂的实现。

  • 加速合并请求审查:即时了解代码更改。检索完整的合并请求上下文、分析特定差异并审查提交历史,为你的团队提供更快、更有意义的反馈。

  • 排查 CI/CD 流水线问题:无需离开聊天即可诊断构建失败。检查流水线状态并检索详细的作业日志,精确定位特定合并请求或提交检查失败的原因。

前提条件

与智能体一起使用

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")
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,
            ),
        )
    ],
)
import { LlmAgent, MCPToolset } from "@google/adk";

// Replace with your instance URL if self-hosted (e.g., "gitlab.example.com")
const GITLAB_INSTANCE_URL = "gitlab.com";

const rootAgent = new LlmAgent({
    model: "gemini-2.5-pro",
    name: "gitlab_agent",
    instruction: "Help users get information from GitLab",
    tools: [
        new MCPToolset({
            type: "StdioConnectionParams",
            serverParams: {
                command: "npx",
                args: [
                    "-y",
                    "mcp-remote",
                    `https://${GITLAB_INSTANCE_URL}/api/v4/mcp`,
                    "--static-oauth-client-metadata",
                    '{"scope": "mcp"}',
                ],
            },
        }),
    ],
});

export { rootAgent };

Note

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

可用工具

工具 描述
get_mcp_server_version 返回 GitLab MCP 服务器的当前版本
create_issue 在 GitLab 项目中创建新问题
get_issue 检索有关特定 GitLab 问题的详细信息
create_merge_request 在项目中创建合并请求
get_merge_request 检索有关特定 GitLab 合并请求的详细信息
get_merge_request_commits 检索特定合并请求中的提交列表
get_merge_request_diffs 检索特定合并请求的差异
get_merge_request_pipelines 检索特定合并请求的流水线
get_pipeline_jobs 检索特定 CI/CD 流水线的作业
gitlab_search 使用搜索 API 在整个 GitLab 实例中搜索术语
semantic_code_search 在项目中搜索相关代码片段

其他资源