Add get_orbit_context tool to the orbit MCP toolset
What does this MR do and why?
Agents using the Orbit tools on the GitLab MCP server could only run graph queries. They had no way to read one issue or merge request from a token. This adds a read-only get_orbit_context tool to the orbit toolset. It follows the same access and rate limit rules as the matching REST endpoint.
References
Related to gitlab-org/orbit/knowledge-graph#1531
Tool proposal: #641198 (closed)
Screenshots or screen recordings
Output of the tool's formatter for one seeded issue (orbit-test/demo#4), run with rails runner on a local stack. Before, master does not list the tool. After:
get_orbit_context {"token": "orbit-test/demo#4"}
orbit_context version=1.4.0 entities=1
- orbit-test/demo#4 id=4 found=true
title="Slow pipeline list"
state="closed"
work_item_type="issue"
labels="backend, bug"A token that doesn't resolve now returns an MCP error instead of a success. The JSON-RPC result for MergeRequest[<missing id>], from a request spec through the real ContextService:
{
"content": [
{
"type": "text",
"text": "orbit_context version=1.4.0 entities=1\n- \"MergeRequest[2147483647]\" found=false error=not_found\n"
}
],
"structuredContent": {},
- "isError": false
+ "isError": true
}How to set up and validate locally
- Enable Orbit for a group you are a Reporter in.
- Enable the flag:
Feature.enable(:orbit_get_context_tool). - Call
tools/liston/api/v4/mcpwith theX-Gitlab-Enabled-Mcp-Server-Toolsets: orbitheader and check thatget_orbit_contextis listed. - Call
get_orbit_contextwith a token such asgroup/project#7.
Specs: ee/spec/services/mcp, ee/spec/lib/ai/tool_rules, spec/services/mcp and ee/spec/requests/api/mcp, 0 failures.
MR acceptance checklist
Evaluated against the MR acceptance checklist. The tool is behind the orbit_get_context_tool feature flag (gitlab_com_derisk, disabled by default). Rollout: #642917. No database change.
Agent context
Mcp::Tools::Orbit::ContextToolcallsAnalytics::Orbit::ContextServiceand returns thellmformat. It shares theorbit_queryrate limit helper withCommandToolthroughMcp::Tools::Orbit::RateLimits.EE::Mcp::Tools::Manager#user_toolsmerges the tool into the catalog tools.CommandCatalog.available_for?is the existing gate (read_orbit token permission, Orbit accessible, enabled namespaces), extracted so both paths use it. The tool stays listed when the Orbit server is down, because it does not need the command list.- Checks mirrored from
ee/lib/api/orbit/data.rb:orbit_queryrate limit and enabled namespaces. EE::Mcp::Tools::Manager#entity_toolschecksorbit_get_context_toolforcurrent_user, so with the flag off the tool is neither listed nor callable (get_toolraisesToolNotFoundError).- An unresolved token returns
Response.error:not_foundmaps toNOT_FOUND,invalid_tokenandunsupported_typetoBAD_REQUEST. - Governance: the tool resolves its token to a project or group with
Analytics::Orbit::ContextToken.container_for, whichContextServiceshares. Rules apply to that container only, not to linked items or expanded neighbors (follow-up: #642923).GovernedMcpToolsnow also lists this per-user tool, so rules can be created for it. - Not changed:
McpConfigServiceallowlists andToolCatalogcover the separate/api/v4/orbit/mcpendpoint. Since !272139 (merged) that endpoint also lists the catalog commands, and it does not getget_orbit_context. Docs added inmcp_server_tools.mdandmcp_server.md.