Skip to content

Register MCP App UI resources in shared server constructor#2570

Merged
SamMorrowDrums merged 1 commit into
mainfrom
sammorrowdrums/register-ui-resources-in-http
May 29, 2026
Merged

Register MCP App UI resources in shared server constructor#2570
SamMorrowDrums merged 1 commit into
mainfrom
sammorrowdrums/register-ui-resources-in-http

Conversation

@SamMorrowDrums
Copy link
Copy Markdown
Collaborator

Fixes #2467

Bug

When the remote_mcp_ui_apps feature flag is enabled per-request on the remote/HTTP server (api.githubcopilot.com/mcp/), tools like issue_write and create_pull_request advertise a ui://github-mcp-server/... resource URI in their _meta.ui block and tell the model "click Submit in the form". The client then tries to load that resource via resources/read, but the resource was never registered on the HTTP server — RegisterUIResources was only called from the stdio bootstrap in internal/ghmcp/server.go. The read fails with -32002 Resource not found, which VS Code surfaces as:

Error loading MCP App: MPC -32002: Resource not found

The stdio bootstrap was also subtly fragile: it gated registration on featureChecker(context.Background(), MCPAppsFeatureFlag), which can't see per-request flag overrides (insiders URL, X-MCP-Features header).

Fix

Move the RegisterUIResources call into pkg/github.NewMCPServer — the shared constructor used by both the stdio and HTTP paths — gated only on UIAssetsAvailable(). The resources are inert static HTML embedded at build time; the inventory still strips _meta.ui from tools per-request via stripMCPAppsMetadata, so a client only sees the URI when the feature flag is actually on for that request.

Tests

Added pkg/github/ui_resources_test.go with two tests that reproduce the user's bug without VS Code:

  1. TestRegisterUIResources_ReadableViaClient — registers the resources and confirms every advertised URI (get-me, issue-write, pr-write) resolves via resources/read.
  2. TestNewMCPServer_RegistersUIResources — exercises the shared constructor that the HTTP handler uses and proves the URI is readable end-to-end through an in-memory MCP client.

Both tests fail with the exact calling "resources/read": Resource not found error before this change and pass after. They skip when script/build-ui hasn't been run, matching the existing pattern in mcp-diff.yml.

script/lint, script/test, and script/generate-docs all clean.

The remote/HTTP server never called RegisterUIResources, so when the
remote_mcp_ui_apps feature flag was enabled per-request, tools like
issue_write and create_pull_request would advertise a ui:// resource URI
in their _meta.ui block but the resource itself was not registered. The
client's follow-up resources/read call then failed with -32002 'Resource
not found' (the error surfaced as 'Error loading MCP App: MPC -32002:
Resource not found' in VS Code).

The stdio bootstrap also gated registration on featureChecker called
with context.Background(), which can't see per-request flag overrides.

Move RegisterUIResources into pkg/github.NewMCPServer (the shared
constructor used by both stdio and HTTP), gated only on
UIAssetsAvailable(). The resources are inert static HTML; the inventory
still strips _meta.ui from tools per-request via stripMCPAppsMetadata,
so the URI is only advertised to clients when the flag is on for that
request.

Fixes #2467

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@SamMorrowDrums SamMorrowDrums requested a review from a team as a code owner May 29, 2026 09:39
Copilot AI review requested due to automatic review settings May 29, 2026 09:39
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a remote/HTTP MCP server bug where tools could advertise ui://github-mcp-server/... MCP App resource URIs (via _meta.ui when remote_mcp_ui_apps is enabled per-request), but the corresponding UI resources were only registered in the stdio bootstrap—causing resources/read to fail with -32002 Resource not found in clients like VS Code.

Changes:

  • Move RegisterUIResources into the shared pkg/github.NewMCPServer constructor (gated by UIAssetsAvailable()), so both stdio and HTTP servers register the UI resources.
  • Remove the stdio-only UI resource registration block from internal/ghmcp/server.go.
  • Add regression tests that verify advertised ui:// URIs resolve via resources/read, including an end-to-end in-memory client/server test through NewMCPServer.
Show a summary per file
File Description
pkg/github/server.go Registers embedded MCP App UI resources in the shared server constructor so HTTP/remote servers serve ui:// resources too.
internal/ghmcp/server.go Removes stdio-only UI resource registration now that it’s handled in the shared constructor.
pkg/github/ui_resources_test.go Adds regression coverage ensuring UI resource URIs are actually readable via resources/read, including through NewMCPServer.

Copilot's findings

  • Files reviewed: 3/3 changed files
  • Comments generated: 1

Comment thread pkg/github/server.go
Comment on lines +113 to +115
if UIAssetsAvailable() {
RegisterUIResources(ghServer)
}
@SamMorrowDrums SamMorrowDrums merged commit 3fbf64f into main May 29, 2026
20 checks passed
@SamMorrowDrums SamMorrowDrums deleted the sammorrowdrums/register-ui-resources-in-http branch May 29, 2026 10:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[vscode] Error loading MCP App: MPC -32002: Resource not found

2 participants