Skip to content

Extract a shared MCP Apps host package to remove per-framework duplication #6823

Closed

Description

@yannj-fr

Summary

The MCP Apps host is currently re-implemented once per frontend framework, each hand-rolling the app↔host protocol:

  • React: packages/react-core/src/v2/components/MCPAppsActivityRenderer.tsx
  • Vue: packages/vue/src/v2/components/MCPAppsActivityRenderer.ts
  • Angular: packages/angular/src/mcp-apps/lib/*

This triplication is the root cause of recurring drift between hosts. #6707 migrated the React host onto @modelcontextprotocol/ext-apps (AppBridge + PostMessageTransport), which ties it to the spec at compile time — but Vue and Angular still hand-roll everything, so the same widget now behaves differently depending on the host framework.

Proposal: a shared mcp-apps-support package

Extract a single, framework-agnostic package (working name @copilotkit/mcp-apps-support) that owns the whole host protocol layer on top of @modelcontextprotocol/ext-apps, and have each framework renderer become a thin adapter that only:

  1. creates/attaches the sandbox iframe in its own render model, and
  2. wires framework-specific glue (agent access, state updates).

The shared core would own everything that is currently copy-pasted and drifting:

  • AppBridge + PostMessageTransport wiring and the sandbox-proxy relay (buildSandboxHTML)
  • protocol-version negotiation (single LATEST_PROTOCOL_VERSION source)
  • host-context seeding (theme/platform, and later display-mode / available-display-modes)
  • the CopilotKit behaviors: tools/call proxy + request queue, ui/message role/followUp extensions via _meta.copilotkit, thread-capture semantics (🐛 Bug: MCP app ui/message follow-up work can lose its enqueue-time thread context #5819), ui/open-link scheme denylist, tool-input/result forwarding

Why now (concrete drift this removes)

Protocol version is the clearest example. After #6707, React negotiates the MCP Apps protocol version 2026-01-26 (via ext-apps LATEST_PROTOCOL_VERSION), while Vue and Angular still hardcode 2025-06-18:

  • packages/vue/src/v2/components/MCPAppsActivityRenderer.ts:9 — const PROTOCOL_VERSION = "2025-06-18";
  • packages/angular/src/mcp-apps/lib/mcp-apps-widget.ts:25 — const PROTOCOL_VERSION = "2025-06-18";

Note 2025-06-18 is a base MCP protocol version, independent from the MCP Apps protocol (2026-01-26) — so these hosts are not just behind, they are advertising a version from a different spec line. Historically the same duplication produced other drift too (e.g. size-change vs the spec's size-changed, CSP directive mapping, incomplete capabilities). A shared package fixes this class of bug by construction.

Scope / sequencing

  • React is the pilot (feat(react-core): migrate MCP Apps host to @modelcontextprotocol/ext-apps (AppBridge) #6707); it already consumes ext-apps directly and can be refactored to consume the shared package once it exists.
  • Vue and Angular migrate onto the shared package next, deleting their hand-rolled protocol code.
  • Follow-up work (display-mode, update-model-context, theme host-context) then lands once in the shared package and is available to all three frameworks.

Refs: #6707

Activity

  1. copilotkit-outpost-bot commented on Sep 1, 2026

    @copilotkit-outpost-bot

    ⚠️ This is an AI-generated response. We've escalated this to our engineering team — someone will follow up in this thread shortly.

    Thanks for the detailed write-up. I want to be upfront about what I can and can't do here before responding.

    What I can see vs. what I can't

    My documentation context covers the user-facing MCP Apps integration (middleware setup, MCPAppsMiddleware, serverId configuration, etc.) — not CopilotKit's internal package structure or source files. So I haven't read the files you're referencing (MCPAppsActivityRenderer.tsx, mcp-apps-widget.ts, etc.), and I can't verify the specific drift you're describing.

    That said, the architectural proposal itself is something I can engage with meaningfully.


    On the proposal

    The core argument — that triplicating a protocol implementation across React/Vue/Angular creates a structural drift problem that a shared package fixes by construction — is a sound software engineering position. The protocol-version example you cite is a concrete, falsifiable illustration of the problem class, not just a theoretical concern.

    A few things worth the team considering as they evaluate scope:

    • Iframe lifecycle ownership is the trickiest part of "thin adapter" claims. Each framework has meaningfully different opinions about when DOM nodes are created, destroyed, and re-used (React's reconciler, Vue's virtual DOM, Angular's change detection + ViewContainerRef). The shared package's API surface will need to be designed so the adapter boundary is at the right level — too high and you leak framework assumptions into the core, too low and adapters still hand-roll too much.

    • The buildSandboxHTML / CSP surface is a good candidate for shared ownership precisely because it's security-relevant and currently the kind of thing that gets quietly diverged (as you note with the CSP directive mapping history).

    • Sequencing risk: if React is already on ext-apps and Vue/Angular are not, there's a window where the shared package is being built while two frameworks are still on the old path. Worth being explicit about whether Vue/Angular get a direct migration or go through an intermediate "shared package v1" step.


    What I'd suggest

    Since this is an architectural proposal touching internals across multiple packages, the right people to evaluate the tradeoffs are the CopilotKit maintainers directly — which is exactly where this issue already is. I don't have visibility into the team's current roadmap, package ownership, or whether there are constraints (e.g., bundle-size targets, monorepo tooling) that would affect the design.

    The proposal is well-structured and the drift evidence is specific — that's the right format for the team to act on it. If you haven't already, tagging the maintainers who worked on #6707 would get it in front of the people with the most context on the ext-apps migration.

    Was there a specific technical question about the user-facing MCP Apps behavior I can help with in the meantime?


    🤖 Generated by CopilotKit AI Support · Documentation


    Was this helpful? React with 👍 or 👎

  2. yannj-fr commented on Sep 4, 2026

    @yannj-fr
    ContributorAuthor

    PR #6884 delivers the shared package + React pilot for this. Two pieces are deliberately deferred to the Vue/Angular follow-up and tracked here so they are not lost:

    • <copilotkit-mcp-app> web component (the intended shared consumption path for React/Vue/Angular): built, then pulled from the React-pilot PR since nothing consumes it there. Lands with the Vue/Angular adapters, its first real consumer.
    • Self-driving message forwarding (F8): bindMcpApp is push-driven in the pilot (the adapter forwards tool input/result). The framework-agnostic end state is a self-subscribing core (messageId + onActivitySnapshotEvent/onActivityDeltaEvent + self-push, unsubscribe in teardown), landing alongside the Vue/Angular adapters that benefit most from it.
  3. yannj-fr commented on Sep 9, 2026

    @yannj-fr
    ContributorAuthor

    Status update

    The React pilot (PR #6884) is essentially done and awaiting approval. Progress against this issue:

    Delivered in #6884

    • New framework-agnostic package @copilotkit/mcp-apps-renderer owning the whole app/host protocol layer on top of @modelcontextprotocol/ext-apps (bindMcpApp: AppBridge + PostMessage transport, sandbox proxy, per-thread request queue, ui/message role/followUp with 🐛 Bug: MCP app ui/message follow-up work can lose its enqueue-time thread context #5819 thread capture, ui/open-link scheme denylist, tools/call + resources/read proxy, tool input/result forwarding).
    • react-core reduced to a thin adapter over bindMcpApp (786 -> ~250 LOC), dropping its direct @modelcontextprotocol/ext-apps dependency and the @modelcontextprotocol/sdk peer (FR-007). The package is now the sole owner of the MCP libraries.
    • Bridge-free ./activity subpath so registering the activity never pulls the ext-apps bundle (the lazy import() keeps the bridge out of the eager chunk; measured zero net bundle cost).
    • Single source of LATEST_PROTOCOL_VERSION, sourced from the bridge itself (no hand-maintained literal).
    • Validated: package + react-core MCP e2e suites green, public API manifest regenerated, and a real-browser smoke test in Chrome (widget renders, full ext-apps handshake, size-changed, tool result).

    Next (own PRs, behavior-changing for their users)

    • Vue and Angular adapters migrate onto the package, deleting their hand-rolled protocol and per-framework PROTOCOL_VERSION (this is what removes the 2025-06-18 vs 2026-01-26 drift described above).
    • The <copilotkit-mcp-app> web component (the intended shared consumption path) lands with the Vue/Angular PR, its first real consumer.
    • Self-driving message forwarding (F8): bindMcpApp gains an optional self-subscribing mode (messageId + activity subscription + self-push) so all three adapters inherit forwarding for free.

    Related follow-up

  4. yannj-fr commented on Sep 15, 2026

    @yannj-fr
    ContributorAuthor

    Vue and Angular are now migrated in #7161, which completes the sequencing described above: React was the pilot (#6707, #6884), and the two remaining hosts delete their hand-rolled protocol code rather than keeping a second copy.

    Status against the scope listed in this issue:

    Item State
    AppBridge + PostMessageTransport + sandbox relay shared
    protocol-version negotiation (single source) shared. The 2025-06-18 literals quoted above are gone from both hosts
    host-context seeding shared, and now configurable (hostInfo / hostCapabilities / hostContext), which absorbs Angular's MCP_APPS_CONFIG
    tools/call proxy + request queue shared
    ui/message role/followUp via _meta.copilotkit shared. Vue and Angular gain the extension channel
    thread-capture semantics (#5819) shared, and extended to the resources/read and tools/call proxies, which no host guarded
    ui/open-link scheme denylist shared, single policy for the three frontends
    tool input/result forwarding shared, driven by the session itself

    Two things worth recording, because they were not simply a move:

    The extraction happened before Vue and Angular moved onto it, so the shared host carried React's behaviour and none of the protections those two enforced locally. Migrating as-is would have dropped them. The queue now owns per-widget cancellation and agent+thread keying (from Angular) and the busy-agent timeout (from Vue); the session owns URI-based resource selection and UTF-8 base64 decoding (from Angular, where React and Vue had the bug: atob mangled non-ASCII widget HTML).

    The link policy diverged rather than converged at first. Angular restricted to http(s), which predated the decision to allow app-defined deep links. Keeping that as a per-framework option would have meant the same widget behaving differently depending on the host, with no way for an application to choose, since no adapter exposed the setting. The policies are merged instead: the denylist stays, and the two guarantees only Angular had (embedded credentials refused, relative paths resolved) now apply everywhere.

    Follow-up work named in this issue (display-mode, update-model-context, theme host-context) can now land once in the shared package.

  5. added a commit that references this issue on Oct 2, 2026
    06f61ae
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions