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
-
Check out the branch and restart Rails, since the tool registry is memoized:
gdk restart rails-web -
Create a personal access token with the
mcpscope: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" -
Confirm the tool is advertised, by looking for
list_repository_treein 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"}' -
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:
entrieslists the subdirectories and files underfileswithtype,path, andmode, plus apageInfoobject. -
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)