FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Add Repository Tree Navigation Tool by natagdunbar · Pull Request #1164 · github/github-mcp-server · GitHub

Add Repository Tree Navigation Tool - #1164

Merged
natagdunbar merged 9 commits into
mainfrom
natagdunbar/add-repo-nav-tool
Nov 10, 2025
Merged

Add Repository Tree Navigation Tool#1164
natagdunbar merged 9 commits into
mainfrom
natagdunbar/add-repo-nav-tool

Conversation

natagdunbar commented Sep 30, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

Closes: https://github.com/github/copilot-agent-services/issues/651

This PR adds a new get_repository_tree tool to the GitHub MCP Server, enabling natural language exploration of repository file structures.

What's Added

New Tool: get_repository_tree - Retrieves repository file/directory structure using GitHub's Git Tree API
Response Types: TreeResponse and TreeEntryResponse structs for structured data
Tool Registration: Added to the "repos" toolset alongside existing repository tools
Recursive Exploration: Optional recursive directory traversal
Path Filtering: Filter results by directory prefix (e.g., src/, pkg)
Branch/SHA Support: Query specific branches, tags, or commit SHAs
Rich Metadata: Returns file types, modes, SHAs, and URLs

Impact

This addresses the navigation capability gap between VS Code agent mode (which has CLI access for ls) and dotcom chat, enabling AI assistants to naturally explore and understand repository structures through conversational interfaces.

I was able to use this tool in VS code:



natagdunbar marked this pull request as ready for review September 30, 2025 20:40
natagdunbar requested a review from a team as a code owner September 30, 2025 20:40
Copilot AI review requested due to automatic review settings September 30, 2025 20:40
natagdunbar changed the title add repo nav tool Add Repository Tree Navigation Tool Sep 30, 2025

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Pull Request Overview

This PR adds a new get_repository_tree tool to the GitHub MCP Server, enabling AI assistants to explore and understand repository file structures through natural language interfaces. This addresses the navigation capability gap between VS Code agent mode and dotcom chat.

  • Adds GetRepositoryTree function with support for recursive exploration and path filtering
  • Implements comprehensive test coverage for the new tool functionality
  • Updates tool registration and documentation to include the new capability

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
pkg/github/tools.go Registers the new GetRepositoryTree tool in the repos toolset
pkg/github/repositories.go Implements the GetRepositoryTree function with GitHub Git Tree API integration
pkg/github/repositories_test.go Adds comprehensive test cases for the new tool including error scenarios
pkg/github/toolsnaps/get_repository_tree.snap Tool definition snapshot for testing
README.md Documents the new tool parameters and usage

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pkg/github/repositories.go Outdated
Comment thread pkg/github/repositories.go Outdated
Comment on lines +801 to +803
response := TreeResponse{
SHA: *tree.SHA,
Truncated: *tree.Truncated,

Copilot AI Sep 30, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Potential nil pointer dereference when dereferencing tree.SHA and tree.Truncated from the GitHub API response without null checks.

Suggested change
response := TreeResponse{
SHA: *tree.SHA,
Truncated: *tree.Truncated,
var sha string
if tree.SHA != nil {
sha = *tree.SHA
} else {
sha = ""
}
var truncated bool
if tree.Truncated != nil {
truncated = *tree.Truncated
} else {
truncated = false
}
response := TreeResponse{
SHA: sha,
Truncated: truncated,

Copilot uses AI. Check for mistakes.

iancanderson left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

It seems checking for a nil tree entry URL might be necessary since URL isn't listed as required in the response schema (even though that's surprising..).

Other than a nil check for that, this looks good to me!

Comment thread pkg/github/repositories.go Outdated
}

// Get the tree using the GitHub Git Tree API
tree, resp, err := client.Git.GetTree(ctx, owner, repo, treeSHA, recursive)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Does the client handle recursive: false such that it won't return recursive entries? The docs suggest that we'll need to omit the recursive parameter completely in order to prevent recursion:

Setting this parameter to any value returns the objects or subtrees referenced by the tree specified in :tree_sha. For example, setting recursive to any of the following will enable returning objects or subtrees: 0, 1, "true", and "false". Omit this parameter to prevent recursively returning objects or subtrees.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Ah, yep, it looks like the client will only include the recursive parameter if it's true: https://github.com/google/go-github/blob/46f1bf23e6f9659d04f9eaebff5d25902cddfd8e/github/git_trees.go#L102-L104

👍

Comment thread pkg/github/repositories.go Outdated
Comment thread pkg/github/repositories.go Outdated
iancanderson previously approved these changes Oct 1, 2025

iancanderson left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

LGTM!

Comment thread pkg/github/repositories.go Outdated

omgitsads left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Changes look good, but I would like to see this (and eventually all Git tooling) moved out to a separate git toolset. Can you move this out to a new toolset as we discussed.

omgitsads left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Looks good, just one last change to annotate the repo Get error!

Comment thread pkg/github/git.go Outdated
natagdunbar requested a review from omgitsads October 29, 2025 22:21
omgitsads previously approved these changes Oct 30, 2025

SamMorrowDrums left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Re-approve after build error fixes. Have not reviewed, but I trust @omgitsads review.

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants


Back | FazBrowse Home | New Git URL