From 354ed5fd14c7e9417082ac3021caa69f7075b98c Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Mon, 9 Nov 2026 06:52:21 -0400 Subject: [PATCH 1/2] fix: warn on unrecognized --exclude-tools and --features names A misspelled --exclude-tools entry matched nothing and left the tool enabled with no signal, and unknown --features names were dropped silently. Log a warning for both at startup, like unrecognized toolsets. Fixes #3761 Co-Authored-By: Claude Sonnet 5.5 --- internal/ghmcp/server.go | 4 +++ pkg/github/feature_flags.go | 14 +++++++++ pkg/github/feature_flags_test.go | 11 +++++++ pkg/github/server.go | 4 +++ pkg/http/server.go | 5 ++++ pkg/inventory/builder.go | 15 ++++++++++ pkg/inventory/registry.go | 9 ++++++ pkg/inventory/registry_test.go | 49 ++++++++++++++++++++++++++++++++ 8 files changed, 111 insertions(+) diff --git a/internal/ghmcp/server.go b/internal/ghmcp/server.go index c826b6d0ea..32030a4954 100644 --- a/internal/ghmcp/server.go +++ b/internal/ghmcp/server.go @@ -182,6 +182,10 @@ func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Se return nil, fmt.Errorf("failed to create GitHub clients: %w", err) } + if unrecognized := github.UnrecognizedFeatureFlags(cfg.EnabledFeatures); len(unrecognized) > 0 { + cfg.Logger.Warn("Warning: unrecognized features ignored", "features", strings.Join(unrecognized, ", ")) + } + // Create feature checker — resolves explicit features + insiders expansion featureChecker := createFeatureChecker(cfg.EnabledFeatures, cfg.InsidersMode) diff --git a/pkg/github/feature_flags.go b/pkg/github/feature_flags.go index 4957c2f71e..04bd244e14 100644 --- a/pkg/github/feature_flags.go +++ b/pkg/github/feature_flags.go @@ -132,3 +132,17 @@ func ResolveFeatureFlags(enabledFeatures []string, insidersMode bool) map[string } return effective } + +// UnrecognizedFeatureFlags returns the entries of enabledFeatures that are not in +// AllowedFeatureFlags, preserving order and dropping duplicates. ResolveFeatureFlags +// ignores them silently; callers with trusted operator input (the --features CLI flag) +// can use this to warn about typos. +func UnrecognizedFeatureFlags(enabledFeatures []string) []string { + var unrecognized []string + for _, feature := range enabledFeatures { + if !slices.Contains(AllowedFeatureFlags, feature) && !slices.Contains(unrecognized, feature) { + unrecognized = append(unrecognized, feature) + } + } + return unrecognized +} diff --git a/pkg/github/feature_flags_test.go b/pkg/github/feature_flags_test.go index 173a8cfd12..f66381c527 100644 --- a/pkg/github/feature_flags_test.go +++ b/pkg/github/feature_flags_test.go @@ -298,3 +298,14 @@ func TestThreadResolutionReasonToolVariants(t *testing.T) { }) } } + +func TestUnrecognizedFeatureFlags(t *testing.T) { + t.Parallel() + + assert.Empty(t, UnrecognizedFeatureFlags(nil)) + assert.Empty(t, UnrecognizedFeatureFlags(AllowedFeatureFlags)) + assert.Equal(t, + []string{"not_a_feature", "csv-output"}, + UnrecognizedFeatureFlags([]string{FeatureFlagCSVOutput, "not_a_feature", "csv-output", "not_a_feature"}), + ) +} diff --git a/pkg/github/server.go b/pkg/github/server.go index 78a66f2582..5384fa15ed 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -114,6 +114,10 @@ func NewMCPServer(ctx context.Context, cfg *MCPServerConfig, deps ToolDependenci cfg.Logger.Warn("Warning: unrecognized toolsets ignored", "toolsets", strings.Join(unrecognized, ", ")) } + if unrecognized := inv.UnrecognizedExcludeTools(); len(unrecognized) > 0 { + cfg.Logger.Warn("Warning: unrecognized excluded tools ignored; these tools are not disabled", "tools", strings.Join(unrecognized, ", ")) + } + // Register GitHub tools/resources/prompts from the inventory. inv.RegisterAll(ctx, ghServer, deps, cfg.ToolHandlerMiddleware...) diff --git a/pkg/http/server.go b/pkg/http/server.go index 08e76b48e7..cb7c13ae7b 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -10,6 +10,7 @@ import ( "os" "os/signal" "strconv" + "strings" "syscall" "time" @@ -166,6 +167,10 @@ func RunHTTPServer(cfg ServerConfig) error { repoAccessOpts = append(repoAccessOpts, lockdown.WithTTL(*cfg.RepoAccessCacheTTL)) } + if unrecognized := github.UnrecognizedFeatureFlags(cfg.EnabledFeatures); len(unrecognized) > 0 { + logger.Warn("Warning: unrecognized features ignored", "features", strings.Join(unrecognized, ", ")) + } + featureChecker := createHTTPFeatureChecker(cfg.EnabledFeatures, cfg.InsidersMode) scopeFetcher := scopes.NewFetcher(apiHost, scopes.FetcherOptions{}) inventoryFactory, err := NewDefaultInventoryFactory(&cfg, t, featureChecker, scopeFetcher) diff --git a/pkg/inventory/builder.go b/pkg/inventory/builder.go index e70df0eed3..5511e40f7f 100644 --- a/pkg/inventory/builder.go +++ b/pkg/inventory/builder.go @@ -45,6 +45,7 @@ type Builder struct { toolsetIDs []string // raw input, processed at Build() toolsetIDsIsNil bool // tracks if nil was passed (nil = defaults) additionalTools []string // raw input, processed at Build() + excludeTools []string // cleaned input, checked against the inventory at Build() featureChecker FeatureFlagChecker filters []ToolFilter // filters to apply to all tools generateInstructions bool @@ -154,6 +155,7 @@ func (b *Builder) WithFilter(filter ToolFilter) *Builder { func (b *Builder) WithExcludeTools(toolNames []string) *Builder { cleaned := cleanTools(toolNames) if len(cleaned) > 0 { + b.excludeTools = append(b.excludeTools, cleaned...) b.filters = append(b.filters, CreateExcludeToolsFilter(cleaned)) } return b @@ -250,6 +252,19 @@ func (b *Builder) Build() (*Inventory, error) { } } + // Track excluded tool names that match nothing so callers can warn about + // typos. Unlike WithTools this is not an error: the exclusion is simply a no-op. + seenExcluded := make(map[string]bool, len(b.excludeTools)) + for _, name := range b.excludeTools { + if seenExcluded[name] || validToolNames[name] { + continue + } + seenExcluded[name] = true + // Deprecated aliases are not exempt: the exclude filter compares exact + // tool names, so excluding an alias removes nothing. + r.unrecognizedExcludeTools = append(r.unrecognizedExcludeTools, name) + } + if b.generateInstructions { r.instructions = generateInstructions(r) } diff --git a/pkg/inventory/registry.go b/pkg/inventory/registry.go index e85d8b607c..67e18b0fb4 100644 --- a/pkg/inventory/registry.go +++ b/pkg/inventory/registry.go @@ -58,6 +58,8 @@ type Inventory struct { filters []ToolFilter // unrecognizedToolsets holds toolset IDs that were requested but don't match any registered toolsets unrecognizedToolsets []string + // unrecognizedExcludeTools holds names passed to WithExcludeTools that match no registered tool + unrecognizedExcludeTools []string // server instructions hold high-level instructions for agents to use the server effectively instructions string } @@ -68,6 +70,13 @@ func (r *Inventory) UnrecognizedToolsets() []string { return r.unrecognizedToolsets } +// UnrecognizedExcludeTools returns tool names that were passed to WithExcludeTools but +// match no registered tool by exact name (deprecated aliases are not resolved by the +// exclude filter). Such an entry excludes nothing, so this is useful for warning users about typos. +func (r *Inventory) UnrecognizedExcludeTools() []string { + return r.unrecognizedExcludeTools +} + // MCP method constants for use with ForMCPRequest. const ( MCPMethodInitialize = "initialize" diff --git a/pkg/inventory/registry_test.go b/pkg/inventory/registry_test.go index ffae37b169..a6381c5e19 100644 --- a/pkg/inventory/registry_test.go +++ b/pkg/inventory/registry_test.go @@ -4,11 +4,13 @@ import ( "context" "encoding/json" "fmt" + "strings" "testing" "time" ghcontext "github.com/github/github-mcp-server/v2/pkg/context" "github.com/modelcontextprotocol/go-sdk/mcp" + "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" ) @@ -2557,3 +2559,50 @@ func TestForMCPRequest_PreservesInstructions(t *testing.T) { "instructions must be preserved for %s (server identity)", m) } } + +func TestUnrecognizedExcludeTools(t *testing.T) { + tools := []ServerTool{ + mockTool("tool1", "toolset1", true), + mockTool("tool2", "toolset1", true), + } + aliases := map[string]string{"old_tool": "tool1"} + + tests := []struct { + name string + excluded []string + expected []string + }{ + {name: "nothing excluded", excluded: nil, expected: nil}, + {name: "all known", excluded: []string{"tool1", "tool2"}, expected: nil}, + {name: "deprecated alias is not resolved", excluded: []string{"old_tool"}, expected: []string{"old_tool"}}, + {name: "typo reported", excluded: []string{"tool1", "tool_2"}, expected: []string{"tool_2"}}, + {name: "duplicates and whitespace cleaned", excluded: []string{" nope ", "nope", "tool1"}, expected: []string{"nope"}}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + inv, err := NewBuilder(). + SetTools(tools). + WithDeprecatedAliases(aliases). + WithToolsets([]string{"all"}). + WithExcludeTools(tt.excluded). + Build() + require.NoError(t, err) + assert.Equal(t, tt.expected, inv.UnrecognizedExcludeTools()) + // The typo must stay a no-op: known tools are still excluded, unknown ones change nothing. + for _, name := range tt.excluded { + for _, tool := range inv.AvailableTools(context.Background()) { + assert.NotEqual(t, strings.TrimSpace(name), tool.Tool.Name) + } + } + if tt.name == "deprecated alias is not resolved" { + // Excluding an alias does not exclude the canonical tool it points to. + var names []string + for _, tool := range inv.AvailableTools(context.Background()) { + names = append(names, tool.Tool.Name) + } + assert.Contains(t, names, "tool1") + } + }) + } +} From 6e3fbaec4e5a68fe599e9f8d6f153682d6b6de26 Mon Sep 17 00:00:00 2001 From: Alex Castillo Date: Mon, 9 Nov 2026 07:09:20 -0400 Subject: [PATCH 2/2] fix: warn on unrecognized --exclude-tools in HTTP mode and keep stdio warning in ghmcp --- internal/ghmcp/server.go | 4 ++++ pkg/github/server.go | 4 ---- pkg/http/server.go | 12 ++++++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/internal/ghmcp/server.go b/internal/ghmcp/server.go index 32030a4954..fd4308564d 100644 --- a/internal/ghmcp/server.go +++ b/internal/ghmcp/server.go @@ -231,6 +231,10 @@ func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Se return nil, fmt.Errorf("failed to build inventory: %w", err) } + if unrecognized := inventory.UnrecognizedExcludeTools(); len(unrecognized) > 0 { + cfg.Logger.Warn("Warning: unrecognized excluded tools ignored; these tools are not disabled", "tools", strings.Join(unrecognized, ", ")) + } + ghServer, err := github.NewMCPServer(ctx, &cfg, deps, inventory) if err != nil { return nil, fmt.Errorf("failed to create GitHub MCP server: %w", err) diff --git a/pkg/github/server.go b/pkg/github/server.go index 5384fa15ed..78a66f2582 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -114,10 +114,6 @@ func NewMCPServer(ctx context.Context, cfg *MCPServerConfig, deps ToolDependenci cfg.Logger.Warn("Warning: unrecognized toolsets ignored", "toolsets", strings.Join(unrecognized, ", ")) } - if unrecognized := inv.UnrecognizedExcludeTools(); len(unrecognized) > 0 { - cfg.Logger.Warn("Warning: unrecognized excluded tools ignored; these tools are not disabled", "tools", strings.Join(unrecognized, ", ")) - } - // Register GitHub tools/resources/prompts from the inventory. inv.RegisterAll(ctx, ghServer, deps, cfg.ToolHandlerMiddleware...) diff --git a/pkg/http/server.go b/pkg/http/server.go index cb7c13ae7b..6096b4c701 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -171,6 +171,18 @@ func RunHTTPServer(cfg ServerConfig) error { logger.Warn("Warning: unrecognized features ignored", "features", strings.Join(unrecognized, ", ")) } + if len(cfg.ExcludeTools) > 0 { + // Check against the full tool universe: the per-request inventories are + // built from an already-filtered tool list and would report real tools. + universe, err := github.NewInventory(t).WithExcludeTools(cfg.ExcludeTools).Build() + if err != nil { + return fmt.Errorf("failed to build inventory: %w", err) + } + if unrecognized := universe.UnrecognizedExcludeTools(); len(unrecognized) > 0 { + logger.Warn("Warning: unrecognized excluded tools ignored; these tools are not disabled", "tools", strings.Join(unrecognized, ", ")) + } + } + featureChecker := createHTTPFeatureChecker(cfg.EnabledFeatures, cfg.InsidersMode) scopeFetcher := scopes.NewFetcher(apiHost, scopes.FetcherOptions{}) inventoryFactory, err := NewDefaultInventoryFactory(&cfg, t, featureChecker, scopeFetcher)