MCPcopy
hub / github.com/github/github-mcp-server / TestInsidersRoutePreservesUIMeta

Function TestInsidersRoutePreservesUIMeta

pkg/http/handler_test.go:871–906  ·  view source on GitHub ↗

TestInsidersRoutePreservesUIMeta is a regression test for the bug where _meta.ui was stripped from tools/list responses on the HTTP /insiders route. Before the fix: - buildStaticInventory called Build() on a builder configured with the HTTP feature checker (which reads insiders mode from the reques

(t *testing.T)

Source from the content-addressed store, hash-verified

869// - RegisterTools applies the strip per-request, using the request context
870// where the HTTP feature checker correctly observes insiders mode.
871func TestInsidersRoutePreservesUIMeta(t *testing.T) {
872 const uiURI = "ui://test/widget"
873 uiTool := mockTool("with_ui", "repos", true)
874 uiTool.Tool.Meta = mcp.Meta{"ui": map[string]any{"resourceUri": uiURI}}
875
876 checker := createHTTPFeatureChecker(nil, false)
877 build := func() *inventory.Inventory {
878 inv, err := inventory.NewBuilder().
879 SetTools([]inventory.ServerTool{uiTool}).
880 WithFeatureChecker(checker).
881 WithToolsets([]string{"all"}).
882 Build()
883 require.NoError(t, err)
884 return inv
885 }
886
887 // Simulate a /insiders request: ctx has insiders mode set.
888 insidersCtx := ghcontext.WithInsidersMode(context.Background(), true)
889
890 // AvailableTools no longer strips _meta.ui (post-fix), regardless of ctx.
891 // The strip lives in RegisterTools, gated on the per-request FF check.
892 insidersTools := build().AvailableTools(insidersCtx)
893 plainTools := build().AvailableTools(context.Background())
894
895 // On the /insiders path, the FF check returns true → no strip → _meta preserved.
896 enabled, _ := checker(insidersCtx, "remote_mcp_ui_apps")
897 require.True(t, enabled, "FF should be on for /insiders ctx")
898 require.Len(t, insidersTools, 1)
899 require.NotNil(t, insidersTools[0].Tool.Meta, "_meta should be present on /insiders")
900 require.Equal(t, uiURI, insidersTools[0].Tool.Meta["ui"].(map[string]any)["resourceUri"])
901
902 // On the non-insiders path, RegisterTools strips _meta.ui.
903 plainEnabled, _ := checker(context.Background(), "remote_mcp_ui_apps")
904 require.False(t, plainEnabled, "FF should be off for non-insiders ctx")
905 require.Len(t, plainTools, 1)
906}
907
908// TestUIMetaStrippedWhenClientLacksCapability verifies that even on the
909// /insiders path (where the feature flag is on), UI metadata is stripped from

Callers

nothing calls this directly

Calls 8

NewBuilderFunction · 0.92
createHTTPFeatureCheckerFunction · 0.85
BuildMethod · 0.80
WithToolsetsMethod · 0.80
WithFeatureCheckerMethod · 0.80
SetToolsMethod · 0.80
AvailableToolsMethod · 0.80
mockToolFunction · 0.70

Tested by

no test coverage detected