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_connectioninternal event, fired fromAPI::Mcp::Handlers::InitializeRequest#invoke, records the negotiated protocol version.list_mcp_toolsinternal event, fired fromAPI::Mcp::Handlers::ListTools#invoke.- An
mcp.logline for each method throughGitlab::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
-
Start the internal events monitor in GDK:
bin/rails runner scripts/internal_events/monitor.rb initialize_mcp_connection list_mcp_tools -
With a token that has the
mcpscope, send aninitializerequest: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_connectionshows up withprotocol_version: 2025-06-18. Repeat with"protocolVersion":"2026-07-28"and confirm the recorded version is2025-11-25. -
Send a
tools/listrequest: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_toolsshows up in the monitor. -
Check
log/mcp.logfor theinitializeandtools_listlines.
This contribution was prepared with the help of an AI assistant. I reviewed the changes and take responsibility for them.