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
15 changes: 15 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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=<your-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.
Expand Down
11 changes: 11 additions & 0 deletions cmd/github-mcp-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down Expand Up @@ -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),
}
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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"))
Expand All @@ -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() {
Expand Down
28 changes: 28 additions & 0 deletions cmd/github-mcp-server/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"}},
Expand Down
3 changes: 3 additions & 0 deletions docs/server-configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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` |
Expand Down Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion internal/ghmcp/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down
16 changes: 16 additions & 0 deletions pkg/context/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}

Expand Down
29 changes: 28 additions & 1 deletion pkg/github/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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) {
Expand Down
78 changes: 78 additions & 0 deletions pkg/github/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading