Skip to content

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_server to control access to new API (WIP, disabled by default)
  • API endpoint: Add POST /api/v4/mcp for 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

How to set up and validate locally

  1. In rails console enable the feature flag:
Feature.enable(:mcp_server)
  1. Perform JSON-RPC method invocation:
POST /api/v4/mcp
Content-Type: application/json

{"jsonrpc":"2.0","method":"initialize","id":"1"}
  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
  1. 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"
        }
      }
    }
  }
  1. Manually list and call tools from MCP client:

IDE

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

Merge request reports

Loading