diff --git a/internal/ghmcp/server.go b/internal/ghmcp/server.go index ac7a90b57d..7ba43257cc 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) @@ -229,6 +233,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/feature_flags.go b/pkg/github/feature_flags.go index 88e7218af1..cd08b9e495 100644 --- a/pkg/github/feature_flags.go +++ b/pkg/github/feature_flags.go @@ -141,3 +141,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 dfa5828d26..b79b9c2540 100644 --- a/pkg/github/feature_flags_test.go +++ b/pkg/github/feature_flags_test.go @@ -309,3 +309,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/http/server.go b/pkg/http/server.go index 320df45ef0..145b864a30 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -10,6 +10,7 @@ import ( "os" "os/signal" "strconv" + "strings" "syscall" "time" @@ -167,6 +168,22 @@ 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, ", ")) + } + + 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) 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 e829f08e62..5a494c946d 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 // configuration preserves tool availability before per-method registration narrowing. @@ -70,6 +72,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") + } + }) + } +}