Instrument initialize and tools/list MCP protocol methods

What does this MR do and why?

Only the tools/call MCP method emitted an internal event. initialize and tools/list emitted nothing (no internal event and no mcp.log line), so we had no visibility into client connects, tool-list requests, or whether a tool rename breaks existing vs. new connections.

This adds, all in CE (the MCP server is a CE feature):

  • initialize_mcp_connection internal event, fired from API::Mcp::Handlers::InitializeRequest#invoke, records the negotiated protocol version.
  • list_mcp_tools internal event, fired from API::Mcp::Handlers::ListTools#invoke.
  • An mcp.log line for each method through Gitlab::Mcp::Logger#conditional_info, so both are queryable in Kibana:
    • initialize: event_name: 'initialize', requested_protocol_version, protocol_version (negotiated).
    • tools/list: event_name: 'tools_list', tool_count.

Both event definitions live in config/events/ with product_group: agent_execution, product_categories: [mcp_server] and all tiers. Each event also has a Service Ping metric in config/metrics/counts_all/ (count_total_initialize_mcp_connection and count_total_list_mcp_tools, time_frame: [7d, 28d, all]), so Self-Managed and Dedicated instances report them too.

Closes #630107 (closed)

Screenshots or screen recordings

Not applicable — instrumentation only, no UI change.

How to set up and validate locally

  1. Start the internal events monitor in GDK:

    bin/rails runner scripts/internal_events/monitor.rb initialize_mcp_connection list_mcp_tools
  2. With a token that has the mcp scope, send an initialize request:

    curl --request POST "http://gdk.test:3000/api/v4/mcp" \
      --header "Authorization: Bearer <token>" \
      --header "Content-Type: application/json" \
      --data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18"}}'

    Confirm initialize_mcp_connection shows up with protocol_version: 2025-06-18. Repeat with "protocolVersion":"2026-07-28" and confirm the recorded version is 2025-11-25.

  3. Send a tools/list request:

    curl --request POST "http://gdk.test:3000/api/v4/mcp" \
      --header "Authorization: Bearer <token>" \
      --header "Content-Type: application/json" \
      --data '{"jsonrpc":"2.0","id":2,"method":"tools/list"}'

    Confirm list_mcp_tools shows up in the monitor.

  4. Check log/mcp.log for the initialize and tools_list lines.

This contribution was prepared with the help of an AI assistant. I reviewed the changes and take responsibility for them.

Edited by Anish Kumar

Merge request reports

Loading
Loading