diff --git a/docs/insiders-features.md b/docs/insiders-features.md index 911257ae4..1ed5b90f3 100644 --- a/docs/insiders-features.md +++ b/docs/insiders-features.md @@ -20,25 +20,4 @@ For configuration examples, see the [Server Configuration Guide](./server-config --- -## MCP Apps - -[MCP Apps](https://modelcontextprotocol.io/docs/extensions/apps) is an extension to the Model Context Protocol that enables servers to deliver interactive user interfaces to end users. Instead of returning plain text that the LLM must interpret and relay, tools can render forms, profiles, and dashboards right in the chat using MCP Apps. - -This means you can interact with GitHub visually: fill out forms to create issues, see user profiles with avatars, open pull requests — all without leaving your agent chat. - -### Supported tools - -The following tools have MCP Apps UIs: - -| Tool | Description | -|------|-------------| -| `get_me` | Displays your GitHub user profile with avatar, bio, and stats in a rich card | -| `issue_write` | Opens an interactive form to create or update issues | -| `create_pull_request` | Provides a full PR creation form to create a pull request (or a draft pull request) | - -### Client requirements - -MCP Apps requires a host that supports the [MCP Apps extension](https://modelcontextprotocol.io/docs/extensions/apps). Currently tested and working with: - -- **VS Code Insiders** — enable via the `chat.mcp.apps.enabled` setting -- **Visual Studio Code** — enable via the `chat.mcp.apps.enabled` setting +_There are currently no insiders-only features. [MCP Apps](./server-configuration.md#mcp-apps) has graduated to a feature flag (`remote_mcp_ui_apps`) and can be enabled independently._ diff --git a/docs/server-configuration.md b/docs/server-configuration.md index 87d48e01e..6fa3f2491 100644 --- a/docs/server-configuration.md +++ b/docs/server-configuration.md @@ -14,6 +14,7 @@ We currently support the following ways in which the GitHub MCP Server can be co | Dynamic Mode | Not available | `--dynamic-toolsets` flag or `GITHUB_DYNAMIC_TOOLSETS` 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 | +| Feature Flags | `X-MCP-Features` header | `--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` | @@ -390,7 +391,10 @@ Lockdown mode ensures the server only surfaces content in public repositories fr **Best for:** Users who want early access to experimental features and new tools before they reach general availability. -Insiders Mode unlocks experimental features, such as [MCP Apps](./insiders-features.md#mcp-apps) support. We created this mode to have a way to roll out experimental features and collect feedback. So if you are using Insiders, please don't hesitate to share your feedback with us! Features in Insiders Mode may change, evolve, or be removed based on user feedback. +Insiders Mode unlocks experimental features. We created this mode to have a way to roll out experimental features and collect feedback. So if you are using Insiders, please don't hesitate to share your feedback with us! Features in Insiders Mode may change, evolve, or be removed based on user feedback. + +> [!NOTE] +> Insiders mode also enables the `remote_mcp_ui_apps` feature flag for backward compatibility. See [MCP Apps](#mcp-apps) below. @@ -443,6 +447,62 @@ See [Insiders Features](./insiders-features.md) for a full list of what's availa --- +### MCP Apps + +[MCP Apps](https://modelcontextprotocol.io/docs/extensions/apps) is an extension to the Model Context Protocol that enables servers to deliver interactive user interfaces to end users. Instead of returning plain text that the LLM must interpret and relay, tools can render forms, profiles, and dashboards right in the chat. + +MCP Apps is controlled by the `remote_mcp_ui_apps` feature flag and can be enabled independently of insiders mode. + +**Supported tools:** + +| Tool | Description | +|------|-------------| +| `get_me` | Displays your GitHub user profile with avatar, bio, and stats in a rich card | +| `issue_write` | Opens an interactive form to create or update issues | +| `create_pull_request` | Provides a full PR creation form to create a pull request (or a draft pull request) | + +**Client requirements:** MCP Apps requires a host that supports the [MCP Apps extension](https://modelcontextprotocol.io/docs/extensions/apps). Currently tested with VS Code (`chat.mcp.apps.enabled` setting). + +
Remote ServerLocal Server
+ + + + + +
Remote ServerLocal Server
+ +```json +{ + "type": "http", + "url": "https://api.githubcopilot.com/mcp/", + "headers": { + "X-MCP-Features": "remote_mcp_ui_apps" + } +} +``` + + + +```json +{ + "type": "stdio", + "command": "go", + "args": [ + "run", + "./cmd/github-mcp-server", + "stdio", + "--features=remote_mcp_ui_apps" + ], + "env": { + "GITHUB_PERSONAL_ACCESS_TOKEN": "${input:github_token}" + } +} +``` + +
+ +--- + ### Scope Filtering **Automatic feature:** The server handles OAuth scopes differently depending on authentication type: diff --git a/internal/ghmcp/server.go b/internal/ghmcp/server.go index 5dfaf596c..4e45b751e 100644 --- a/internal/ghmcp/server.go +++ b/internal/ghmcp/server.go @@ -8,6 +8,7 @@ import ( "net/http" "os" "os/signal" + "slices" "strings" "syscall" "time" @@ -114,8 +115,13 @@ func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Se return nil, fmt.Errorf("failed to create GitHub clients: %w", err) } - // Create feature checker - featureChecker := createFeatureChecker(cfg.EnabledFeatures) + // Create feature checker — insiders mode transitionally enables remote_mcp_ui_apps + enabledFeatures := cfg.EnabledFeatures + if cfg.InsidersMode && !slices.Contains(enabledFeatures, github.MCPAppsFeatureFlag) { + enabledFeatures = append(slices.Clone(enabledFeatures), github.MCPAppsFeatureFlag) + } + featureChecker := createFeatureChecker(enabledFeatures) + mcpAppsEnabled := slices.Contains(enabledFeatures, github.MCPAppsFeatureFlag) // Create dependencies for tool handlers obs, err := observability.NewExporters(cfg.Logger, metrics.NewNoopMetrics()) @@ -145,7 +151,8 @@ func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Se WithExcludeTools(cfg.ExcludeTools). WithServerInstructions(). WithFeatureChecker(featureChecker). - WithInsidersMode(cfg.InsidersMode) + WithInsidersMode(cfg.InsidersMode). + WithMCPApps(mcpAppsEnabled) // Apply token scope filtering if scopes are known (for PAT filtering) if cfg.TokenScopes != nil { @@ -162,10 +169,11 @@ func NewStdioMCPServer(ctx context.Context, cfg github.MCPServerConfig) (*mcp.Se return nil, fmt.Errorf("failed to create GitHub MCP server: %w", err) } - // Register MCP App UI resources if available (requires running script/build-ui). - // We check availability to allow Insiders mode to work for non-UI features - // even when UI assets haven't been built. - if cfg.InsidersMode && github.UIAssetsAvailable() { + // Register MCP App UI resources if the remote_mcp_ui_apps feature flag is enabled + // and UI assets are available (requires running script/build-ui). + // We check availability to allow the feature flag to be enabled without + // requiring a UI build (graceful degradation). + if mcpAppsEnabled && github.UIAssetsAvailable() { github.RegisterUIResources(ghServer) } diff --git a/pkg/github/feature_flags.go b/pkg/github/feature_flags.go index fd06a659b..b5dd7e7f2 100644 --- a/pkg/github/feature_flags.go +++ b/pkg/github/feature_flags.go @@ -1,5 +1,11 @@ package github +// MCPAppsFeatureFlag is the feature flag name that enables MCP Apps +// (interactive UI forms) for supported tools. When enabled, tools like +// get_me, issue_write, and create_pull_request can render rich UI via +// the MCP Apps extension instead of plain text responses. +const MCPAppsFeatureFlag = "remote_mcp_ui_apps" + // FeatureFlags defines runtime feature toggles that adjust tool behavior. type FeatureFlags struct { LockdownMode bool diff --git a/pkg/github/issues.go b/pkg/github/issues.go index 05af64cab..0e20393f3 100644 --- a/pkg/github/issues.go +++ b/pkg/github/issues.go @@ -1073,12 +1073,12 @@ Options are: return utils.NewToolResultError(err.Error()), nil, nil } - // When insiders mode is enabled and the client supports MCP Apps UI, + // When the MCP Apps feature flag is enabled and the client supports MCP Apps UI, // check if this is a UI form submission. The UI sends _ui_submitted=true // to distinguish form submissions from LLM calls. uiSubmitted, _ := OptionalParam[bool](args, "_ui_submitted") - if deps.GetFlags(ctx).InsidersMode && clientSupportsUI(ctx, req) && !uiSubmitted { + if deps.IsFeatureEnabled(ctx, MCPAppsFeatureFlag) && clientSupportsUI(ctx, req) && !uiSubmitted { if method == "update" { // Skip the UI form when a state change is requested because // the form only handles title/body editing and would lose the diff --git a/pkg/github/issues_test.go b/pkg/github/issues_test.go index d06721be7..24d42f1cc 100644 --- a/pkg/github/issues_test.go +++ b/pkg/github/issues_test.go @@ -932,9 +932,9 @@ func Test_CreateIssue(t *testing.T) { } } -// Test_IssueWrite_InsidersMode_UIGate verifies the insiders mode UI gate +// Test_IssueWrite_MCPApps_UIGate verifies the MCP Apps feature flag UI gate // behavior: UI clients get a form message, non-UI clients execute directly. -func Test_IssueWrite_InsidersMode_UIGate(t *testing.T) { +func Test_IssueWrite_MCPApps_UIGate(t *testing.T) { t.Parallel() mockIssue := &github.Issue{ @@ -949,11 +949,17 @@ func Test_IssueWrite_InsidersMode_UIGate(t *testing.T) { PostReposIssuesByOwnerByRepo: mockResponse(t, http.StatusCreated, mockIssue), })) - deps := BaseDeps{ - Client: client, - GQLClient: githubv4.NewClient(nil), - Flags: FeatureFlags{InsidersMode: true}, + mcpAppsChecker := func(_ context.Context, flag string) (bool, error) { + return flag == MCPAppsFeatureFlag, nil } + deps := NewBaseDeps( + client, githubv4.NewClient(nil), nil, nil, + translations.NullTranslationHelper, + FeatureFlags{}, + 0, + mcpAppsChecker, + stubExporters(), + ) handler := serverTool.Handler(deps) t.Run("UI client without _ui_submitted returns form message", func(t *testing.T) { @@ -1066,11 +1072,14 @@ func Test_IssueWrite_InsidersMode_UIGate(t *testing.T) { ), )) - closeDeps := BaseDeps{ - Client: closeClient, - GQLClient: closeGQLClient, - Flags: FeatureFlags{InsidersMode: true}, - } + closeDeps := NewBaseDeps( + closeClient, closeGQLClient, nil, nil, + translations.NullTranslationHelper, + FeatureFlags{}, + 0, + mcpAppsChecker, + stubExporters(), + ) closeHandler := serverTool.Handler(closeDeps) request := createMCPRequestWithSession(t, ClientNameVSCodeInsiders, true, map[string]any{ diff --git a/pkg/github/pullrequests.go b/pkg/github/pullrequests.go index 731db4931..69c02f159 100644 --- a/pkg/github/pullrequests.go +++ b/pkg/github/pullrequests.go @@ -601,12 +601,12 @@ func CreatePullRequest(t translations.TranslationHelperFunc) inventory.ServerToo return utils.NewToolResultError(err.Error()), nil, nil } - // When insiders mode is enabled and the client supports MCP Apps UI, + // When the MCP Apps feature flag is enabled and the client supports MCP Apps UI, // check if this is a UI form submission. The UI sends _ui_submitted=true // to distinguish form submissions from LLM calls. uiSubmitted, _ := OptionalParam[bool](args, "_ui_submitted") - if deps.GetFlags(ctx).InsidersMode && clientSupportsUI(ctx, req) && !uiSubmitted { + if deps.IsFeatureEnabled(ctx, MCPAppsFeatureFlag) && clientSupportsUI(ctx, req) && !uiSubmitted { return utils.NewToolResultText(fmt.Sprintf("Ready to create a pull request in %s/%s. IMPORTANT: The PR has NOT been created yet. Do NOT tell the user the PR was created. The user MUST click Submit in the form to create it.", owner, repo)), nil, nil } diff --git a/pkg/github/pullrequests_test.go b/pkg/github/pullrequests_test.go index 801122dca..0febb2fc4 100644 --- a/pkg/github/pullrequests_test.go +++ b/pkg/github/pullrequests_test.go @@ -2312,9 +2312,9 @@ func Test_CreatePullRequest(t *testing.T) { } } -// Test_CreatePullRequest_InsidersMode_UIGate verifies the insiders mode UI gate +// Test_CreatePullRequest_MCPApps_UIGate verifies the MCP Apps feature flag UI gate // behavior: UI clients get a form message, non-UI clients execute directly. -func Test_CreatePullRequest_InsidersMode_UIGate(t *testing.T) { +func Test_CreatePullRequest_MCPApps_UIGate(t *testing.T) { t.Parallel() mockPR := &github.PullRequest{ @@ -2332,11 +2332,17 @@ func Test_CreatePullRequest_InsidersMode_UIGate(t *testing.T) { PostReposPullsByOwnerByRepo: mockResponse(t, http.StatusCreated, mockPR), })) - deps := BaseDeps{ - Client: client, - GQLClient: githubv4.NewClient(nil), - Flags: FeatureFlags{InsidersMode: true}, + mcpAppsChecker := func(_ context.Context, flag string) (bool, error) { + return flag == MCPAppsFeatureFlag, nil } + deps := NewBaseDeps( + client, githubv4.NewClient(nil), nil, nil, + translations.NullTranslationHelper, + FeatureFlags{}, + 0, + mcpAppsChecker, + stubExporters(), + ) handler := serverTool.Handler(deps) t.Run("UI client without _ui_submitted returns form message", func(t *testing.T) { diff --git a/pkg/http/handler.go b/pkg/http/handler.go index 2e828211d..d279f6ea7 100644 --- a/pkg/http/handler.go +++ b/pkg/http/handler.go @@ -5,6 +5,7 @@ import ( "errors" "log/slog" "net/http" + "slices" ghcontext "github.com/github/github-mcp-server/pkg/context" "github.com/github/github-mcp-server/pkg/github" @@ -261,6 +262,19 @@ func InventoryFiltersForRequest(r *http.Request, builder *inventory.Builder) *in builder = builder.WithReadOnly(true) } + insiders := ghcontext.IsInsidersMode(ctx) + if insiders { + builder = builder.WithInsidersMode(true) + } + + // Enable MCP Apps if the feature flag is present in the request headers + // or if insiders mode is active (transitional: insiders implies remote_mcp_ui_apps). + headerFeatures := ghcontext.GetHeaderFeatures(ctx) + mcpApps := slices.Contains(headerFeatures, github.MCPAppsFeatureFlag) || insiders + if mcpApps { + builder = builder.WithMCPApps(true) + } + toolsets := ghcontext.GetToolsets(ctx) tools := ghcontext.GetTools(ctx) diff --git a/pkg/http/server.go b/pkg/http/server.go index 55aed1c61..73b4a36ef 100644 --- a/pkg/http/server.go +++ b/pkg/http/server.go @@ -27,7 +27,9 @@ import ( // knownFeatureFlags are the feature flags that can be enabled via X-MCP-Features header. // Only these flags are accepted from headers. -var knownFeatureFlags = []string{} +var knownFeatureFlags = []string{ + github.MCPAppsFeatureFlag, +} type ServerConfig struct { // Version of the server @@ -212,7 +214,8 @@ func initGlobalToolScopeMap(t translations.TranslationHelperFunc) error { } // createHTTPFeatureChecker creates a feature checker that reads header features from context -// and validates them against the knownFeatureFlags whitelist +// and validates them against the knownFeatureFlags whitelist. +// It also handles transitional behavior where insiders mode implies remote_mcp_ui_apps. func createHTTPFeatureChecker() inventory.FeatureFlagChecker { // Pre-compute whitelist as set for O(1) lookup knownSet := make(map[string]bool, len(knownFeatureFlags)) @@ -224,6 +227,10 @@ func createHTTPFeatureChecker() inventory.FeatureFlagChecker { if knownSet[flag] && slices.Contains(ghcontext.GetHeaderFeatures(ctx), flag) { return true, nil } + // Transitional: insiders mode implies remote_mcp_ui_apps feature flag + if flag == github.MCPAppsFeatureFlag && ghcontext.IsInsidersMode(ctx) { + return true, nil + } return false, nil } } diff --git a/pkg/inventory/builder.go b/pkg/inventory/builder.go index d492e69b5..98df9166d 100644 --- a/pkg/inventory/builder.go +++ b/pkg/inventory/builder.go @@ -49,6 +49,7 @@ type Builder struct { filters []ToolFilter // filters to apply to all tools generateInstructions bool insidersMode bool + mcpApps bool } // NewBuilder creates a new Builder. @@ -155,14 +156,23 @@ func (b *Builder) WithExcludeTools(toolNames []string) *Builder { } // WithInsidersMode enables or disables insiders mode features. -// When insiders mode is disabled (default), UI metadata is removed from tools -// so clients won't attempt to load UI resources. +// When insiders mode is disabled (default), tools marked InsidersOnly are removed +// and insiders-only Meta keys are stripped. // Returns self for chaining. func (b *Builder) WithInsidersMode(enabled bool) *Builder { b.insidersMode = enabled return b } +// WithMCPApps enables or disables MCP Apps UI features. +// When disabled (default), the "ui" Meta key is stripped from tools +// so clients won't attempt to load UI resources. +// Returns self for chaining. +func (b *Builder) WithMCPApps(enabled bool) *Builder { + b.mcpApps = enabled + return b +} + // CreateExcludeToolsFilter creates a ToolFilter that excludes tools by name. // Any tool whose name appears in the excluded list will be filtered out. // The input slice should already be cleaned (trimmed, deduplicated). @@ -210,6 +220,11 @@ func (b *Builder) Build() (*Inventory, error) { tools = stripInsidersFeatures(b.tools) } + // When MCP Apps is disabled, strip UI metadata from tools + if !b.mcpApps { + tools = stripMCPAppsMetadata(tools) + } + r := &Inventory{ tools: tools, resourceTemplates: b.resourceTemplates, @@ -378,9 +393,9 @@ func (b *Builder) processToolsets() (map[ToolsetID]bool, []string, []ToolsetID, // insidersOnlyMetaKeys lists the Meta keys that are only available in insiders mode. // Add new experimental feature keys here to have them automatically stripped // when insiders mode is disabled. -var insidersOnlyMetaKeys = []string{ - "ui", // MCP Apps UI metadata -} +// Note: "ui" (MCP Apps) is now controlled by the remote_mcp_ui_apps feature flag via +// WithMCPApps and mcpAppsMetaKeys, not by insiders mode. +var insidersOnlyMetaKeys = []string{} // stripInsidersFeatures removes insiders-only features from tools. // This includes removing tools marked with InsidersOnly and stripping @@ -392,7 +407,26 @@ func stripInsidersFeatures(tools []ServerTool) []ServerTool { if tool.InsidersOnly { continue } - if stripped := stripInsidersMetaFromTool(tool); stripped != nil { + if stripped := stripMetaKeys(tool, insidersOnlyMetaKeys); stripped != nil { + result = append(result, *stripped) + } else { + result = append(result, tool) + } + } + return result +} + +// mcpAppsMetaKeys lists the Meta keys controlled by the remote_mcp_ui_apps feature flag. +var mcpAppsMetaKeys = []string{ + "ui", // MCP Apps UI metadata +} + +// stripMCPAppsMetadata removes MCP Apps UI metadata from tools when the +// remote_mcp_ui_apps feature flag is not enabled. +func stripMCPAppsMetadata(tools []ServerTool) []ServerTool { + result := make([]ServerTool, 0, len(tools)) + for _, tool := range tools { + if stripped := stripMetaKeys(tool, mcpAppsMetaKeys); stripped != nil { result = append(result, *stripped) } else { result = append(result, tool) @@ -401,30 +435,30 @@ func stripInsidersFeatures(tools []ServerTool) []ServerTool { return result } -// stripInsidersMetaFromTool removes insiders-only Meta keys from a single tool. +// stripMetaKeys removes the specified Meta keys from a single tool. // Returns a modified copy if changes were made, nil otherwise. -func stripInsidersMetaFromTool(tool ServerTool) *ServerTool { - if tool.Tool.Meta == nil { +func stripMetaKeys(tool ServerTool, keys []string) *ServerTool { + if tool.Tool.Meta == nil || len(keys) == 0 { return nil } - // Check if any insiders-only keys exist - hasInsidersKeys := false - for _, key := range insidersOnlyMetaKeys { + // Check if any of the specified keys exist + hasKeys := false + for _, key := range keys { if tool.Tool.Meta[key] != nil { - hasInsidersKeys = true + hasKeys = true break } } - if !hasInsidersKeys { + if !hasKeys { return nil } - // Make a shallow copy and remove insiders-only keys + // Make a shallow copy and remove specified keys toolCopy := tool newMeta := make(map[string]any, len(tool.Tool.Meta)) for k, v := range tool.Tool.Meta { - if !slices.Contains(insidersOnlyMetaKeys, k) { + if !slices.Contains(keys, k) { newMeta[k] = v } } diff --git a/pkg/inventory/registry_test.go b/pkg/inventory/registry_test.go index 207e65dba..0a7bd51d9 100644 --- a/pkg/inventory/registry_test.go +++ b/pkg/inventory/registry_test.go @@ -1874,24 +1874,24 @@ func TestWithInsidersMode_DisabledStripsUIMetadata(t *testing.T) { } } -func TestWithInsidersMode_EnabledPreservesUIMetadata(t *testing.T) { +func TestWithMCPApps_EnabledPreservesUIMetadata(t *testing.T) { uiData := map[string]any{"html": "
hello
"} toolWithUI := mockToolWithMeta("tool_with_ui", "toolset1", map[string]any{ "ui": uiData, "description": "kept", }) - // Insiders mode enabled - UI meta should be preserved + // MCP Apps enabled - UI meta should be preserved reg := mustBuild(t, NewBuilder(). SetTools([]ServerTool{toolWithUI}). WithToolsets([]string{"all"}). - WithInsidersMode(true)) + WithMCPApps(true)) available := reg.AvailableTools(context.Background()) require.Len(t, available, 1) // UI metadata should be preserved if available[0].Tool.Meta["ui"] == nil { - t.Errorf("Expected 'ui' meta to be preserved in insiders mode") + t.Errorf("Expected 'ui' meta to be preserved with MCP Apps enabled") } // Other metadata should also be preserved if available[0].Tool.Meta["description"] != "kept" { @@ -1933,14 +1933,14 @@ func TestWithInsidersMode_DisabledRemovesInsidersOnlyTools(t *testing.T) { require.Equal(t, "normal", available[0].Tool.Name) } -func TestWithInsidersMode_ToolsWithoutUIMetaUnaffected(t *testing.T) { +func TestWithMCPApps_ToolsWithoutUIMetaUnaffected(t *testing.T) { toolNoUI := mockToolWithMeta("tool_no_ui", "toolset1", map[string]any{ "description": "kept", "version": "1.0", }) toolNilMeta := mockTool("tool_nil_meta", "toolset1", true) - // Test with insiders disabled + // Test with MCP Apps disabled (default) - non-UI meta should be unaffected reg := mustBuild(t, NewBuilder(). SetTools([]ServerTool{toolNoUI, toolNilMeta}). WithToolsets([]string{"all"})) @@ -1973,8 +1973,8 @@ func TestWithInsidersMode_ToolsWithoutUIMetaUnaffected(t *testing.T) { } } -func TestWithInsidersMode_UIOnlyMetaBecomesNil(t *testing.T) { - // Tool with ONLY ui metadata - should become nil after stripping +func TestWithMCPApps_UIOnlyMetaBecomesNil(t *testing.T) { + // Tool with ONLY ui metadata - should become nil after stripping when MCP Apps is disabled toolUIOnly := mockToolWithMeta("tool_ui_only", "toolset1", map[string]any{ "ui": map[string]any{"html": "
hello
"}, }) @@ -1985,44 +1985,76 @@ func TestWithInsidersMode_UIOnlyMetaBecomesNil(t *testing.T) { available := reg.AvailableTools(context.Background()) require.Len(t, available, 1) - // Meta should be nil since ui was the only key + // Meta should be nil since ui was the only key and MCP Apps is off by default if available[0].Tool.Meta != nil { t.Errorf("Expected Meta to be nil after stripping only key, got %v", available[0].Tool.Meta) } } -func TestStripInsidersMetaFromTool(t *testing.T) { +func TestWithMCPApps_EnabledPreservesUIMeta(t *testing.T) { + // Tool with ui metadata - should be preserved when MCP Apps is enabled + toolWithUI := mockToolWithMeta("tool_with_ui", "toolset1", map[string]any{ + "ui": map[string]any{"html": "
hello
"}, + "description": "kept", + }) + + reg := mustBuild(t, NewBuilder(). + SetTools([]ServerTool{toolWithUI}). + WithToolsets([]string{"all"}). + WithMCPApps(true)) + available := reg.AvailableTools(context.Background()) + + require.Len(t, available, 1) + require.NotNil(t, available[0].Tool.Meta, "Meta should be preserved with MCP Apps enabled") + require.NotNil(t, available[0].Tool.Meta["ui"], "ui key should be preserved with MCP Apps enabled") + require.Equal(t, "kept", available[0].Tool.Meta["description"]) +} + +func TestStripMetaKeys(t *testing.T) { tests := []struct { name string meta map[string]any + keys []string expectChange bool expectedMeta map[string]any // nil means Meta should be nil }{ { name: "nil meta - no change", meta: nil, + keys: mcpAppsMetaKeys, expectChange: false, }, { - name: "no insiders keys - no change", + name: "no matching keys - no change", meta: map[string]any{"description": "test", "version": "1.0"}, + keys: mcpAppsMetaKeys, expectChange: false, }, { name: "ui key only - becomes nil", meta: map[string]any{"ui": "data"}, + keys: mcpAppsMetaKeys, expectChange: true, expectedMeta: nil, }, { name: "ui key with other keys - ui stripped", meta: map[string]any{"ui": "data", "description": "kept"}, + keys: mcpAppsMetaKeys, expectChange: true, expectedMeta: map[string]any{"description": "kept"}, }, { - name: "ui is nil value - no change (nil value means key not present)", + name: "ui is nil value - ui stripped", meta: map[string]any{"ui": nil, "description": "kept"}, + keys: mcpAppsMetaKeys, + expectChange: true, + expectedMeta: map[string]any{"description": "kept"}, + }, + { + name: "empty keys list - no change", + meta: map[string]any{"ui": "data"}, + keys: []string{}, expectChange: false, }, } @@ -2030,7 +2062,7 @@ func TestStripInsidersMetaFromTool(t *testing.T) { for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { tool := mockToolWithMeta("test", "toolset1", tt.meta) - result := stripInsidersMetaFromTool(tool) + result := stripMetaKeys(tool, tt.keys) if tt.expectChange { require.NotNil(t, result, "expected change but got nil") @@ -2050,14 +2082,14 @@ func TestStripInsidersMetaFromTool(t *testing.T) { } } -func TestStripInsidersFeatures(t *testing.T) { +func TestStripMCPAppsMetadata(t *testing.T) { tools := []ServerTool{ mockToolWithMeta("tool1", "toolset1", map[string]any{"ui": "data"}), mockToolWithMeta("tool2", "toolset1", map[string]any{"description": "kept"}), mockTool("tool3", "toolset1", true), // nil meta } - result := stripInsidersFeatures(tools) + result := stripMCPAppsMetadata(tools) require.Len(t, result, 3) @@ -2089,16 +2121,9 @@ func TestStripInsidersFeatures_RemovesInsidersOnlyTools(t *testing.T) { require.Equal(t, "normal2", result[1].Tool.Name) } -func TestInsidersOnlyMetaKeys_FutureAdditions(t *testing.T) { +func TestStripMetaKeys_MultipleKeys(t *testing.T) { // This test verifies the mechanism works for multiple keys - // If we add new experimental keys to insidersOnlyMetaKeys, they should be stripped - - // Save original and restore after test - originalKeys := insidersOnlyMetaKeys - defer func() { insidersOnlyMetaKeys = originalKeys }() - - // Add a hypothetical future experimental key - insidersOnlyMetaKeys = []string{"ui", "experimental_feature", "beta"} + keys := []string{"ui", "experimental_feature", "beta"} tool := mockToolWithMeta("test", "toolset1", map[string]any{ "ui": "ui data", @@ -2107,7 +2132,7 @@ func TestInsidersOnlyMetaKeys_FutureAdditions(t *testing.T) { "description": "kept", }) - result := stripInsidersMetaFromTool(tool) + result := stripMetaKeys(tool, keys) require.NotNil(t, result) require.NotNil(t, result.Tool.Meta) @@ -2117,12 +2142,12 @@ func TestInsidersOnlyMetaKeys_FutureAdditions(t *testing.T) { require.Equal(t, "kept", result.Tool.Meta["description"], "description should be preserved") } -func TestWithInsidersMode_DoesNotMutateOriginalTools(t *testing.T) { +func TestWithMCPApps_DoesNotMutateOriginalTools(t *testing.T) { originalMeta := map[string]any{"ui": "data", "description": "kept"} tool := mockToolWithMeta("test", "toolset1", originalMeta) tools := []ServerTool{tool} - // Build with insiders disabled - should strip ui + // Build with MCP Apps disabled (default) - should strip ui _ = mustBuild(t, NewBuilder().SetTools(tools).WithToolsets([]string{"all"})) // Original tool should be unchanged