Loading
[Refactor] Govern the remaining MCP tools by their own container lookup
What does this MR do and why?
This is the last of three stacked MRs that make MCP governance resolve a call's containers through each tool's own lookup. It's stacked on !268283 and targets its branch. !261045 adds the plumbing and explains the change.
It has two commits:
- Convert the remaining tools. These are the projects, project members, groups, labels, pipelines, jobs,
list_todos, wikis and releases tools, plus the EE security and Duo workflow tools. The custom servicesget_job,get_artifact_fileandlist_releases, and the aggregatedstart_duo_session, use their own lookup. Record arguments (pipeline_id,vulnerability_id,workflow_id) still use the declaredrecord:lookups. - Make
GraphqlTool#governed_containersraiseNotImplementedErrorby default and remove the fallback to the declared lookup fromGraphqlService. Every GraphQL tool has converted by now, so no tool can be governed through a stale declaration. An ungovernable service such asget_userreturns before it builds its tool, because that tool has nogoverned_containers.
REST tools keep the declared lookup through Gitlab::ResourceLookup, the same function Grape's find_project uses.
This MR targets !268283's branch instead of !261045's. The NotImplementedError default needs every tool converted, including the ones in !268283, so its pipeline can only pass on top of that MR. The diff against the target branch shows only this MR's files, so both MRs can still be reviewed in parallel.
!261051 is stacked on this MR.
How to reproduce the issue
There is no user-facing defect.
- Check out
633015-mcp-governance-mr-repository-tools. - Define a
GraphqlToolsubclass withoutgoverned_containersand callgoverned_containerson its service. - You can see that the call falls back to the declared lookup.
How to test the fix
- On this branch, repeat the call. It raises
NotImplementedError. - Call
governed_containersforget_pipelineandget_vulnerability. The result is the project the tool's execute path resolves.
Run the specs:
bin/rspec spec/services/mcp ee/spec/services/mcp ee/spec/services/ee/mcp spec/lib/api/mcp/handlers ee/spec/lib/ee/api/mcp/handlers ee/spec/lib/ai/tool_rules spec/requests/api/mcp ee/spec/requests/api/mcpReferences
- Issue: https://gitlab.com/gitlab-org/gitlab/-/work_items/633015
- Split proposal: !261045 (comment 4162846677)
- Previous in the stack: !268283
- Follow-up MR: !261051
Edited by Raounak Sharma