diff --git a/README.md b/README.md index ab7377f127..c5709d9d1e 100644 --- a/README.md +++ b/README.md @@ -1772,6 +1772,21 @@ docker run -i --rm \ ghcr.io/github/github-mcp-server ``` +## Disabling MCP Apps + +MCP Apps is on by default. To run the server with no MCP App UI metadata, resources, or form handoff, pass `--mcp-apps=false` or set `GITHUB_MCP_APPS=false`. Tools then execute immediately and return their results inline. This is separate from `--features=mcp_apps_disable_form_deferral`, which keeps result views and only skips the input form. + +```bash +./github-mcp-server stdio --mcp-apps=false +``` + +```bash +docker run -i --rm \ + -e GITHUB_PERSONAL_ACCESS_TOKEN= \ + -e GITHUB_MCP_APPS=false \ + ghcr.io/github/github-mcp-server +``` + ## Lockdown Mode Lockdown mode limits the content that the server will surface from public repositories. When enabled, the server checks whether the author of each item has push access to the repository. Private repositories are unaffected, and collaborators keep full access to their own content. diff --git a/cmd/github-mcp-server/main.go b/cmd/github-mcp-server/main.go index 04ba68e226..598107cde3 100644 --- a/cmd/github-mcp-server/main.go +++ b/cmd/github-mcp-server/main.go @@ -130,6 +130,7 @@ var ( ContentWindowSize: viper.GetInt("content-window-size"), LockdownMode: viper.GetBool("lockdown-mode"), InsidersMode: viper.GetBool("insiders"), + DisableMCPApps: !mcpAppsEnabled(), ExcludeTools: excludeTools, RepoAccessCacheTTL: &ttl, } @@ -224,6 +225,7 @@ var ( ExcludeTools: excludeTools, EnabledFeatures: enabledFeatures, InsidersMode: viper.GetBool("insiders"), + DisableMCPApps: !mcpAppsEnabled(), TrustProxyHeaders: viper.GetBool("trust-proxy-headers"), MRTRStateKey: os.Getenv(ghhttp.MRTRStateKeyEnv), } @@ -252,6 +254,7 @@ func init() { rootCmd.PersistentFlags().Int("content-window-size", 5000, "Specify the content window size") rootCmd.PersistentFlags().Bool("lockdown-mode", false, "Enable lockdown mode") rootCmd.PersistentFlags().Bool("insiders", false, "Enable insiders features") + rootCmd.PersistentFlags().Bool("mcp-apps", true, "Expose MCP Apps UI metadata, resources, and form deferral. Set to false to execute tools inline with no MCP Apps surface") rootCmd.PersistentFlags().Duration("repo-access-cache-ttl", 5*time.Minute, "Override the repo access cache TTL (e.g. 1m, 0s to disable)") // stdio-specific OAuth flags. Provide --oauth-client-id (instead of a token) @@ -289,6 +292,7 @@ func init() { _ = viper.BindPFlag("content-window-size", rootCmd.PersistentFlags().Lookup("content-window-size")) _ = viper.BindPFlag("lockdown-mode", rootCmd.PersistentFlags().Lookup("lockdown-mode")) _ = viper.BindPFlag("insiders", rootCmd.PersistentFlags().Lookup("insiders")) + _ = viper.BindPFlag("mcp-apps", rootCmd.PersistentFlags().Lookup("mcp-apps")) _ = viper.BindPFlag("repo-access-cache-ttl", rootCmd.PersistentFlags().Lookup("repo-access-cache-ttl")) _ = viper.BindPFlag("oauth-client-id", stdioCmd.Flags().Lookup("oauth-client-id")) _ = viper.BindPFlag("oauth-client-secret", stdioCmd.Flags().Lookup("oauth-client-secret")) @@ -314,6 +318,13 @@ func initConfig() { viper.SetEnvPrefix("github") viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_")) viper.AutomaticEnv() + viper.SetDefault("mcp-apps", true) +} + +// mcpAppsEnabled reports whether MCP Apps stay on. The flag defaults to true. +// GITHUB_MCP_APPS=false and --mcp-apps=false both turn the surface off. +func mcpAppsEnabled() bool { + return viper.GetBool("mcp-apps") } func main() { diff --git a/cmd/github-mcp-server/main_test.go b/cmd/github-mcp-server/main_test.go index e064236582..52fecd1dcf 100644 --- a/cmd/github-mcp-server/main_test.go +++ b/cmd/github-mcp-server/main_test.go @@ -59,6 +59,34 @@ func TestAuthorizationServerConfigurationIsHTTPOnly(t *testing.T) { assert.Equal(t, "https://oauth-proxy.example.com", viper.GetString("authorization-server")) } +func TestMCPAppsDefaultsOnAndEnvCanDisable(t *testing.T) { + flag := rootCmd.PersistentFlags().Lookup("mcp-apps") + require.NotNil(t, flag) + assert.Equal(t, "true", flag.DefValue) + + original := flag.Value.String() + originalChanged := flag.Changed + t.Cleanup(func() { + require.NoError(t, flag.Value.Set(original)) + flag.Changed = originalChanged + }) + + require.NoError(t, flag.Value.Set("true")) + flag.Changed = false + t.Setenv("GITHUB_MCP_APPS", "") + initConfig() + assert.True(t, mcpAppsEnabled()) + + t.Setenv("GITHUB_MCP_APPS", "false") + initConfig() + assert.False(t, mcpAppsEnabled()) + + t.Setenv("GITHUB_MCP_APPS", "") + require.NoError(t, flag.Value.Set("false")) + flag.Changed = true + assert.False(t, mcpAppsEnabled()) +} + func TestWriteToolDocScopes(t *testing.T) { tool := inventory.ServerTool{ Tool: mcp.Tool{Name: "delete", Annotations: &mcp.ToolAnnotations{Title: "Delete"}}, diff --git a/docs/server-configuration.md b/docs/server-configuration.md index 25c641153e..811ae54b3f 100644 --- a/docs/server-configuration.md +++ b/docs/server-configuration.md @@ -13,6 +13,7 @@ We currently support the following ways in which the GitHub MCP Server can be co | Read-Only Mode | `X-MCP-Readonly` header or `/readonly` URL | `--read-only` flag or `GITHUB_READ_ONLY` env var | | Lockdown Mode | `X-MCP-Lockdown` header | `--lockdown-mode` flag or `GITHUB_LOCKDOWN_MODE` env var | | Insiders Mode | `X-MCP-Insiders` header or `/insiders` URL | `--insiders` flag or `GITHUB_INSIDERS` env var | +| MCP Apps | Enabled on the hosted remote server | `--mcp-apps` flag (default `true`) or `GITHUB_MCP_APPS` env var | | Feature Flags | `X-MCP-Features` header or `?features=` URL query parameter | `--features` flag | | Scope Filtering | Always enabled | Always enabled | | Server Name/Title | Not available | `GITHUB_MCP_SERVER_NAME` / `GITHUB_MCP_SERVER_TITLE` env vars or `github-mcp-server-config.json` | @@ -404,6 +405,8 @@ See [Insiders Features](./insiders-features.md) for a full list of what's availa MCP Apps is enabled by default. Tools with MCP Apps UIs advertise them via `_meta.ui` to clients that support the [MCP Apps extension](https://modelcontextprotocol.io/docs/extensions/apps); the metadata is omitted for clients that do not advertise the `io.modelcontextprotocol/ui` capability. +To turn MCP Apps off for the whole server, pass `--mcp-apps=false` or set `GITHUB_MCP_APPS=false`. The server then omits `_meta.ui`, does not register MCP App UI resources or app-only tools, skips form deferral, and returns inline tool results. The default stays enabled, and a request cannot turn MCP Apps back on. The hosted remote server does not offer this switch; it applies to the local server and to a self-hosted HTTP server. + To keep MCP App result views enabled while making write tools execute directly instead of first opening an interactive form, enable the `mcp_apps_disable_form_deferral` feature flag. For the remote server, send the diff --git a/internal/ghmcp/server.go b/internal/ghmcp/server.go index ac7a90b57d..06e73aa194 100644 --- a/internal/ghmcp/server.go +++ b/internal/ghmcp/server.go @@ -283,6 +283,9 @@ type StdioServerConfig struct { // InsidersMode expands to the curated set of feature flags enabled for insiders. InsidersMode bool + // DisableMCPApps turns off MCP Apps for the whole server. + DisableMCPApps bool + // ExcludeTools is a list of tool names to disable regardless of other settings. // These tools will be excluded even if their toolset is enabled or they are // explicitly listed in EnabledTools. @@ -339,7 +342,7 @@ func RunStdioServer(cfg StdioServerConfig) error { slogHandler = slog.NewTextHandler(logOutput, &slog.HandlerOptions{Level: slog.LevelInfo}) } logger := slog.New(slogHandler) - logger.Info("starting server", "version", cfg.Version, "host", cfg.Host, "readOnly", cfg.ReadOnly, "lockdownEnabled", cfg.LockdownMode) + logger.Info("starting server", "version", cfg.Version, "host", cfg.Host, "readOnly", cfg.ReadOnly, "lockdownEnabled", cfg.LockdownMode, "mcpApps", !cfg.DisableMCPApps) // Determine the scope set used to filter tools. Classic PATs expose their // granted scopes via the API; OAuth uses the requested scopes (the default @@ -381,6 +384,7 @@ func RunStdioServer(cfg StdioServerConfig) error { ContentWindowSize: cfg.ContentWindowSize, LockdownMode: cfg.LockdownMode, InsidersMode: cfg.InsidersMode, + DisableMCPApps: cfg.DisableMCPApps, ExcludeTools: cfg.ExcludeTools, Logger: logger, RepoAccessTTL: cfg.RepoAccessCacheTTL, diff --git a/pkg/context/request.go b/pkg/context/request.go index 548dc7f575..dd6df2810b 100644 --- a/pkg/context/request.go +++ b/pkg/context/request.go @@ -114,6 +114,22 @@ func GetHeaderFeatures(ctx context.Context) []string { return nil } +// mcpAppsDisabledCtxKey is a context key for a server-wide MCP Apps opt-out. +type mcpAppsDisabledCtxKey struct{} + +// WithMCPAppsDisabled marks the server as having MCP Apps turned off. +// Tool registration and tool calls both honor this: UI metadata is stripped, +// app-only tools are omitted, and form deferral does not run. +func WithMCPAppsDisabled(ctx context.Context) context.Context { + return context.WithValue(ctx, mcpAppsDisabledCtxKey{}, true) +} + +// MCPAppsDisabled reports whether the server was started with MCP Apps turned off. +func MCPAppsDisabled(ctx context.Context) bool { + disabled, _ := ctx.Value(mcpAppsDisabledCtxKey{}).(bool) + return disabled +} + // uiSupportCtxKey is a context key for MCP Apps UI support type uiSupportCtxKey struct{} diff --git a/pkg/github/server.go b/pkg/github/server.go index 90498fc47d..71a6d35c67 100644 --- a/pkg/github/server.go +++ b/pkg/github/server.go @@ -8,6 +8,7 @@ import ( "strings" "time" + ghcontext "github.com/github/github-mcp-server/v2/pkg/context" gherrors "github.com/github/github-mcp-server/v2/pkg/errors" "github.com/github/github-mcp-server/v2/pkg/inventory" "github.com/github/github-mcp-server/v2/pkg/octicons" @@ -54,6 +55,12 @@ type MCPServerConfig struct { // InsidersMode expands to the curated set of feature flags enabled for insiders. InsidersMode bool + // DisableMCPApps turns off MCP Apps for the whole server. UI metadata is + // stripped, app-only tools and UI resources are omitted, and write tools + // execute inline instead of opening a form. The zero value leaves MCP Apps + // enabled. + DisableMCPApps bool + // Logger is used for logging within the server Logger *slog.Logger // RepoAccessTTL overrides the default TTL for repository access cache entries. @@ -115,6 +122,12 @@ func NewMCPServer(ctx context.Context, cfg *MCPServerConfig, deps ToolDependenci o(serverOpts) } + // Set the opt-out before skill publishing. skillsPublisher filters on + // ConfiguredTools, which omits app-only tools only when this flag is set. + if cfg.DisableMCPApps { + ctx = ghcontext.WithMCPAppsDisabled(ctx) + } + publisher, err := skillsPublisher(ctx, cfg, deps, inv) if err != nil { return nil, err @@ -159,6 +172,12 @@ func NewMCPServer(ctx context.Context, cfg *MCPServerConfig, deps ToolDependenci ghServer.AddReceivingMiddleware(middleware...) ghServer.AddReceivingMiddleware(injectFeatureStateMiddleware(inv)) ghServer.AddReceivingMiddleware(InjectDepsMiddleware(deps)) + // Stamp every tool call so a client that advertises MCP Apps cannot + // turn the server-wide opt-out back on. This stays inside the error + // wrapper, which is added last and therefore runs first. + if cfg.DisableMCPApps { + ghServer.AddReceivingMiddleware(disableMCPAppsMiddleware) + } ghServer.AddReceivingMiddleware(addGitHubAPIErrorToContext) // Register MCP App UI resources whenever the embedded UI assets are @@ -168,13 +187,21 @@ func NewMCPServer(ctx context.Context, cfg *MCPServerConfig, deps ToolDependenci // Registering here — rather than in the stdio bootstrap — ensures the // remote/HTTP server also serves them, fixing the "-32002 Resource not // found" error clients hit after the tool returns a ui:// URI. - if UIAssetsAvailable() { + // A server-wide disable skips them entirely: nothing should advertise a + // ui:// URI once MCP Apps are off. + if !cfg.DisableMCPApps && UIAssetsAvailable() { RegisterUIResources(ghServer, cfg.ReadOnly) } return ghServer, nil } +func disableMCPAppsMiddleware(next mcp.MethodHandler) mcp.MethodHandler { + return func(ctx context.Context, method string, req mcp.Request) (mcp.Result, error) { + return next(ghcontext.WithMCPAppsDisabled(ctx), method, req) + } +} + func injectFeatureStateMiddleware(inv *inventory.Inventory) mcp.Middleware { return func(next mcp.MethodHandler) mcp.MethodHandler { return func(ctx context.Context, method string, req mcp.Request) (mcp.Result, error) { diff --git a/pkg/github/server_test.go b/pkg/github/server_test.go index df51fcd802..1ff15597b3 100644 --- a/pkg/github/server_test.go +++ b/pkg/github/server_test.go @@ -257,6 +257,84 @@ func TestNewMCPServerTypedLegacyPreflightAndHandlerReceiveDependencies(t *testin assert.Equal(t, "legacy text", result.Content[0].(*mcp.TextContent).Text) } +func TestNewMCPServer_DisableMCPAppsOmitsUISurface(t *testing.T) { + t.Parallel() + + toolset := inventory.ToolsetMetadata{ID: inventory.ToolsetID("test"), Description: "Test"} + withUI := NewToolWithSchemaOptions[struct{}, struct{}]( + toolset, + mcp.Tool{ + Name: "with_ui", + Meta: mcp.Meta{ + "ui": map[string]any{"resourceUri": IssueWriteUIResourceURI}, + "description": "kept", + }, + }, + inventory.ScopeAccess{}, + inventory.TypedSchemaOptions{}, + func(context.Context, ToolDependencies, *mcp.CallToolRequest, struct{}) (*mcp.CallToolResult, struct{}, error) { + return &mcp.CallToolResult{Content: []mcp.Content{&mcp.TextContent{Text: "inline"}}}, struct{}{}, nil + }, + ) + appOnly := NewToolWithSchemaOptions[struct{}, struct{}]( + toolset, + mcp.Tool{ + Name: "ui_get", + Meta: mcp.Meta{"ui": map[string]any{"visibility": []string{"app"}}}, + }, + inventory.ScopeAccess{}, + inventory.TypedSchemaOptions{}, + func(context.Context, ToolDependencies, *mcp.CallToolRequest, struct{}) (*mcp.CallToolResult, struct{}, error) { + return nil, struct{}{}, nil + }, + ) + inv, err := inventory.NewBuilder(). + SetTools([]inventory.ServerTool{withUI, appOnly}). + WithToolsets([]string{"all"}). + Build() + require.NoError(t, err) + + server, err := NewMCPServer(context.Background(), &MCPServerConfig{ + Version: "test", + Translator: translations.NullTranslationHelper, + Logger: slog.New(slog.DiscardHandler), + DisableMCPApps: true, + }, stubDeps{obsv: stubExporters()}, inv) + require.NoError(t, err) + + serverTransport, clientTransport := mcp.NewInMemoryTransports() + serverSession, err := server.Connect(context.Background(), serverTransport, nil) + require.NoError(t, err) + t.Cleanup(func() { _ = serverSession.Close() }) + + client := mcp.NewClient(&mcp.Implementation{Name: "ui-client", Version: "1"}, nil) + clientSession, err := client.Connect(context.Background(), clientTransport, &mcp.ClientSessionOptions{ + ProtocolVersion: "2025-11-25", + }) + require.NoError(t, err) + t.Cleanup(func() { _ = clientSession.Close() }) + + list, err := clientSession.ListTools(context.Background(), nil) + require.NoError(t, err) + require.Len(t, list.Tools, 1) + assert.Equal(t, "with_ui", list.Tools[0].Name) + if list.Tools[0].Meta != nil { + assert.Nil(t, list.Tools[0].Meta["ui"]) + assert.Equal(t, "kept", list.Tools[0].Meta["description"]) + } + + result, err := clientSession.CallTool(context.Background(), &mcp.CallToolParams{Name: "with_ui"}) + require.NoError(t, err) + require.False(t, result.IsError) + require.Len(t, result.Content, 1) + assert.Equal(t, "inline", result.Content[0].(*mcp.TextContent).Text) + + if UIAssetsAvailable() { + _, err = clientSession.ReadResource(context.Background(), &mcp.ReadResourceParams{URI: IssueWriteUIResourceURI}) + require.Error(t, err) + } +} + func TestFeatureStateMiddlewareCachesHandlerChecks(t *testing.T) { var calls int checker := func(_ context.Context, flag string) (bool, error) { diff --git a/pkg/github/skills_test.go b/pkg/github/skills_test.go index d82a41a3f7..36d8f0c57a 100644 --- a/pkg/github/skills_test.go +++ b/pkg/github/skills_test.go @@ -4,10 +4,12 @@ import ( "bytes" "context" "encoding/json" + "log/slog" "net/http" "net/http/httptest" "testing" + "github.com/github/github-mcp-server/v2/pkg/inventory" "github.com/github/github-mcp-server/v2/pkg/skills" "github.com/github/github-mcp-server/v2/pkg/translations" "github.com/modelcontextprotocol/go-sdk/jsonrpc" @@ -242,6 +244,66 @@ func TestSkillsModernDiscoveryAndCacheEnvelopes(t *testing.T) { } } +func TestDisableMCPAppsWithholdsSkillsThatNeedAppOnlyTools(t *testing.T) { + t.Parallel() + + skill, err := skills.NewSkill("example.com/app-view", []skills.File{ + {Path: "SKILL.md", Content: []byte("---\nname: app-view\ndescription: Open the app view.\n---\n\nUse the app tool.\n")}, + }) + require.NoError(t, err) + skill.RequiredTools = [][]string{{"ui_get"}} + source, err := skills.NewRegistry(skill) + require.NoError(t, err) + + toolset := inventory.ToolsetMetadata{ID: inventory.ToolsetID("test"), Description: "Test"} + appOnly := NewToolWithSchemaOptions[struct{}, struct{}]( + toolset, + mcp.Tool{ + Name: "ui_get", + Meta: mcp.Meta{"ui": map[string]any{"visibility": []string{"app"}}}, + }, + inventory.ScopeAccess{}, + inventory.TypedSchemaOptions{}, + func(context.Context, ToolDependencies, *mcp.CallToolRequest, struct{}) (*mcp.CallToolResult, struct{}, error) { + return nil, struct{}{}, nil + }, + ) + checker := featureCheckerFor(FeatureFlagSkillsExtension) + + for _, disabled := range []bool{false, true} { + t.Run(map[bool]string{false: "apps-enabled", true: "apps-disabled"}[disabled], func(t *testing.T) { + t.Parallel() + cfg := MCPServerConfig{ + Version: "test", + Translator: translations.NullTranslationHelper, + Logger: slog.New(slog.DiscardHandler), + SkillsSource: source, + DisableMCPApps: disabled, + } + deps := NewBaseDeps(nil, nil, nil, nil, cfg.Translator, FeatureFlags{}, 0, checker, stubExporters()) + inv, err := inventory.NewBuilder(). + SetTools([]inventory.ServerTool{appOnly}). + WithToolsets([]string{"all"}). + WithFeatureChecker(checker). + Build() + require.NoError(t, err) + + server, err := NewMCPServer(context.Background(), &cfg, deps, inv) + require.NoError(t, err) + session := connectSkillsClient(t, server) + listed, err := mcp.CallCustomMethod[*skills.ListSkillsParams, *skills.ListSkillsResult]( + context.Background(), session, skills.MethodListSkills, &skills.ListSkillsParams{}) + require.NoError(t, err) + if disabled { + assert.Empty(t, listed.Skills) + return + } + require.Len(t, listed.Skills, 1) + assert.Equal(t, "app-view", listed.Skills[0].Frontmatter.Name()) + }) + } +} + func TestSkillsDisabledPreservesInventoryInstructions(t *testing.T) { t.Parallel() cfg := MCPServerConfig{Version: "test", Translator: translations.NullTranslationHelper} diff --git a/pkg/github/ui_capability.go b/pkg/github/ui_capability.go index a46a8bb842..f198ac4f01 100644 --- a/pkg/github/ui_capability.go +++ b/pkg/github/ui_capability.go @@ -19,6 +19,10 @@ const MCPAppMIMEType = "text/html;profile=mcp-app" // It checks the context first (set by HTTP/stateless servers from stored // session capabilities), then falls back to the go-sdk Session (for stdio). func clientSupportsUI(ctx context.Context, req *mcp.CallToolRequest) bool { + // A server-wide opt-out wins over both the request context and the session. + if ghcontext.MCPAppsDisabled(ctx) { + return false + } // Check context first (works for HTTP/stateless servers) if supported, ok := ghcontext.HasUISupport(ctx); ok { return supported @@ -70,6 +74,9 @@ func hasNonFormParams(args map[string]any, formParams map[string]struct{}) bool // still render the tool's view, which renders the result rather than an input // form. func shouldDeferToForm(ctx context.Context, deps ToolDependencies, req *mcp.CallToolRequest, args map[string]any, formParams map[string]struct{}) bool { + if ghcontext.MCPAppsDisabled(ctx) { + return false + } return !deps.IsFeatureEnabled(ctx, MCPAppsDisableFormDeferralFeatureFlag) && clientSupportsUI(ctx, req) && !uiSubmitted(args) && diff --git a/pkg/github/ui_capability_test.go b/pkg/github/ui_capability_test.go index 02648361c0..6bcdf24c4b 100644 --- a/pkg/github/ui_capability_test.go +++ b/pkg/github/ui_capability_test.go @@ -85,6 +85,14 @@ func Test_clientSupportsUI_fromContext(t *testing.T) { t.Run("no context or session", func(t *testing.T) { assert.False(t, clientSupportsUI(context.Background(), nil)) }) + + t.Run("server disable overrides session and context", func(t *testing.T) { + ctx := ghcontext.WithMCPAppsDisabled(ghcontext.WithUISupport(context.Background(), true)) + caps := &mcp.ClientCapabilities{} + caps.AddExtension("io.modelcontextprotocol/ui", map[string]any{}) + req := createMCPRequestWithCapabilities(t, caps) + assert.False(t, clientSupportsUI(ctx, &req)) + }) } func Test_shouldDeferToForm_featureFlags(t *testing.T) { @@ -110,6 +118,13 @@ func Test_shouldDeferToForm_featureFlags(t *testing.T) { }, } + t.Run("server-level MCP Apps disable executes directly", func(t *testing.T) { + t.Parallel() + disabled := ghcontext.WithMCPAppsDisabled(ctx) + deps := BaseDeps{featureChecker: featureCheckerFor()} + assert.False(t, shouldDeferToForm(disabled, deps, nil, args, formParams)) + }) + for _, tc := range tests { t.Run(tc.name, func(t *testing.T) { t.Parallel() diff --git a/pkg/http/handler.go b/pkg/http/handler.go index 14b7eb2a0f..d03e073b77 100644 --- a/pkg/http/handler.go +++ b/pkg/http/handler.go @@ -223,6 +223,9 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { // Remote consumers install user identity in HTTP middleware before the // inventory factory, so their per-user checker has its full context here. r = r.WithContext(invToUse.WithFeatureState(r.Context())) + if h.config.DisableMCPApps { + r = r.WithContext(ghcontext.WithMCPAppsDisabled(r.Context())) + } ghServer, err := h.githubMcpServerFactory(r, h.deps, invToUse, &github.MCPServerConfig{ Version: h.config.Version, @@ -230,6 +233,7 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) { ContentWindowSize: h.config.ContentWindowSize, Logger: h.logger, RepoAccessTTL: h.config.RepoAccessCacheTTL, + DisableMCPApps: h.config.DisableMCPApps, // Capabilities (no list-changed advertising) are set by NewMCPServer; // here we only supply the remote-specific schema cache. ServerOptions: []github.MCPServerOption{ diff --git a/pkg/http/server.go b/pkg/http/server.go index c7382f0569..c74d97fff9 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -112,6 +112,10 @@ type ServerConfig struct { // InsidersMode expands to the curated set of feature flags enabled for insiders. InsidersMode bool + // DisableMCPApps turns off MCP Apps for every request. Per-request headers + // cannot turn it back on. + DisableMCPApps bool + // MRTRStateKey is a Base64-encoded 32-byte key used to protect multi-round-trip request state. MRTRStateKey string @@ -144,7 +148,7 @@ func RunHTTPServer(cfg ServerConfig) error { slogHandler = slog.NewTextHandler(logOutput, &slog.HandlerOptions{Level: slog.LevelInfo}) } logger := slog.New(slogHandler) - logger.Info("starting server", "version", cfg.Version, "host", cfg.Host, "lockdownEnabled", cfg.LockdownMode, "readOnly", cfg.ReadOnly, "insidersMode", cfg.InsidersMode) + logger.Info("starting server", "version", cfg.Version, "host", cfg.Host, "lockdownEnabled", cfg.LockdownMode, "readOnly", cfg.ReadOnly, "insidersMode", cfg.InsidersMode, "mcpApps", !cfg.DisableMCPApps) stateSealer, err := configureRequestState(&cfg, logger) if err != nil { diff --git a/pkg/inventory/registry.go b/pkg/inventory/registry.go index e829f08e62..17f8bb0887 100644 --- a/pkg/inventory/registry.go +++ b/pkg/inventory/registry.go @@ -239,9 +239,13 @@ func appendFeatureDeclaration(features []FeatureFlag, rule FeatureRule) []Featur } // shouldStripMCPAppsMetadata centralises the strip decision so the same logic -// is exercised by tests and by RegisterTools. Metadata is stripped only when -// the client is known not to support MCP Apps UI. +// is exercised by tests and by RegisterTools. Metadata is stripped when the +// server was started with MCP Apps disabled, and otherwise only when the +// client is known not to support MCP Apps UI. func shouldStripMCPAppsMetadata(ctx context.Context) bool { + if ghcontext.MCPAppsDisabled(ctx) { + return true + } supported, ok := ghcontext.HasUISupport(ctx) return ok && !supported } diff --git a/pkg/inventory/registry_test.go b/pkg/inventory/registry_test.go index ffae37b169..52e76d8fe7 100644 --- a/pkg/inventory/registry_test.go +++ b/pkg/inventory/registry_test.go @@ -2137,6 +2137,14 @@ func TestWithMCPApps_UnsupportedClientOmitsAppOnlyTools(t *testing.T) { } { require.Len(t, reg.ToolsForRegistration(ctx), 4, "app-only tools should be kept when UI is supported or unknown") } + + disabled := reg.ToolsForRegistration(ghcontext.WithMCPAppsDisabled(ghcontext.WithUISupport(context.Background(), true))) + disabledNames := make([]string, 0, len(disabled)) + for _, tool := range disabled { + disabledNames = append(disabledNames, tool.Tool.Name) + require.Nil(t, tool.Tool.Meta["ui"], "ui meta should be stripped when the server disables MCP Apps") + } + require.ElementsMatch(t, []string{"model_and_app", "no_visibility"}, disabledNames) } func TestWithMCPApps_PreservesUIMetadataByDefault(t *testing.T) {