Connecting AI Agents to GitLab: How I Implemented MCP Resources in GitLab Core
说明与用途
在 GitLab Core 中实现了 MCP resources/list 和 resources/templates/list 端点,使 LLM 代理能够访问仓库上下文。为搜索范围添加了枚举约束,防止无效输入导致错误。
问题
MCP clients could not access GitLab resources because the server did not advertise or implement the required endpoints, causing 404 errors and disabling context awareness.
结果
Implemented MCP resources and templates endpoints in GitLab Core, resolving 404 errors and enabling AI agents to access project context. Added enum constraints to search scope, reducing hallucinations and server errors.
工作流
- 1. Identify missing MCP endpoints causing 404 errors.
- 2. Update the server handshake to advertise
resourcescapability. - 3. Implement
ResourcesListHandlerto return a list of available resources. - 4. Implement
ResourceTemplatesListHandlerto return URI templates for resources. - 5. Add enum constraints to the search scope JSON schema to prevent hallucinations.
- 6. Verify handlers via GitLab CI pipelines (Danger Bot, RuboCop, Predictive RSpec).
证据
Because GitLab's server had not implemented or advertised these endpoints, the server responded with: "Method not found: resources/list"
In the server's handshake responder, we registered the resources capability: ...
Next, we added request dispatchers for the resource endpoints: ...
In Merge Request !259119, we introduced explicit enum constraints to the JSON Schema: ...
- 记录日期: 2026-10-16T03:41:20.909Z