Draft: Support updating saved views in save_work_item_saved_view MCP tool
What does this MR do and why?
After !265188, an agent can create a saved view but can't change one. If a user says "rename my Open bugs view" or "also filter it by the backend label", the agent has to create a new view or send them to the UI.
This MR adds updating to the same save_work_item_saved_view tool. When the agent passes saved_view_id, the tool updates that view instead of creating one. The agent sends only the fields it wants to change:
{ "saved_view_id": 123, "name": "Bugs to triage" }Merge order
- !269309:
save_work_item_saved_viewwithout filters. - !265188: the
filtersargument. Targets the branch of 1. - This MR:
save_work_item_saved_viewfor updating a saved view. Targets the branch of 2.
Already merged: !265187 (merged) (list_work_item_saved_views), !267626 (merged) (numeric IDs and displaySettings in get_saved_view_work_items), and !268921 (merged) (granular token permission for filterWarnings). This MR is the first tool that can return a non-empty filterWarnings list to a fine-grained token, so it needed that one.
The tool name and ID format follow the MCP tool review board approval on #636789 (notes 4110954702, 4125506423, 4127284178, 4124641273).
A quick intro to saved views
If you haven't worked with saved views before: a saved view is a named set of filters, sort, and display settings for the work items list. It belongs to a group or a project. !265187 (merged) has a longer intro, and !265188 explains how filters are stored as IDs and why the tool adds its own filterWarnings. The same warnings work on update.
Updating uses the existing workItemSavedViewUpdate GraphQL mutation, so the permission checks are the same as when you edit a view in the UI.
Finding the namespace on update
On create, url, project_id, or group_id tells us the namespace. On update, saved_view_id is enough. Governance looks up the saved view and uses its namespace, the same way get_saved_view_work_items does. Then the tool rules for that group or project apply.
Agents often send the project or group along with the ID, so the tool accepts it too, as agreed in decision D4 on #633661 (closed). It must be the saved view's own project or group, or the call fails. A mismatched namespace never passes silently.
Notes for reviewers
- Numeric IDs only.
saved_view_idis an integer, and the outputidis an integer. Saved views have no iid, so the MCP guide says to unwrap global IDs. - Governance:
saved_view_idresolves to the group, or to the project for a project-level view. If a namespace argument is also given, it's governed too. If the view doesn't exist, no namespace is added, and the call fails in the mutation with a general "not found or no access" error. - Namespace check on update: if
url,project_id, orgroup_idis not the saved view's own project or group, the tool returnsSaved view 'N' not found or inaccessible in 'path'. The same message covers a view that is missing, private to someone else, or in another namespace, so it doesn't reveal where a view lives. The check usesWorkItems::SavedViews::SavedViewsFinder, the same finder as the GraphQLsavedViewsfield. - At least one field: an update with only
saved_view_idis rejected, so the agent gets a clear error instead of an empty update. filtersanddisplay_settingsreplace, they don't merge. This matches the GraphQL mutation. Leaving them out keeps the stored value. The tool description tells agents to read the current value withget_saved_view_work_itemsfirst and send the whole value.
References
- Issue: #631461
- Proposal and board approval: #636789
- Decision D4: #633661 (closed)
- POC with all three tools: !261265 (closed)
Screenshots or screen recordings
| Duo Agentic Chat renames a saved view and changes its filters |
|---|
On the private Team board view (all 227 items, on a board), I asked Rename my "Team board" saved view in group gitlab-org to "Bug board" and make it show only open issues with the bug label. Duo finds the view, then calls save_work_item_saved_view with savedViewId and asks for approval. After approval the same view is now Bug board with the State, Type and Label filters (11 items). It keeps its board layout, sort and visibility, and there are no filter warnings.
How to set up and validate locally
With Duo Agentic Chat
If you have Duo Agentic Chat working locally, you can test updates from chat:
-
Make sure the top-level group has Settings > GitLab Duo > External MCP tools turned on. Without it, chat doesn't get the GitLab MCP tools.
-
Create a saved view called Team board in
gitlab-org, from the UI or by asking Duo. -
On the
gitlab-orgwork items list, open GitLab Duo Chat, pick the GitLab Duo agent, and send:Rename my "Team board" saved view in group gitlab-org to "Bug board" and make it show only open issues with the bug label -
Approve the save work item saved view tool call.
-
The same view is now Bug board with the new filters. Its layout, sort and visibility are unchanged.
-
Clean up: delete the Bug board saved view.
With the Rails console
-
Open a Rails console (
gdk rails c), create a view to update, and keep its ID:user = User.find_by_username('root') call = ->(arguments, as: user) do tool = Mcp::Tools::Manager.new.get_tool(name: 'save_work_item_saved_view') tool.set_cred(current_user: as) tool.execute(params: { arguments: arguments }) end id = call.({ group_id: 'gitlab-org', name: 'Open bugs', filters: { state: 'opened' } })[:structuredContent]['id'] # => an integer, for example 42 -
Rename it. Only the name should change:
call.({ saved_view_id: id, name: 'Bugs to triage' })[:structuredContent] # => name "Bugs to triage", filters still {"state" => "opened"} -
Send the group along with the ID. The matching group works, another group fails:
call.({ saved_view_id: id, group_id: 'gitlab-org', sort: 'UPDATED_DESC' })[:isError] # => false call.({ saved_view_id: id, group_id: 'flightjs', sort: 'UPDATED_DESC' }).dig(:content, 0, :text) # => "Tool execution failed: Saved view '42' not found or inaccessible in 'flightjs'" -
Check that governance finds the right group:
Mcp::Tools::Manager.new.get_tool(name: 'save_work_item_saved_view').governed_containers({ saved_view_id: id }).containers.map(&:full_path) # => ["gitlab-org"] -
Check that an update with no fields is rejected:
call.({ saved_view_id: id }).dig(:content, 0, :text) # => "Validation error: Provide at least one of name, description, filters, display_settings, sort, is_private to update the saved view" -
Check that a user who isn't a member can't update it:
outsider = User.human.active.find { |u| !u.admin? && !Group.find_by_full_path('gitlab-org').member?(u) } call.({ saved_view_id: id, name: 'hijack' }, as: outsider).slice(:isError, :reason) # => {isError: true, reason: :unauthorized} -
Clean up: delete the Bugs to triage view from the work items list.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.