Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
8 changes: 8 additions & 0 deletions internal/ghmcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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)
Expand Down
14 changes: 14 additions & 0 deletions pkg/github/feature_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
11 changes: 11 additions & 0 deletions pkg/github/feature_flags_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}),
)
}
17 changes: 17 additions & 0 deletions pkg/http/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"os"
"os/signal"
"strconv"
"strings"
"syscall"
"time"

Expand Down Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions pkg/inventory/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
}
Expand Down
9 changes: 9 additions & 0 deletions pkg/inventory/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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"
Expand Down
49 changes: 49 additions & 0 deletions pkg/inventory/registry_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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")
}
})
}
}