Add list_repository_tree MCP tool

What does this MR do and why?

Adds a list_repository_tree MCP server tool so agents can see which files and directories exist in a repository before reading or editing them. It keeps the public tool name agents already use.

The tool is a GraphQL-backed tool pair over the existing paginatedTree field. Callers identify the project with exactly one of url or project_id, then optionally narrow the listing with path, ref and recursive, and page through it with after.

It is read only, and returns entry metadata only, never file contents.

How to test locally

  1. Check out the branch and restart Rails, since the tool registry is memoized:

    gdk restart rails-web
  2. Create a personal access token with the mcp scope:

    bundle exec rails runner "u=User.find_by_username('root'); t=u.personal_access_tokens.create!(name: 'mcp-test', scopes: [:mcp], expires_at: 2.days.from_now); raw='glpat-'+SecureRandom.hex(20); t.set_token(raw); t.save!; puts raw"
  3. Confirm the tool is advertised, by looking for list_repository_tree in the response:

    curl -s -X POST http://gdk.test:3000/api/v4/mcp -H "Authorization: Bearer <TOKEN>" -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list"}'
  4. Call the tool:

    curl -s -X POST http://gdk.test:3000/api/v4/mcp -H "Authorization: Bearer <TOKEN>" -H 'Content-Type: application/json' -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"list_repository_tree","arguments":{"project_id":"gitlab-org/gitlab-test","path":"files"}}}'

    Expected: entries lists the subdirectories and files under files with type, path, and mode, plus a pageInfo object.

  5. Optionally try "recursive":true, a bad ref, or a bad path to see the specific error messages. On a repository with more than 100 entries, pass "after":"<endCursor>" from the previous response to fetch the next page.

Closes #605873 (closed)

Edited by Amr Taha

Merge request reports

Loading
Loading