用于 ADK 的 GitLab MCP 工具¶
在 ADK 中得到支持。PythonTypeScript
The GitLab MCP Server 将您的 ADK 代理直接连接到…… GitLab.com 或者您自己管理的 GitLab 实例。这种集成功能使您的代理能够管理问题、合并请求、检查 CI/CD 流程、执行语义代码搜索,并通过自然语言实现开发工作流的自动化。
使用场景¶
-
语义代码探索(Semantic Code Exploration):使用自然语言来浏览您的代码库。 与传统的文本搜索不同,您可以查询代码中的逻辑和意图,从而快速理解复杂的实现方式。
-
加快合并请求的审核流程:立即了解代码变更的情况。您可以获取完整的合并请求信息,分析具体的代码差异(diffs),并查看提交历史记录,从而更快、更准确地为您的团队提供反馈。
-
排查 CI/CD 流程中的问题(故障)无需离开聊天界面,即可诊断构建失败的问题。您可以查看流水线状态并获取详细的作业日志,从而准确找出某个合并请求或提交操作为何未能通过检查。
先决条件¶
- 一个拥有 Premium 或 Ultimate 订阅资格的 GitLab 账户; GitLab Duo 已启用
- 测试版和实验性功能 已在您的 GitLab 设置中启用该功能。
与代理程序(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")
GITLAB_INSTANCE_URL = "gitlab.com"
root_agent = Agent(
model="gemini-flash-latest",
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-flash-latest",
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 };
注意:
当你第一次运行这个代理程序时,系统会自动打开一个浏览器窗口(同时会显示一个授权请求页面),该页面会请求你授予 OAuth 权限。你必须批准这个请求,才能让该代理程序访问你的 GitLab 数据。
可用的工具¶
| 工具 | 描述 |
|---|---|
get_mcp_server_version |
返回 GitLab MCP 服务器的当前版本信息。 |
create_issue |
在 GitLab 项目中创建一个新的问题(即一个新的任务或 bug)。 |
get_issue |
检索有关特定 GitLab 问题的详细信息。 |
create_merge_request |
在一个项目中创建一个合并请求。 |
get_merge_request |
检索有关特定 GitLab 合并请求的详细信息。 |
get_merge_request_commits |
检索特定合并请求中的提交记录列表。 |
get_merge_request_diffs |
检索特定合并请求的差异信息(即两个代码版本之间的变化)。 |
get_merge_request_pipelines |
检索特定合并请求相关的管道(pipelines)。 |
get_pipeline_jobs |
检索特定 CI/CD 流程中的所有作业(即需要执行的步骤或任务)。 |
gitlab_search |
使用搜索 API 在整个 GitLab 实例中查找指定的术语。 |
semantic_code_search |
在项目中搜索相关的代码片段。 |