Repository navigation
feat(interactive-ui): add zero-egress MCP App server and built-in catalog - #4553
josemontespg wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces the interactive-ui tool, a zero-egress MCP App server built on @a2ui/embed that allows hosting and rendering interactive A2UI v1.0 surfaces inline. It includes eight strict-CSP Lit Web Components, an MCP server, and a comprehensive suite of unit and end-to-end tests. Feedback on the changes highlights three key areas for improvement: first, the path resolution logic in server.ts should fail fast on non-existent custom paths instead of silently falling back to defaults; second, the table sorting logic in table.ts needs explicit handling for image columns to avoid sorting by stringified objects; and third, table link elements should include target='_blank' to prevent navigation issues within the sandboxed iframe.
| export function resolveDefaultAppPaths( | ||
| options: Pick<CreateInteractiveUiServerOptions, 'htmlPath' | 'catalogSchemaPath'> = {}, | ||
| ): ResolvedInteractiveUiPaths { | ||
| const here = dirname(fileURLToPath(import.meta.url)); | ||
| const envHtml = process.env['A2UI_INTERACTIVE_UI_HTML']; | ||
| const envCatalog = process.env['A2UI_INTERACTIVE_UI_CATALOG']; | ||
|
|
||
| const htmlCandidates = [ | ||
| options.htmlPath, | ||
| envHtml, | ||
| resolve(here, 'a2ui-app.html'), | ||
| resolve(here, '..', 'dist', 'a2ui-app.html'), | ||
| ].filter( | ||
| (candidate): candidate is string => typeof candidate === 'string' && candidate.length > 0, | ||
| ); | ||
|
|
||
| const htmlPath = htmlCandidates.find(candidate => existsSync(candidate)) ?? htmlCandidates[0]!; | ||
|
|
||
| const catalogCandidates = [ | ||
| options.catalogSchemaPath, | ||
| envCatalog, | ||
| htmlPath.endsWith('.html') ? htmlPath.replace(/\.html$/, '.catalog.json') : undefined, | ||
| resolve(here, 'a2ui-app.catalog.json'), | ||
| resolve(here, '..', 'dist', 'a2ui-app.catalog.json'), | ||
| ].filter( | ||
| (candidate): candidate is string => typeof candidate === 'string' && candidate.length > 0, | ||
| ); | ||
|
|
||
| const catalogSchemaPath = | ||
| catalogCandidates.find(candidate => existsSync(candidate)) ?? catalogCandidates[0]!; | ||
|
|
||
| return {htmlPath, catalogSchemaPath}; | ||
| } |
There was a problem hiding this comment.
When an explicit htmlPath or catalogSchemaPath is provided (either via options or environment variables), the server should respect those paths directly.
Currently, the candidates array includes fallback paths, and htmlCandidates.find(candidate => existsSync(candidate)) is used to select the first existing path. If a custom path is specified but does not exist yet (or fails to resolve), the server will silently fall back to the prebuilt default path instead of failing fast. This can lead to highly confusing behavior where developers believe they are running their custom build but are actually running the default prebuilt app.
Please update the resolution logic to prioritize explicit options/environment variables directly, and only use the existsSync fallback logic when no explicit path is provided.
export function resolveDefaultAppPaths(
options: Pick<CreateInteractiveUiServerOptions, 'htmlPath' | 'catalogSchemaPath'> = {},
): ResolvedInteractiveUiPaths {
const here = dirname(fileURLToPath(import.meta.url));
const envHtml = process.env['A2UI_INTERACTIVE_UI_HTML'];
const envCatalog = process.env['A2UI_INTERACTIVE_UI_CATALOG'];
const htmlPath =
options.htmlPath ||
envHtml ||
[resolve(here, 'a2ui-app.html'), resolve(here, '..', 'dist', 'a2ui-app.html')].find(candidate =>
existsSync(candidate),
) ||
resolve(here, 'a2ui-app.html');
const catalogSchemaPath =
options.catalogSchemaPath ||
envCatalog ||
(htmlPath.endsWith('.html') && existsSync(htmlPath.replace(/\.html$/, '.catalog.json'))
? htmlPath.replace(/\.html$/, '.catalog.json')
: [resolve(here, 'a2ui-app.catalog.json'), resolve(here, '..', 'dist', 'a2ui-app.catalog.json')].find(
candidate => existsSync(candidate),
) || resolve(here, 'a2ui-app.catalog.json'));
return {htmlPath, catalogSchemaPath};
}References
- When validating input or configuration data, do not silently skip invalid or malformed entries if the specification expects validation to fail. Instead, throw an appropriate validation error.
| if (kind === 'link' && typeof value === 'object' && !Array.isArray(value)) { | ||
| const rec = value as Record<string, unknown>; | ||
| return String(rec['label'] ?? rec['url'] ?? ''); | ||
| } |
There was a problem hiding this comment.
When sorting is enabled on an image column, extractComparable currently falls through to the default String(value) conversion. If the image cell value is represented as an object (e.g., {url: "...", label: "..."}), this returns "[object Object]" for all rows, making the sorting behavior arbitrary and broken.
Please add explicit handling for the image column kind in extractComparable to extract and sort by the label, alt, or url properties.
if (kind === 'link' && typeof value === 'object' && !Array.isArray(value)) {
const rec = value as Record<string, unknown>;
return String(rec['label'] ?? rec['url'] ?? '');
}
if (kind === 'image' && typeof value === 'object' && !Array.isArray(value)) {
const rec = value as Record<string, unknown>;
return String(rec['label'] ?? rec['alt'] ?? rec['url'] ?? '');
}| if (url && isSafeHttpUrl(url)) { | ||
| return html`<a class="ui-tbl__link" href=${url} rel="noopener noreferrer">${label}</a>`; | ||
| } |
There was a problem hiding this comment.
Since this MCP App is rendered inside a sandboxed iframe (typically with strict CSP and without top-level navigation permissions), clicking a standard <a> link without target="_blank" will attempt to navigate the iframe itself. This will either be blocked by the browser or fail to load due to the strict default-src 'none' CSP, replacing the interactive card with a blank screen or error.
Please add target="_blank" to the link element to ensure external links open safely in a new tab/window.
| if (url && isSafeHttpUrl(url)) { | |
| return html`<a class="ui-tbl__link" href=${url} rel="noopener noreferrer">${label}</a>`; | |
| } | |
| if (url && isSafeHttpUrl(url)) { | |
| return html`<a class="ui-tbl__link" href=${url} target="_blank" rel="noopener noreferrer">${label}</a>`; | |
| } |
d2464a4 to
c8c4b91
Compare
0ce128a to
c1bf913
Compare
c8c4b91 to
a9c074f
Compare
c1bf913 to
a409c0d
Compare
Summary
Problem: End users on third-party MCP Apps hosts (VS Code, Cursor, Windsurf, Claude Desktop, Antigravity, Goose, OpenAI Codex Desktop) need a zero-code, zero-egress MCP App server built on
@a2ui/embedso they can render interactive A2UI v1.0 cards inline without writing server code or opening outbound network channels.This PR adds the
tools/interactive-ui/workspace (@a2ui/interactive-ui). The server exposesget_ui_guideandrender_ui_cardover@a2ui/embed/mcp/expresswith built-in safesubmitfollow-up support and zero outbound HTTP requests. Its single-file HTML bundle pairs the A2UI v1.0 Basic Catalog with a private superset of 8 strict-CSP Lit Web Components so host models can compose decision cards, sortable tables, inline SVG charts, KPI strips, steppers, progress bars, badges, and collapsibles in both light and dark host themes.Changes
tools/interactive-ui/src/catalog/: Private superset ofbasicCatalog(interactiveUiCatalog) addingChoiceCards,Table,Chart,Badge,ProgressBar,Stepper,Collapsible, andKpiStrip.isSafeImageUrlaccepts inline rasterdata:image/*URIs only and rejects externalhttp:/https:URLs to keep rendering strictly zero-egress.tools/interactive-ui/src/{server,stdio,cli,examples}.ts: Zero-egress MCP server factory (createInteractiveUiServer), standalone runtime-only stdio entrypoint (stdio.ts, free of@a2ui/embed/buildfor single-file bundling), developer CLI (cli.tswith--configsupport), and verified Express examples.tools/interactive-ui/skills/interactive-ui/SKILL.mdandREADME.md: Companion agent skill and package documentation.tools/interactive-ui/src/server.test.tsandscripts/e2e.mjs: Vitest unit and integration suite plus Playwright strict-CSP (default-src 'none') browser E2E suite.yarn.lock: Registers the@a2ui/interactive-uiworkspace under existingtools/*glob.Verification
yarn workspace @a2ui/interactive-ui run build: Wrotedist/a2ui-app.html(1.00 MiB) anddist/a2ui-app.catalog.json.yarn workspace @a2ui/interactive-ui run test: 8/8 Vitest tests passed, including zero-egressfetchspy and custom--configbuild tests.yarn workspace @a2ui/interactive-ui run lintandformat:check: 0 ESLint errors/warnings and Prettier clean.yarn workspace @a2ui/interactive-ui run e2e: 7/7 Playwright strict-CSP checks passed across dark and light host themes with 0 CSP violations, 0 external network requests, and 0 console errors.