Connecting AI Agents to GitLab: How I Implemented MCP Resources in GitLab Core
Description and use
Implemented MCP resources/list and resources/templates/list endpoints in GitLab Core, enabling LLM agents to access repository context. Added enum constraints to the search scope to prevent invalid inputs.
Problem
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.
Outcome
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.
Workflow
- 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).
Evidence
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: ...
- Record date: 2026-10-16T03:41:20.909Z