Skip to content

Conversation

@SamMorrowDrums
Copy link
Collaborator

Summary

Refactors the pkg/toolsets package to pkg/registry with improved organization and a builder pattern API.

Changes

Package Rename

  • Renamed pkg/toolsetspkg/registry
  • Updated all imports across the codebase (~45 files)

File Organization

Split the monolithic toolsets.go into focused files:

File Purpose
registry.go Core Registry struct, MCP method constants, ForMCPRequest optimization
builder.go Builder pattern for constructing Registry instances
filters.go Tool/resource/prompt filtering logic
server_tool.go ServerTool, ToolsetMetadata, ToolsetID types
resources.go ServerResourceTemplate type
prompts.go ServerPrompt type
errors.go ToolsetDoesNotExistError, ToolDoesNotExistError

Builder Pattern API

New fluent builder API for constructing registries:

registry := registry.NewBuilder().
    SetTools(tools...).
    SetResources(resources...).
    SetPrompts(prompts...).
    WithToolsets(enabledToolsets).
    WithReadOnly(true).
    WithFeatureChecker(checker).
    Build()

Lint Fix

  • Renamed RegistryBuilderBuilder to avoid Go stuttering lint error (registry.RegistryBuilder)

Testing

  • All existing tests pass
  • script/lint passes
  • go build ./... succeeds

Stack

This PR is stacked on #1602

- Rename pkg/toolsets to pkg/registry (better reflects its purpose)
- Split monolithic toolsets.go into focused files:
  - registry.go: Core Registry struct and MCP methods
  - builder.go: Builder pattern for creating Registry instances
  - filters.go: All filtering logic (toolsets, read-only, feature flags)
  - resources.go: ServerResourceTemplate type
  - prompts.go: ServerPrompt type
  - errors.go: Error types
  - server_tool.go: ServerTool and ToolsetMetadata (existing)
- Fix lint: Rename RegistryBuilder to Builder (avoid stuttering)
- Update all imports across ~45 files

This refactoring improves code organization and makes the registry's
purpose clearer. The builder pattern provides a clean API:

  reg := registry.NewBuilder().
      SetTools(tools).
      WithReadOnly(true).
      WithToolsets([]string{"repos"}).
      Build()
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner December 15, 2025 14:35
Copilot AI review requested due to automatic review settings December 15, 2025 14:35
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR refactors the pkg/toolsets package to pkg/registry with improved organization and a builder pattern API. The main changes include renaming the package, splitting the monolithic toolsets.go into focused files (registry.go, builder.go, filters.go, etc.), introducing a builder pattern for constructing Registry instances, and converting ToolDependencies from a struct to an interface with a BaseDeps implementation.

Key Changes

  • Package rename: pkg/toolsetspkg/registry with ~45 file imports updated
  • Builder pattern: New NewBuilder().SetTools().Build() API replacing direct NewRegistry().SetTools()
  • ToolDependencies refactor: Changed from struct to interface with BaseDeps implementation for better flexibility

Reviewed changes

Copilot reviewed 56 out of 56 changed files in this pull request and generated no comments.

Show a summary per file
File Description
pkg/registry/registry.go Core Registry struct, MCP constants, and main registry operations
pkg/registry/builder.go Builder pattern implementation with fluent API
pkg/registry/filters.go Tool/resource/prompt filtering logic extraction
pkg/registry/server_tool.go ServerTool type (package declaration change only)
pkg/registry/resources.go ServerResourceTemplate and related types
pkg/registry/prompts.go ServerPrompt type definitions
pkg/registry/errors.go Error type definitions
pkg/registry/registry_test.go Test updates for builder pattern
pkg/github/dependencies.go ToolDependencies struct→interface, BaseDeps implementation
pkg/github/*_test.go Test updates to use BaseDeps
internal/ghmcp/server.go Server setup refactoring with new builder pattern
e2e/e2e_test.go E2E test updates for builder pattern
cmd/github-mcp-server/generate_docs.go Documentation generation updates

// - Runtime toolset enabling for dynamic toolsets mode
type Registry struct {
// tools holds all tools in this group
tools []ServerTool
Copy link
Contributor

Choose a reason for hiding this comment

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

Can each of these collections be a map already?

func (r *Registry) ToolsetIDs() []ToolsetID {
seen := make(map[ToolsetID]bool)
for i := range r.tools {
seen[r.tools[i].Toolset.ID] = true
Copy link
Contributor

Choose a reason for hiding this comment

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

It doesn't need to be a map, we can use a set here and just check if the id is already there. (Although in go it's not such a big difference, set is anyway a map ;__;)

Two behavioral regressions were fixed in resolveEnabledToolsets():

1. When --tools=X is used without --toolsets, the server should only
   register the specified tools, not the default toolsets. Now returns
   an empty slice instead of nil when EnabledTools is set.

2. When --toolsets=all --dynamic-toolsets is used, the 'all' and 'default'
   pseudo-toolsets should be removed so only the dynamic management tools
   are registered. This matches the original pre-refactor behavior.
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.

3 participants