Add JSON-RPC API
What does this MR do and why?
Introduce JSON-RPC API implementation for Model Context Protocol (MCP) server functionality. The implementation follows JSON-RPC specification 2.0 and MCP specification (2025-06-18).
Key additions:
-
Feature flag: Add
mcp_serverto control access to new API (WIP, disabled by default) -
API endpoint: Add
POST /api/v4/mcpfor JSON-RPC method invocation - JSON-RPC result/error: Add validations and error handling
-
JSON-RPC request handlers: Scaffold initial methods:
-
initialize- Server initialization and capability negotiation -
notifications/initialized- Client initialization confirmation -
tools/list- List available tools -
tools/call- Execute tool operations
-
References
- Issue: #554939 (closed)
- JSON-RPC Specification: https://www.jsonrpc.org/specification
- Model Context Protocol Specification: https://modelcontextprotocol.io/specification/2025-06-18
How to set up and validate locally
- In rails console enable the feature flag:
Feature.enable(:mcp_server)
- Perform JSON-RPC method invocation:
POST /api/v4/mcp
Content-Type: application/json
{"jsonrpc":"2.0","method":"initialize","id":"1"}
- Confirm JSON-RPC result:
{
"jsonrpc": "2.0",
"result": {
"protocolVersion": "2025-06-18",
"capabilities": {
"tools": {
"listChanged": false
}
},
"serverInfo": {
"name": "Official GitLab MCP Server",
"version": "0.0.1-beta"
}
},
"id": "1"
}
Alternatively, you can validate locally end-to-end using client:
Click to expand
- Configure
mcp.json:
{
"mcpServers": {
"GitLab": {
"command": "npx",
"args": [
"mcp-remote",
"http://127.0.0.1:3000/api/v4/mcp",
"--allow-http",
"--debug",
"--header",
"Authorization:${AUTH_HEADER}"
],
"env": {
"AUTH_HEADER": "Temporary workaround. See: https://gitlab.com/gitlab-org/gitlab/-/issues/554826"
}
}
}
}
- Manually list and call tools from MCP client:
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
Edited by Chance Feick
