Skip to content

feat(interactive-ui): add zero-egress MCP App server and built-in catalog - #4553

Draft
josemontespg wants to merge 1 commit into
embed/6-expressfrom
interactive-ui/1-server
Draft

josemontespg wants to merge 1 commit into
embed/6-expressfrom
interactive-ui/1-server

Conversation

@josemontespg

Copy link
Copy Markdown
Collaborator

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/embed so 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 exposes get_ui_guide and render_ui_card over @a2ui/embed/mcp/express with built-in safe submit follow-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 of basicCatalog (interactiveUiCatalog) adding ChoiceCards, Table, Chart, Badge, ProgressBar, Stepper, Collapsible, and KpiStrip. isSafeImageUrl accepts inline raster data:image/* URIs only and rejects external http:/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/build for single-file bundling), developer CLI (cli.ts with --config support), and verified Express examples.
  • tools/interactive-ui/skills/interactive-ui/SKILL.md and README.md: Companion agent skill and package documentation.
  • tools/interactive-ui/src/server.test.ts and scripts/e2e.mjs: Vitest unit and integration suite plus Playwright strict-CSP (default-src 'none') browser E2E suite.
  • yarn.lock: Registers the @a2ui/interactive-ui workspace under existing tools/* glob.

Verification

  • yarn workspace @a2ui/interactive-ui run build: Wrote dist/a2ui-app.html (1.00 MiB) and dist/a2ui-app.catalog.json.
  • yarn workspace @a2ui/interactive-ui run test: 8/8 Vitest tests passed, including zero-egress fetch spy and custom --config build tests.
  • yarn workspace @a2ui/interactive-ui run lint and format: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.

@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 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.

Comment on lines +74 to +106
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};
}

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.

medium

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
  1. 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.

Comment on lines +129 to +132
if (kind === 'link' && typeof value === 'object' && !Array.isArray(value)) {
const rec = value as Record<string, unknown>;
return String(rec['label'] ?? rec['url'] ?? '');
}

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.

medium

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'] ?? '');
  }

Comment on lines +461 to +463
if (url && isSafeHttpUrl(url)) {
return html`<a class="ui-tbl__link" href=${url} rel="noopener noreferrer">${label}</a>`;
}

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.

medium

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.

Suggested change
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>`;
}

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