f929c58c6b
* Add CSV output for list tools under insiders mode * fix: resolve rebase feature flag conflicts Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Simplify feature-flag handling: collapse CSV dual-variant + skip filtering when no checker (#2516) * refactor: generic toolset+name sort, clarify feature flag intent Address review feedback on #2450: - Collapse the three near-identical sort helpers in pkg/inventory/filters.go into a generic sortByToolsetThenName so adding new inventory item types doesn't require copying the comparator. - Expand the doc comments on the three *WithoutFeatureFiltering helpers to spell out why they exist: HTTP mode builds a static (process-wide) inventory as an upper bound, but per-request feature flags from headers (X-MCP-Features, X-MCP-Insiders) are evaluated later, so feature-flagged variants must be preserved here. - Strengthen the doc comment on ResolveFeatureFlags to make the contract explicit: user-supplied flags are validated against AllowedFeatureFlags, but insiders expansion deliberately is not — InsidersFeatureFlags may include server-controlled flags that are not user-toggleable. CORS comments are intentionally left for the PR author. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs(feature-flags): clarify allowed and insiders sets are independent Also add tests covering: - a user-toggleable flag (FeatureFlagIssuesGranular) that insiders does not turn on automatically - insiders mode not turning on user-only allowed flags Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(inventory): collapse three *WithoutFeatureFiltering helpers into StaticUpperBound The three parallel methods (AvailableToolsWithoutFeatureFiltering, AvailableResourceTemplatesWithoutFeatureFiltering, AvailablePromptsWithoutFeatureFiltering) were always called as a triple in exactly two places: HTTP buildStaticInventory and its test mirror. They exist because the dual-variant pattern (sibling tools with mirrored FeatureFlagEnable / FeatureFlagDisable on the same name, e.g. CSV output) makes feature filtering at static-build time impossible — both variants must be kept and resolved per-request. Replace the three with one method, Inventory.StaticUpperBound(ctx), that returns (tools, resources, prompts) and carries the rationale in its doc comment. Reduces API surface, eliminates the triplication, and makes the single "skip feature filtering" concept obvious to readers. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor: simplify feature-flag handling Two related simplifications, both about treating insiders as a meta flag that expands once at startup and then stops mattering: - Collapse CSV's dual-variant pattern into a single tool whose handler performs a runtime feature-flag check via deps.IsFeatureEnabled. CSV is a pure response-format toggle, not a schema change, so it does not need the dual-name pattern that genuine schema variants (granular issues/PRs) still use. - When no feature checker is installed, skip feature-flag filtering and return the full upper bound. The static HTTP inventory now uses plain AvailableTools/Resources/Prompts; the per-request inventory always installs a checker, so MCP registration (which serves a tool name once) always sees a deduplicated set. The bespoke StaticUpperBound helper and the isToolEnabledWithFeatureFlags split go away. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * ci(mcp-diff): add insiders + per-feature configs The mcp-diff matrix now includes: - --insiders (and --insiders --read-only) - one config per github.AllowedFeatureFlags entry, generated by script/print-mcp-diff-configs so new user-controllable flags get diffed automatically without editing the workflow Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs(insiders): explain feature-flag resolution for contributors Adds a 'How feature flags are resolved' section covering: - Insiders is a meta flag, like 'all'/'default' for toolsets - User input -> allowlist filter -> insiders expansion -> server-side fallback (remote only) - AllowedFeatureFlags vs InsidersFeatureFlags are independent - How to add a new feature flag, including the TestGitHubPackageDoesNotReadInsidersMode guard Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * refactor(inventory): make feature-flag gating a regular ToolFilter Move tool feature-flag evaluation out of isToolEnabled and into a ToolFilter installed at the head of the pipeline by Build() when WithFeatureChecker received a non-nil checker. The 'no checker = no filtering' contract is now expressed structurally (the filter isn't installed) instead of by a runtime nil check inside the helper. Resources and prompts have no filter pipeline, so they call the now-pure featureFlagAllowed helper behind an explicit r.featureChecker != nil guard at the iteration site. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * perf(inventory): cache extracted toolset IDs in sort comparator Avoid evaluating the extractor closures up to three times per comparison. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: correct MCP features header in cors * docs: regenerate README for CSV output toolset Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * fix: remove duplicate MCPFeaturesHeader from CORS headers * ci(mcp-diff): add streamable-http job with header-based configs Adds a sibling mcp-diff-http job that exercises the streamable-http transport against a shared HTTP server, with per-config settings supplied via X-MCP-* request headers — mirroring how the remote server is invoked in production (server-side defaults + per-user header overrides). The config generator gains a -transport flag: - stdio (default, unchanged behaviour) - http-headers (emits headers-only configs targeting a shared server) Two new combined entries layer multiple headers together as a smoke test for header-merging regressions. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * docs: regenerate after merging main Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Sam Morrow <info@sam-morrow.com> Co-authored-by: sammorrowdrums <sammorrowdrums@github.com>
218 lines
6.3 KiB
Go
218 lines
6.3 KiB
Go
// Command print-mcp-diff-configs emits the configuration matrix consumed by
|
|
// the mcp-server-diff GitHub Action. The matrix is composed of three parts:
|
|
//
|
|
// 1. Hand-curated baseline configs (default, read-only, common toolset combos)
|
|
// 2. Insiders configs (--insiders, --insiders --read-only) — meta flag that
|
|
// expands to the curated insiders feature set
|
|
// 3. One config per entry in github.AllowedFeatureFlags — automatically kept
|
|
// in sync with the Go source so any new user-controllable feature flag
|
|
// gets diffed without touching the workflow
|
|
//
|
|
// The same logical matrix is rendered for two transports, selected by
|
|
// -transport:
|
|
//
|
|
// stdio Default. Args are appended to the action's top-level
|
|
//
|
|
// start_command (one stdio process per config).
|
|
//
|
|
// http-headers streamable-http transport against a shared HTTP server. The
|
|
//
|
|
// server is started once with no extra flags and every config
|
|
// provides its settings via X-MCP-* request headers, mirroring
|
|
// how the remote server is invoked in production (server-side
|
|
// defaults + per-user header overrides).
|
|
//
|
|
// Usage:
|
|
//
|
|
// go run ./script/print-mcp-diff-configs
|
|
// go run ./script/print-mcp-diff-configs -transport http-headers
|
|
package main
|
|
|
|
import (
|
|
"encoding/json"
|
|
"flag"
|
|
"fmt"
|
|
"os"
|
|
"sort"
|
|
"strings"
|
|
|
|
"github.com/github/github-mcp-server/pkg/github"
|
|
mcphdr "github.com/github/github-mcp-server/pkg/http/headers"
|
|
)
|
|
|
|
type config struct {
|
|
Name string `json:"name"`
|
|
Args string `json:"args,omitempty"`
|
|
Transport string `json:"transport,omitempty"`
|
|
ServerURL string `json:"server_url,omitempty"`
|
|
Headers map[string]string `json:"headers,omitempty"`
|
|
}
|
|
|
|
// baseEntry describes one logical configuration in transport-agnostic form.
|
|
// settings are translated to either CLI flags or X-MCP-* headers depending on
|
|
// the target transport.
|
|
type baseEntry struct {
|
|
name string
|
|
settings settings
|
|
}
|
|
|
|
type settings struct {
|
|
toolsets string // comma-separated, "" for defaults
|
|
tools string
|
|
excludeTools string
|
|
features string
|
|
readOnly bool
|
|
insiders bool
|
|
lockdown bool
|
|
}
|
|
|
|
const httpServerURL = "http://localhost:8082/mcp"
|
|
|
|
func main() {
|
|
transport := flag.String("transport", "stdio", "Transport to target: stdio or http-headers")
|
|
flag.Parse()
|
|
|
|
entries := baseEntries()
|
|
|
|
var out []config
|
|
switch *transport {
|
|
case "stdio":
|
|
for _, e := range entries {
|
|
out = append(out, config{Name: e.name, Args: e.settings.toArgs()})
|
|
}
|
|
case "http-headers":
|
|
for _, e := range entries {
|
|
h := e.settings.toHeaders()
|
|
if h == nil {
|
|
h = map[string]string{}
|
|
}
|
|
// The action's top-level headers may be replaced (not merged) by
|
|
// per-config headers, so always include the bearer token here.
|
|
// The token must match a recognized GitHub prefix so the server's
|
|
// Authorization parser accepts it without contacting the API.
|
|
h[mcphdr.AuthorizationHeader] = "Bearer ghp_test"
|
|
out = append(out, config{
|
|
Name: e.name,
|
|
Transport: "streamable-http",
|
|
ServerURL: httpServerURL,
|
|
Headers: h,
|
|
})
|
|
}
|
|
default:
|
|
fmt.Fprintf(os.Stderr, "unknown transport %q (want stdio or http-headers)\n", *transport)
|
|
os.Exit(2)
|
|
}
|
|
|
|
enc := json.NewEncoder(os.Stdout)
|
|
enc.SetIndent("", " ")
|
|
if err := enc.Encode(out); err != nil {
|
|
fmt.Fprintln(os.Stderr, err)
|
|
os.Exit(1)
|
|
}
|
|
}
|
|
|
|
func baseEntries() []baseEntry {
|
|
entries := []baseEntry{
|
|
{name: "default"},
|
|
{name: "read-only", settings: settings{readOnly: true}},
|
|
{name: "toolsets-repos", settings: settings{toolsets: "repos"}},
|
|
{name: "toolsets-issues", settings: settings{toolsets: "issues"}},
|
|
{name: "toolsets-context", settings: settings{toolsets: "context"}},
|
|
{name: "toolsets-pull_requests", settings: settings{toolsets: "pull_requests"}},
|
|
{name: "toolsets-repos,issues", settings: settings{toolsets: "repos,issues"}},
|
|
{name: "toolsets-issues,context", settings: settings{toolsets: "issues,context"}},
|
|
{name: "toolsets-all", settings: settings{toolsets: "all"}},
|
|
{name: "tools-get_me", settings: settings{tools: "get_me"}},
|
|
{name: "tools-get_me,list_issues", settings: settings{tools: "get_me,list_issues"}},
|
|
{name: "toolsets-repos+read-only", settings: settings{toolsets: "repos", readOnly: true}},
|
|
{name: "insiders", settings: settings{insiders: true}},
|
|
{name: "insiders+read-only", settings: settings{insiders: true, readOnly: true}},
|
|
// Combined entries: exercise multiple settings together so we catch
|
|
// regressions when several X-MCP-* headers (or CLI flags) are merged.
|
|
{name: "combined-toolsets+exclude+readonly", settings: settings{
|
|
toolsets: "repos,issues",
|
|
excludeTools: "delete_file",
|
|
readOnly: true,
|
|
}},
|
|
{name: "combined-insiders+toolsets+features", settings: settings{
|
|
insiders: true,
|
|
toolsets: "repos",
|
|
features: firstFeatureFlag(),
|
|
}},
|
|
}
|
|
|
|
flags := append([]string(nil), github.AllowedFeatureFlags...)
|
|
sort.Strings(flags)
|
|
for _, f := range flags {
|
|
entries = append(entries, baseEntry{
|
|
name: "feature-" + f,
|
|
settings: settings{features: f},
|
|
})
|
|
}
|
|
return entries
|
|
}
|
|
|
|
func (s settings) toArgs() string {
|
|
var parts []string
|
|
if s.toolsets != "" {
|
|
parts = append(parts, "--toolsets="+s.toolsets)
|
|
}
|
|
if s.tools != "" {
|
|
parts = append(parts, "--tools="+s.tools)
|
|
}
|
|
if s.excludeTools != "" {
|
|
parts = append(parts, "--exclude-tools="+s.excludeTools)
|
|
}
|
|
if s.features != "" {
|
|
parts = append(parts, "--features="+s.features)
|
|
}
|
|
if s.readOnly {
|
|
parts = append(parts, "--read-only")
|
|
}
|
|
if s.insiders {
|
|
parts = append(parts, "--insiders")
|
|
}
|
|
if s.lockdown {
|
|
parts = append(parts, "--lockdown-mode")
|
|
}
|
|
return strings.Join(parts, " ")
|
|
}
|
|
|
|
func (s settings) toHeaders() map[string]string {
|
|
h := map[string]string{}
|
|
if s.toolsets != "" {
|
|
h[mcphdr.MCPToolsetsHeader] = s.toolsets
|
|
}
|
|
if s.tools != "" {
|
|
h[mcphdr.MCPToolsHeader] = s.tools
|
|
}
|
|
if s.excludeTools != "" {
|
|
h[mcphdr.MCPExcludeToolsHeader] = s.excludeTools
|
|
}
|
|
if s.features != "" {
|
|
h[mcphdr.MCPFeaturesHeader] = s.features
|
|
}
|
|
if s.readOnly {
|
|
h[mcphdr.MCPReadOnlyHeader] = "true"
|
|
}
|
|
if s.insiders {
|
|
h[mcphdr.MCPInsidersHeader] = "true"
|
|
}
|
|
if s.lockdown {
|
|
h[mcphdr.MCPLockdownHeader] = "true"
|
|
}
|
|
if len(h) == 0 {
|
|
return nil
|
|
}
|
|
return h
|
|
}
|
|
|
|
func firstFeatureFlag() string {
|
|
flags := append([]string(nil), github.AllowedFeatureFlags...)
|
|
if len(flags) == 0 {
|
|
return ""
|
|
}
|
|
sort.Strings(flags)
|
|
return flags[0]
|
|
}
|