[MCP Bundle] Add MCP Apps support (#[AsMcpApp] / #[AsMcpAppTool])#2237
Open
chr-hertel wants to merge 7 commits into
Open
[MCP Bundle] Add MCP Apps support (#[AsMcpApp] / #[AsMcpAppTool])#2237chr-hertel wants to merge 7 commits into
chr-hertel wants to merge 7 commits into
Conversation
794f92f to
2040e89
Compare
Contributor
|
Can you add a screencast from the new Movie MCPApp? |
Member
Author
Can show you in a few minutes in real 🥳 But will do, yes. Can you check if your MCP Apps would work with this as well? basically with less code |
2040e89 to
a7e0b52
Compare
The default render() only injected `model.html`, so an MCP App's form controls were not kept in sync with the tool result — e.g. the movie app's search box was empty on the first render even though the model had searched. render() now also copies scalar model fields into matching `[name]` controls (skipping the focused one), restoring the query in the input.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this?
Wire your Symfony services + Twig into MCP Apps — interactive HTML UIs an MCP host renders in a sandboxed iframe instead of a plain-text tool result. One class is the whole app:
#[AsMcpApp]registers the UI resource, the linked tool and the MCP Apps server extension, and the bundle ships the iframe bridge (@Mcp/app/base.html.twig). You write a tool method and a Twig template — no protocol plumbing, no client JS.A minimal app (single template)
The tool method returns a context array; the bundle renders
toolTemplateinto the result over the wire, so no Twig touches your handler:#[AsMcpApp( uri: 'ui://weather', name: 'get_weather', template: 'mcp/weather.html.twig', // static iframe shell toolTemplate: 'mcp/_weather.html.twig', // rendered into the tool result )] final class WeatherApp { public function __construct(private WeatherClient $weather) {} public function render(string $city): array { return ['forecast' => $this->weather->forecastFor($city)]; } }Adding interactive tools
Declare follow-up tools with
#[AsMcpAppTool](server side) and trigger them from the markup with the base template's declarative attributes (client side) — still no JavaScript:data-callinvokes the tool and swaps the returned HTML into#root;data-openopens an external link. It works on buttons, submit buttons (incl. the cross-DOMform="…"pattern) and anchors — verified with a jsdom harness.Notes
ReferenceHandlerdecorator renders the template into the tool result while keeping the SDK's reflection-derived input schema intact;mcp.apps.enabledtoggles the extension.demo/exposes the movie collection as an MCP App (MovieApp— searchable grid + detail), reusing the existingmovie_searchagent tool (Movieis nowJsonSerializable, so it serves both the agent and the UI).Demo
Screencast.from.2026-06-25.10-07-36.webm