Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
d29e73b
refactor(git): migrate GetRepositoryTree to NewTool pattern
SamMorrowDrums Dec 13, 2025
a12e2c4
refactor(security): migrate code_scanning, secret_scanning, dependabo…
SamMorrowDrums Dec 13, 2025
e14092e
refactor(discussions): migrate to NewTool pattern
SamMorrowDrums Dec 13, 2025
221ca8e
Refactor security_advisories tools to use NewTool pattern
SamMorrowDrums Dec 13, 2025
8e91837
refactor: convert projects, labels, and dynamic_tools to NewTool pattern
SamMorrowDrums Dec 13, 2025
963b26c
Add --features CLI flag for feature flag support
SamMorrowDrums Dec 13, 2025
46a694f
Add validation tests for tools, resources, and prompts metadata
SamMorrowDrums Dec 13, 2025
217bd12
Fix default toolsets behavior when not in dynamic mode
SamMorrowDrums Dec 13, 2025
17b80d9
refactor: address PR review feedback for toolsets
SamMorrowDrums Dec 14, 2025
c1bb4dd
refactor: Apply HandlerFunc pattern to resources for stateless NewToo…
SamMorrowDrums Dec 14, 2025
d3adf84
refactor: simplify ForMCPRequest switch cases
SamMorrowDrums Dec 14, 2025
70bd337
refactor(generate_docs): use strings.Builder and AllTools() iteration
SamMorrowDrums Dec 14, 2025
e7311b5
feat(toolsets): add AvailableToolsets() with exclude filter
SamMorrowDrums Dec 14, 2025
27d6afa
refactor(generate_docs): hoist success logging to generateAllDocs
SamMorrowDrums Dec 14, 2025
a1c19e2
refactor: consolidate toolset validation into ToolsetGroup
SamMorrowDrums Dec 14, 2025
f66d360
refactor: rename toolsets package to registry with builder pattern
SamMorrowDrums Dec 15, 2025
6c4f13b
fix: remove unnecessary type arguments in helper_test.go
SamMorrowDrums Dec 15, 2025
ccbb1fb
fix: restore correct behavior for --tools and --toolsets flags
SamMorrowDrums Dec 15, 2025
d6d8070
Move labels tools to issues toolset
SamMorrowDrums Dec 15, 2025
1a58695
Restore labels toolset with get_label in both issues and labels
SamMorrowDrums Dec 15, 2025
d9c7525
Fix instruction generation and capability advertisement
SamMorrowDrums Dec 15, 2025
edab448
Add tests for dynamic toolset management tools
SamMorrowDrums Dec 15, 2025
bfd541f
Advertise all capabilities in dynamic toolsets mode
SamMorrowDrums Dec 15, 2025
9a239e0
Improve conformance test with dynamic tool calls and JSON normalization
SamMorrowDrums Dec 15, 2025
3d6db39
Add conformance-report to .gitignore
SamMorrowDrums Dec 15, 2025
253e786
Add conformance test CI workflow
SamMorrowDrums Dec 15, 2025
301147e
Add map indexes for O(1) lookups in Registry
SamMorrowDrums Dec 15, 2025
ea40ee7
perf(registry): O(1) HasToolset lookup via pre-computed set
SamMorrowDrums Dec 15, 2025
039e82f
simplify: remove lazy toolsByName map - not needed for actual use cases
SamMorrowDrums Dec 15, 2025
bcf04f1
Add generic tool filtering mechanisms to registry package
Copilot Dec 16, 2025
0488fa0
docs: improve filter evaluation order and FilteredTools documentation
SamMorrowDrums Dec 16, 2025
f1c38da
Refactor GenerateToolsetsHelp() to use strings.Builder pattern
Copilot Dec 15, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
228 changes: 114 additions & 114 deletions pkg/github/git.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

ghErrors "github.com/github/github-mcp-server/pkg/errors"
"github.com/github/github-mcp-server/pkg/toolsets"
"github.com/github/github-mcp-server/pkg/translations"
"github.com/github/github-mcp-server/pkg/utils"
"github.com/google/go-github/v79/github"
Expand Down Expand Up @@ -37,140 +38,139 @@ type TreeResponse struct {
}

// GetRepositoryTree creates a tool to get the tree structure of a GitHub repository.
func GetRepositoryTree(getClient GetClientFn, t translations.TranslationHelperFunc) (mcp.Tool, mcp.ToolHandlerFor[map[string]any, any]) {
tool := mcp.Tool{
Name: "get_repository_tree",
Description: t("TOOL_GET_REPOSITORY_TREE_DESCRIPTION", "Get the tree structure (files and directories) of a GitHub repository at a specific ref or SHA"),
Annotations: &mcp.ToolAnnotations{
Title: t("TOOL_GET_REPOSITORY_TREE_USER_TITLE", "Get repository tree"),
ReadOnlyHint: true,
},
InputSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"owner": {
Type: "string",
Description: "Repository owner (username or organization)",
},
"repo": {
Type: "string",
Description: "Repository name",
},
"tree_sha": {
Type: "string",
Description: "The SHA1 value or ref (branch or tag) name of the tree. Defaults to the repository's default branch",
},
"recursive": {
Type: "boolean",
Description: "Setting this parameter to true returns the objects or subtrees referenced by the tree. Default is false",
Default: json.RawMessage(`false`),
},
"path_filter": {
Type: "string",
Description: "Optional path prefix to filter the tree results (e.g., 'src/' to only show files in the src directory)",
func GetRepositoryTree(t translations.TranslationHelperFunc) toolsets.ServerTool {
return NewTool(
mcp.Tool{
Name: "get_repository_tree",
Description: t("TOOL_GET_REPOSITORY_TREE_DESCRIPTION", "Get the tree structure (files and directories) of a GitHub repository at a specific ref or SHA"),
Annotations: &mcp.ToolAnnotations{
Title: t("TOOL_GET_REPOSITORY_TREE_USER_TITLE", "Get repository tree"),
ReadOnlyHint: true,
},
InputSchema: &jsonschema.Schema{
Type: "object",
Properties: map[string]*jsonschema.Schema{
"owner": {
Type: "string",
Description: "Repository owner (username or organization)",
},
"repo": {
Type: "string",
Description: "Repository name",
},
"tree_sha": {
Type: "string",
Description: "The SHA1 value or ref (branch or tag) name of the tree. Defaults to the repository's default branch",
},
"recursive": {
Type: "boolean",
Description: "Setting this parameter to true returns the objects or subtrees referenced by the tree. Default is false",
Default: json.RawMessage(`false`),
},
"path_filter": {
Type: "string",
Description: "Optional path prefix to filter the tree results (e.g., 'src/' to only show files in the src directory)",
},
},
Required: []string{"owner", "repo"},
},
Required: []string{"owner", "repo"},
},
}
func(deps ToolDependencies) mcp.ToolHandlerFor[map[string]any, any] {
return func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
owner, err := RequiredParam[string](args, "owner")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
repo, err := RequiredParam[string](args, "repo")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
treeSHA, err := OptionalParam[string](args, "tree_sha")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
recursive, err := OptionalBoolParamWithDefault(args, "recursive", false)
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
pathFilter, err := OptionalParam[string](args, "path_filter")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}

handler := mcp.ToolHandlerFor[map[string]any, any](
func(ctx context.Context, _ *mcp.CallToolRequest, args map[string]any) (*mcp.CallToolResult, any, error) {
owner, err := RequiredParam[string](args, "owner")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
repo, err := RequiredParam[string](args, "repo")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
treeSHA, err := OptionalParam[string](args, "tree_sha")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
recursive, err := OptionalBoolParamWithDefault(args, "recursive", false)
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
pathFilter, err := OptionalParam[string](args, "path_filter")
if err != nil {
return utils.NewToolResultError(err.Error()), nil, nil
}
client, err := deps.GetClient(ctx)
if err != nil {
return utils.NewToolResultError("failed to get GitHub client"), nil, nil
}

client, err := getClient(ctx)
if err != nil {
return utils.NewToolResultError("failed to get GitHub client"), nil, nil
}
// If no tree_sha is provided, use the repository's default branch
if treeSHA == "" {
repoInfo, repoResp, err := client.Repositories.Get(ctx, owner, repo)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get repository info",
repoResp,
err,
), nil, nil
}
treeSHA = *repoInfo.DefaultBranch
}

// If no tree_sha is provided, use the repository's default branch
if treeSHA == "" {
repoInfo, repoResp, err := client.Repositories.Get(ctx, owner, repo)
// Get the tree using the GitHub Git Tree API
tree, resp, err := client.Git.GetTree(ctx, owner, repo, treeSHA, recursive)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get repository info",
repoResp,
"failed to get repository tree",
resp,
err,
), nil, nil
}
treeSHA = *repoInfo.DefaultBranch
}
defer func() { _ = resp.Body.Close() }()

// Get the tree using the GitHub Git Tree API
tree, resp, err := client.Git.GetTree(ctx, owner, repo, treeSHA, recursive)
if err != nil {
return ghErrors.NewGitHubAPIErrorResponse(ctx,
"failed to get repository tree",
resp,
err,
), nil, nil
}
defer func() { _ = resp.Body.Close() }()

// Filter tree entries if path_filter is provided
var filteredEntries []*github.TreeEntry
if pathFilter != "" {
for _, entry := range tree.Entries {
if strings.HasPrefix(entry.GetPath(), pathFilter) {
filteredEntries = append(filteredEntries, entry)
// Filter tree entries if path_filter is provided
var filteredEntries []*github.TreeEntry
if pathFilter != "" {
for _, entry := range tree.Entries {
if strings.HasPrefix(entry.GetPath(), pathFilter) {
filteredEntries = append(filteredEntries, entry)
}
}
} else {
filteredEntries = tree.Entries
}
} else {
filteredEntries = tree.Entries
}

treeEntries := make([]TreeEntryResponse, len(filteredEntries))
for i, entry := range filteredEntries {
treeEntries[i] = TreeEntryResponse{
Path: entry.GetPath(),
Type: entry.GetType(),
Mode: entry.GetMode(),
SHA: entry.GetSHA(),
URL: entry.GetURL(),
treeEntries := make([]TreeEntryResponse, len(filteredEntries))
for i, entry := range filteredEntries {
treeEntries[i] = TreeEntryResponse{
Path: entry.GetPath(),
Type: entry.GetType(),
Mode: entry.GetMode(),
SHA: entry.GetSHA(),
URL: entry.GetURL(),
}
if entry.Size != nil {
treeEntries[i].Size = entry.Size
}
}
if entry.Size != nil {
treeEntries[i].Size = entry.Size

response := TreeResponse{
SHA: *tree.SHA,
Truncated: *tree.Truncated,
Tree: treeEntries,
TreeSHA: treeSHA,
Owner: owner,
Repo: repo,
Recursive: recursive,
Count: len(filteredEntries),
}
}

response := TreeResponse{
SHA: *tree.SHA,
Truncated: *tree.Truncated,
Tree: treeEntries,
TreeSHA: treeSHA,
Owner: owner,
Repo: repo,
Recursive: recursive,
Count: len(filteredEntries),
}
r, err := json.Marshal(response)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal response: %w", err)
}

r, err := json.Marshal(response)
if err != nil {
return nil, nil, fmt.Errorf("failed to marshal response: %w", err)
return utils.NewToolResultText(string(r)), nil, nil
}

return utils.NewToolResultText(string(r)), nil, nil
},
)

return tool, handler
}
19 changes: 11 additions & 8 deletions pkg/github/git_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import (

func Test_GetRepositoryTree(t *testing.T) {
// Verify tool definition once
mockClient := github.NewClient(nil)
tool, _ := GetRepositoryTree(stubGetClientFn(mockClient), translations.NullTranslationHelper)
require.NoError(t, toolsnaps.Test(tool.Name, tool))
toolDef := GetRepositoryTree(translations.NullTranslationHelper)
require.NoError(t, toolsnaps.Test(toolDef.Tool.Name, toolDef.Tool))

assert.Equal(t, "get_repository_tree", tool.Name)
assert.NotEmpty(t, tool.Description)
assert.Equal(t, "get_repository_tree", toolDef.Tool.Name)
assert.NotEmpty(t, toolDef.Tool.Description)

// Type assert the InputSchema to access its properties
inputSchema, ok := tool.InputSchema.(*jsonschema.Schema)
inputSchema, ok := toolDef.Tool.InputSchema.(*jsonschema.Schema)
require.True(t, ok, "expected InputSchema to be *jsonschema.Schema")
assert.Contains(t, inputSchema.Properties, "owner")
assert.Contains(t, inputSchema.Properties, "repo")
Expand Down Expand Up @@ -148,12 +147,16 @@ func Test_GetRepositoryTree(t *testing.T) {

for _, tc := range tests {
t.Run(tc.name, func(t *testing.T) {
_, handler := GetRepositoryTree(stubGetClientFromHTTPFn(tc.mockedClient), translations.NullTranslationHelper)
client := github.NewClient(tc.mockedClient)
deps := ToolDependencies{
GetClient: stubGetClientFn(client),
}
handler := toolDef.Handler(deps)

// Create the tool request
request := createMCPRequest(tc.requestArgs)

result, _, err := handler(context.Background(), &request, tc.requestArgs)
result, err := handler(context.Background(), &request)

if tc.expectError {
require.NoError(t, err)
Expand Down
Loading