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

  1. Enable Orbit for a group you are a Reporter in.
  2. Enable the flag: Feature.enable(:orbit_get_context_tool).
  3. Call tools/list on /api/v4/mcp with the X-Gitlab-Enabled-Mcp-Server-Toolsets: orbit header and check that get_orbit_context is listed.
  4. Call get_orbit_context with a token such as group/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::ContextTool calls Analytics::Orbit::ContextService and returns the llm format. It shares the orbit_query rate limit helper with CommandTool through Mcp::Tools::Orbit::RateLimits.
  • EE::Mcp::Tools::Manager#user_tools merges 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_query rate limit and enabled namespaces.
  • EE::Mcp::Tools::Manager#entity_tools checks orbit_get_context_tool for current_user, so with the flag off the tool is neither listed nor callable (get_tool raises ToolNotFoundError).
  • An unresolved token returns Response.error: not_found maps to NOT_FOUND, invalid_token and unsupported_type to BAD_REQUEST.
  • Governance: the tool resolves its token to a project or group with Analytics::Orbit::ContextToken.container_for, which ContextService shares. Rules apply to that container only, not to linked items or expanded neighbors (follow-up: #642923). GovernedMcpTools now also lists this per-user tool, so rules can be created for it.
  • Not changed: McpConfigService allowlists and ToolCatalog cover the separate /api/v4/orbit/mcp endpoint. Since !272139 (merged) that endpoint also lists the catalog commands, and it does not get get_orbit_context. Docs added in mcp_server_tools.md and mcp_server.md.
Edited by Dmitry Gruzd

Merge request reports

Loading
Loading