Skip to content

feat(embed): add @a2ui/embed/mcp/express for host-authored Express - #4504

Draft
josemontespg wants to merge 1 commit into
embed/5-markdownfrom
embed/6-express
Draft

josemontespg wants to merge 1 commit into
embed/5-markdownfrom
embed/6-express

Conversation

@josemontespg

Copy link
Copy Markdown
Collaborator

Summary

Adds an optional @a2ui/embed/mcp/express entry point so an MCP server can let the host model author A2UI Express directly without running a server-side LLM.

registerExpressTools(app, options) registers two tools on top of createA2uiApp: a plain-text guide tool (get_a2ui_guide) that documents the app's catalogs, examples, and registered actions, and an MCP App render tool (render_a2ui) that compiles Express into validated v1.0 A2UI messages inside structuredContent.a2ui. It supports standalone rendering kits via allowSubmit: true, backend-connected servers via authoritative resolveDataRef merging (with editableKeys and component guards), and pre-validation post-processing via transformMessages (such as server-side image hydration under strict CSP).

Changes

  • typescript/embed/src/mcp/express/register_express_tools.ts: Implement registerExpressTools with optional allowSubmit, resolveDataRef, transformMessages, examples, and custom tool naming/summary hooks.
  • typescript/embed/src/mcp/express/compile_express.ts: Compile Express to v1.0 messages, strip accidental code fences or <a2ui> wrappers, enable sendDataModel by default, and merge authoritative dataRef slices while respecting editableKeys.
  • typescript/embed/src/mcp/express/load_catalogs.ts: Load @a2ui/agent catalogs from a2ui-app.catalog.json, normalizing flattened @-prefixed protocol mixins back to allOf $refs so InMemoryCatalogProvider loads basicCatalog + custom catalogs losslessly.
  • typescript/embed/src/mcp/server/{app_internals.ts,create_a2ui_app.ts}: Associate McpServer and loaded CatalogSchemaFile with an A2uiApp instance via a package-internal WeakMap.
  • typescript/embed/src/mcp/express/register_express_tools.test.ts: Add unit tests covering multi-catalog Express compilation, allowSubmit, dataRef authoritative override + editableKeys + component guards, error diagnostics, transformMessages + post-transform validation, and catalog subsetting.
  • typescript/embed/{package.json,CHANGELOG.md} & yarn.lock: Export ./mcp/express, add @a2ui/agent as an optional peer dependency, and record the unreleased changelog entry.

Verification

  • yarn --cwd embed build, yarn --cwd embed test (Node, Karma, and Playwright E2E), yarn --cwd embed test:types, yarn --cwd embed lint, and yarn --cwd embed format:check all pass locally.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request introduces the @a2ui/embed/mcp/express module, enabling MCP servers to allow host models to author A2UI Express directly. It adds tools for retrieving the Express guide (get_a2ui_guide) and compiling/rendering the Express DSL (render_a2ui). The review feedback identifies a high-severity issue in register_express_tools.ts where the surfaceId passed to resolveDataRef can be incorrect if it is overridden inside the Express DSL but omitted in the tool arguments. To resolve this, it is recommended to compile the Express DSL first to extract the actual resolved surfaceId before invoking resolveDataRef.

This branch has not been deployed

No deployments
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.

1 participant