Add list_work_item_saved_views MCP tool

What does this MR do and why?

Agents can already open one saved view with get_saved_view_work_items, but they need its ID first. There is no tool to find out which saved views exist in a project or group, so the agent has to ask the user for the ID.

This MR adds a read-only list_work_item_saved_views MCP tool to the work_items toolset. It returns the saved views in a project or group and supports search, subscribed_only, sort, and cursor pagination.

All of this comes from the existing namespace.savedViews GraphQL field, so the tool is a thin wrapper around that field and adds no new finder or query logic.

This is MR 1 of 3:

  1. This MR: list_work_item_saved_views
  2. !265188: save_work_item_saved_view for creating a saved view
  3. !265189: save_work_item_saved_view for updating a saved view

Merge request saved views exist too (MergeRequests::SavedView), so the name says which saved views it lists. The MCP tool review board approved the tool name and the integer ID output:

Blocked by !267626 (merged)

This tool returns numeric saved view IDs, for example 42. get_saved_view_work_items accepts numeric IDs only after !267626 (merged) merges. If this MR merges first, list → get fails in between, so please merge !267626 (merged) first.

A quick intro to saved views

If you haven't worked with saved views before, here is the short version.A saved view is a named set of filters, sort, and display settings for the work items list. For example, "Open bugs for my team". It belongs to a group or a project.
  • Private or shared: a private view is visible only to its author. A shared view is visible to everyone who can see the namespace (SavedView.visible_to).
  • Subscribed: when a user subscribes to a view, it shows up as a tab on their work items list. Subscriptions live in user_saved_views, which also stores the user's own tab order in relative_position.
  • Name and description: both are 140 characters max. search matches either of them.

What the tool returns

Each row has id, name, description, sort, isPrivate, subscribed, shareUrl, and updatedAt, plus pageInfo for the next page.

id is a plain integer, not a global ID. Saved views have no iid, so the MCP ID rules say to unwrap the global ID, the same way list_projects and list_groups do. The agent can pass id straight to get_saved_view_work_items and save_work_item_saved_view.

Notes for reviewers
  • No filters in the list. The filters and filterWarnings fields can resolve for only one saved view per request, so the list leaves them out. Agents use get_saved_view_work_items for those.
  • Only three sort values. WorkItemsSavedViewsSort also inherits the generic created and updated values from Types::SortEnum, but the finder ignores them and falls back to ID. So the tool offers only ID, NAME_ASC, and RELATIVE_POSITION.
  • RELATIVE_POSITION needs subscribed_only: true. The position is per user and stored on the subscription, so without subscribed_only the finder would quietly sort by ID (SavedView.sort_by_attributes). The tool returns a validation error instead, the same way it handles more than one parent identifier.
  • ID sort is newest first (id DESC).
  • Exactly one of url, project_id, or group_id. If you pass more than one, the tool returns an error instead of quietly picking one.

References

Screenshots or screen recordings

Not a UI change, but here is the tool working end to end in GDK with Duo Agentic Chat. I created three saved views in gitlab-org (two shared, one private) and subscribed to one of them. Then I asked "List the saved views in group gitlab-org, and tell me which ones I'm subscribed to". Chat calls the tool once (it was still named list_saved_views when this was recorded), lists all three views, and picks out the one I'm subscribed to.

How to set up and validate locally

  1. Make sure gitlab-org has a few saved views. If it has none, open its work items list, change some filters, and click Save view. Save at least one as private and subscribe to one.

  2. Open a Rails console (gdk rails c):

    user = User.find_by_username('root')
    call = ->(arguments) do
      tool = Mcp::Tools::Manager.new.get_tool(name: 'list_work_item_saved_views')
      tool.set_cred(current_user: user)
      tool.execute(params: { arguments: arguments })[:structuredContent]
    end
    
    call.({ group_id: 'gitlab-org', first: 3 })

    You should get up to 3 saved_views and a pageInfo. If there are more views, hasNextPage is true.

  3. Get the next page by passing the cursor back:

    cursor = call.({ group_id: 'gitlab-org', first: 3 })['pageInfo']['endCursor']
    call.({ group_id: 'gitlab-org', first: 3, after: cursor })
  4. Try the other options:

    call.({ group_id: 'gitlab-org', search: 'bug' })
    call.({ group_id: 'gitlab-org', subscribed_only: true, sort: 'RELATIVE_POSITION' })
  5. Check that a sort outside the three values, and RELATIVE_POSITION without subscribed_only, are rejected:

    tool = Mcp::Tools::Manager.new.get_tool(name: 'list_work_item_saved_views')
    tool.set_cred(current_user: user)
    tool.execute(params: { arguments: { group_id: 'gitlab-org', sort: 'CREATED_DESC' } }).dig(:content, 0, :text)
    # => "Validation error: Invalid sort: 'CREATED_DESC'. Must be one of: ID, NAME_ASC, RELATIVE_POSITION"
    tool.execute(params: { arguments: { group_id: 'gitlab-org', sort: 'RELATIVE_POSITION' } }).dig(:content, 0, :text)
    # => "Validation error: sort RELATIVE_POSITION requires subscribed_only: true"
  6. Optional: connect a real MCP client to GDK as described in MCP server development, then ask "List the saved views in group gitlab-org".

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.

🤖 Generated with Claude Code

Edited by Rajan Mistry

Merge request reports

Loading
Loading