Skip to content

Commit 886025a

Browse files
committed
add missing features.go
1 parent d16f98b commit 886025a

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

pkg/http/features.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package http
2+
3+
import (
4+
"context"
5+
"slices"
6+
7+
"github.com/github/github-mcp-server/pkg/github"
8+
"github.com/github/github-mcp-server/pkg/inventory"
9+
)
10+
11+
// KnownFeatureFlags are the feature flags that can be enabled via X-MCP-Features header.
12+
var KnownFeatureFlags = []string{
13+
github.FeatureFlagConsolidatedProjects,
14+
github.FeatureFlagConsolidatedActions,
15+
}
16+
17+
// ComposeFeatureChecker combines header-based feature flags with a static checker.
18+
func ComposeFeatureChecker(headerFeatures []string, staticChecker inventory.FeatureFlagChecker) inventory.FeatureFlagChecker {
19+
if len(headerFeatures) == 0 && staticChecker == nil {
20+
return nil
21+
}
22+
23+
// Only accept header features that are in the known list
24+
headerSet := make(map[string]bool, len(headerFeatures))
25+
for _, f := range headerFeatures {
26+
if slices.Contains(KnownFeatureFlags, f) {
27+
headerSet[f] = true
28+
}
29+
}
30+
31+
return func(ctx context.Context, flag string) (bool, error) {
32+
// Header-based: static string matching
33+
if headerSet[flag] {
34+
return true, nil
35+
}
36+
// Static checker
37+
if staticChecker != nil {
38+
return staticChecker(ctx, flag)
39+
}
40+
return false, nil
41+
}
42+
}

0 commit comments

Comments
 (0)