Skip to content
Merged
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/deploy_pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ jobs:
- name: Build Production Shell & Catalogs with Correct Base URLs
run: |
yarn workspace ng-basic-catalog run build --base-href=/composer/samples/ng-basic-catalog/
yarn workspace ng-basic-with-mcp-catalog run build --base-href=/composer/samples/ng-basic-with-mcp-catalog/
yarn workspace a2ui-composer-shell run build --base-href=/composer/
yarn workspace lit-basic-catalog run build --base=/composer/samples/lit-basic-catalog/
yarn workspace react-basic-catalog run build --base=/composer/samples/react-basic-catalog/
Expand All @@ -74,6 +75,7 @@ jobs:
- name: Assemble Staging Directory (deploy_dist)
run: |
mkdir -p deploy_dist/samples/ng-basic-catalog
mkdir -p deploy_dist/samples/ng-basic-with-mcp-catalog
mkdir -p deploy_dist/samples/lit-basic-catalog
mkdir -p deploy_dist/samples/react-basic-catalog

Expand All @@ -84,13 +86,19 @@ jobs:
cp -r shell/dist/a2ui-composer/. deploy_dist/
fi

# Stage Angular Sample
# Stage Angular Samples
if [ -d "samples/ng-basic-catalog/dist/ng-basic-catalog/browser" ]; then
cp -r samples/ng-basic-catalog/dist/ng-basic-catalog/browser/. deploy_dist/samples/ng-basic-catalog/
else
cp -r samples/ng-basic-catalog/dist/ng-basic-catalog/. deploy_dist/samples/ng-basic-catalog/
fi

if [ -d "samples/ng-basic-with-mcp-catalog/dist/ng-basic-with-mcp-catalog/browser" ]; then
cp -r samples/ng-basic-with-mcp-catalog/dist/ng-basic-with-mcp-catalog/browser/. deploy_dist/samples/ng-basic-with-mcp-catalog/
else
cp -r samples/ng-basic-with-mcp-catalog/dist/ng-basic-with-mcp-catalog/. deploy_dist/samples/ng-basic-with-mcp-catalog/
fi

# Stage Vite Samples
cp -r samples/lit-basic-catalog/dist/. deploy_dist/samples/lit-basic-catalog/
cp -r samples/react-basic-catalog/dist/. deploy_dist/samples/react-basic-catalog/
Expand Down
8 changes: 8 additions & 0 deletions .github/workflows/pr_preview_build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,13 +73,15 @@ jobs:
PR_NUM: ${{ github.event.pull_request.number }}
run: |
yarn workspace ng-basic-catalog run build --base-href=/composer/pr/${PR_NUM}/samples/ng-basic-catalog/
yarn workspace ng-basic-with-mcp-catalog run build --base-href=/composer/pr/${PR_NUM}/samples/ng-basic-with-mcp-catalog/
yarn workspace a2ui-composer-shell run build --base-href=/composer/pr/${PR_NUM}/
yarn workspace lit-basic-catalog run build --base=/composer/pr/${PR_NUM}/samples/lit-basic-catalog/
yarn workspace react-basic-catalog run build --base=/composer/pr/${PR_NUM}/samples/react-basic-catalog/

- name: Assemble Staging Directory (deploy_dist)
run: |
mkdir -p deploy_dist/samples/ng-basic-catalog
mkdir -p deploy_dist/samples/ng-basic-with-mcp-catalog
mkdir -p deploy_dist/samples/lit-basic-catalog
mkdir -p deploy_dist/samples/react-basic-catalog

Expand All @@ -95,6 +97,12 @@ jobs:
cp -r samples/ng-basic-catalog/dist/ng-basic-catalog/. deploy_dist/samples/ng-basic-catalog/
fi

if [ -d "samples/ng-basic-with-mcp-catalog/dist/ng-basic-with-mcp-catalog/browser" ]; then
cp -r samples/ng-basic-with-mcp-catalog/dist/ng-basic-with-mcp-catalog/browser/. deploy_dist/samples/ng-basic-with-mcp-catalog/
else
cp -r samples/ng-basic-with-mcp-catalog/dist/ng-basic-with-mcp-catalog/. deploy_dist/samples/ng-basic-with-mcp-catalog/
fi

cp -r samples/lit-basic-catalog/dist/. deploy_dist/samples/lit-basic-catalog/
cp -r samples/react-basic-catalog/dist/. deploy_dist/samples/react-basic-catalog/

Expand Down
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ flowchart TD
The ecosystem is architected as a modular, highly cohesive monorepo utilizing
**Yarn v4 Workspaces**:

| Workspace | Package Name | Description & Core Responsibilities |
| :------------- | :----------------------------------------------------------------- | :---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`shell/`** | `a2ui-composer-shell` | Standalone web application hosting chat panel, live JSON editors, real-time iframe preview wrapper, debugging suite, interactive mock rules manager, and IndexedDB storage engines. |
| **`bridge/`** | `a2ui-bridge` | ESBuild-bundled lightweight cross-frame JavaScript library embedded inside child rendering iframes. |
| **`samples/`** | `ng-basic-catalog`<br>`lit-basic-catalog`<br>`react-basic-catalog` | Plug-and-play developer renderer sandbox applications demonstrating zero-boilerplate integration across Lit, Angular, and React rendering stacks. |
| Workspace | Package Name | Description & Core Responsibilities |
| :------------- | :------------------------------------------------------------------------------------------------ | :------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| **`shell/`** | `a2ui-composer-shell` | Standalone web application hosting chat panel, live JSON editors, real-time iframe preview wrapper, debugging suite, interactive mock rules manager, and IndexedDB storage engines. |
| **`bridge/`** | `a2ui-bridge` | ESBuild-bundled lightweight cross-frame JavaScript library embedded inside child rendering iframes. |
| **`samples/`** | `ng-basic-catalog`<br>`ng-basic-with-mcp-catalog`<br>`lit-basic-catalog`<br>`react-basic-catalog` | Plug-and-play developer renderer sandbox applications demonstrating zero-boilerplate integration across Lit, Angular, and React rendering stacks, plus an Angular renderer with MCP catalog integration. |

## Getting Started

Expand All @@ -118,14 +118,20 @@ yarn install
# ng-basic-catalog starts on localhost:3456
# lit-basic-catalog starts on localhost:3457
# react-basic-catalog starts on localhost:3458
# ng-basic-with-mcp-catalog starts on localhost:3459
yarn --cwd samples/ng-basic-catalog start
yarn --cwd samples/lit-basic-catalog start
yarn --cwd samples/react-basic-catalog start
yarn --cwd samples/ng-basic-with-mcp-catalog start

# Launch standalone interactive development shell on http://localhost:4200
yarn --cwd shell start
```

### Angular Basic with MCP Renderer (`ng-basic-with-mcp-catalog`)

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.

This comment seems out of place -- it takes the two paragraphs that used to follow and moves them into this new section, where they don't belong.


`samples/ng-basic-with-mcp-catalog` provides a standalone Angular renderer configured with the `basic_with_mcp` catalog (`https://a2ui.org/specification/v0_9/catalogs/basic_with_mcp/catalog.json`). Unlike the standard basic catalog renderers (`ng-basic-catalog`, `lit-basic-catalog`, and `react-basic-catalog`), this renderer exposes the Model Context Protocol (**MCP**) catalog functions (`callMcpTool`, `jmespath`, `split`, `regexCapture`, `regexReplace`, and `updateDataModel`). When selected in Settings alongside active HTTP MCP servers, the Gemini assistant automatically includes the discovered MCP tools in its system instructions so generated A2UI surfaces can invoke live MCP tools directly.

When the A2UI Composer starts, if this is your first time using it, you'll be
automatically routed to the Settings page, where you will need to enter the URL
of the renderer app you want to use (e.g., "http://localhost:3456).
Expand Down
8 changes: 8 additions & 0 deletions bridge/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,17 @@
"prettier:check": "prettier --ignore-path ../.prettierignore --check .",
"lint": "eslint ."
},
"dependencies": {
"@a2ui/web_core": "0.10.5",
"@modelcontextprotocol/sdk": "portal:../../a2ui/node_modules/@modelcontextprotocol/sdk",
"jmespath": "portal:../../a2ui/node_modules/jmespath",
"re2js": "portal:../../a2ui/node_modules/re2js",
"zod": "^4.1.12"

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.

We shouldn't use the ^ prefix. Along with the ~ prefix, it means we never really know what versions are being used.

},
"devDependencies": {
"@angular/core": "22.0.7",
"@lit/context": "1.1.6",
"@types/jmespath": "portal:../../a2ui/node_modules/@types/jmespath",
"@types/react": "19.2.17",
"@types/react-dom": "19.2.3",
"@vitest/coverage-v8": "4.1.10",
Expand Down
6 changes: 5 additions & 1 deletion bridge/src/angular/angular-bridge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,11 @@ describe('Angular Sandbox Connection Spec', () => {
// 2. Verify A2UI_RENDERER_CONFIG factory and actionHandler
const config = TestBed.inject(A2UI_RENDERER_CONFIG);

expect(config.catalogs).toEqual([mockCatalogInstance]);
expect(config.catalogs).toHaveLength(2);
expect((config.catalogs[0] as {id: string}).id).toBe(
'https://a2ui.org/specification/v0_9/catalogs/basic_with_mcp/catalog.json',
);
expect(config.catalogs[1]).toBe(mockCatalogInstance);

const sendActionSpy = vi.spyOn(a2uiBridge, 'sendAction');
const dummyAction: A2uiClientAction = {
Expand Down
34 changes: 32 additions & 2 deletions bridge/src/angular/angular-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,28 @@ import {
A2UI_RENDERER_CONFIG,
provideMarkdownRenderer,
} from '@a2ui/angular/v0_9';
import {Catalog, ComponentApi} from '@a2ui/web_core/v0_9';
import {Catalog, ComponentApi, FunctionImplementation} from '@a2ui/web_core/v0_9';
import {
a2uiBridge,
ThemePreference,
RendererProcessor,
SurfaceStateSubscription,
CatalogDetails,
createMcpCatalogFunctions,
type ComponentUsages,
} from '../index.js';

export const BASIC_WITH_MCP_CATALOG_ID =
'https://a2ui.org/specification/v0_9/catalogs/basic_with_mcp/catalog.json';

function extractCatalogEntries<T>(collection?: ReadonlyMap<string, T> | Record<string, T>): T[] {
if (!collection) return [];
if (typeof (collection as ReadonlyMap<string, T>).values === 'function') {
return Array.from((collection as ReadonlyMap<string, T>).values());
}
return Object.values(collection);
}

export interface AngularSandboxOptions {
/** Optional custom markdown rendering delegate callback hook */
markdownRendererFn?: (markdown: string) => Promise<string>;
Expand Down Expand Up @@ -154,8 +166,26 @@ export function provideA2uiSandbox(
provide: A2UI_RENDERER_CONFIG,
useFactory: () => {
const resolvedCatalogs = catalogsClasses.map(cls => inject(cls));
const baseCatalog = resolvedCatalogs[0];
const baseComponents = extractCatalogEntries<ComponentApi>(baseCatalog?.components);
const baseFunctions = extractCatalogEntries<FunctionImplementation>(baseCatalog?.functions);
const mcpFunctions = createMcpCatalogFunctions(
{
processMessages: msgs => {
const activeProcessor = (
a2uiBridge as unknown as {activeRenderer?: {processor?: RendererProcessor}}
).activeRenderer?.processor;
activeProcessor?.processMessages(msgs);
},
},
async () => a2uiBridge.getMcpClient(),
);
const mcpCatalog = new Catalog(BASIC_WITH_MCP_CATALOG_ID, baseComponents, [
...baseFunctions,
...mcpFunctions,
]);
return {
catalogs: resolvedCatalogs,
catalogs: [mcpCatalog, ...resolvedCatalogs],
actionHandler: (action: unknown) => {
a2uiBridge.sendAction(action);
},
Expand Down
16 changes: 16 additions & 0 deletions bridge/src/bridge-message.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ export enum PreviewBridgeMessageType {
FORCE_UNBLOCK = 'FORCE_UNBLOCK',
GET_CATALOG = 'GET_CATALOG',
GET_COMPONENT_USAGES = 'GET_COMPONENT_USAGES',
MCP_REQUEST = 'MCP_REQUEST',
MCP_RESPONSE = 'MCP_RESPONSE',
RENDER_A2UI = 'RENDER_A2UI',
RENDER_ERROR = 'RENDER_ERROR',
RENDER_SUCCESS = 'RENDER_SUCCESS',
Expand Down Expand Up @@ -201,3 +203,17 @@ export declare interface A2uiComponentInstance {
id?: string;
[key: string]: unknown;
}

/** Payload for MCP_REQUEST message type. */
export declare interface McpRequestPayload {
requestId: string;
toolName: string;
args: Record<string, unknown>;
}

/** Payload for MCP_RESPONSE message type. */
export declare interface McpResponsePayload {
requestId: string;
result?: unknown;
error?: string;
}
2 changes: 2 additions & 0 deletions bridge/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
export * from './bridge-message.js';
export * from './domain-origin-verification.js';
export * from './instrumentation-overrides.js';
export * from './mcp/index.js';
export * from './mcp/iframe-mcp-client.js';
export * from './preview-bridge.js';
export * from './render-config.js';
export * from './surface-resize-observer.js';
46 changes: 40 additions & 6 deletions bridge/src/lit/lit-bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
SurfaceModel,
Catalog,
ComponentApi,
FunctionImplementation,
A2uiClientAction,
} from '@a2ui/web_core/v0_9';
import type {MarkdownRenderer} from '@a2ui/web_core/types/types';
Expand All @@ -31,9 +32,21 @@ import {
ThemePreference,
SurfaceStateSubscription,
CatalogDetails,
createMcpCatalogFunctions,
type ComponentUsages,
} from '../index.js';

export const BASIC_WITH_MCP_CATALOG_ID =
'https://a2ui.org/specification/v0_9/catalogs/basic_with_mcp/catalog.json';

function extractCatalogEntries<T>(collection?: ReadonlyMap<string, T> | Record<string, T>): T[] {
if (!collection) return [];
if (typeof (collection as ReadonlyMap<string, T>).values === 'function') {
return Array.from((collection as ReadonlyMap<string, T>).values());
}
return Object.values(collection);
}

/**
* Options block configuring custom element generation and static payload injection
* for the Lit component rendering sandbox.
Expand Down Expand Up @@ -79,13 +92,31 @@ export class A2uiSandboxRoot extends LitElement {
/** Optional callback when theme changes shared statically */
static onThemeChange?: (theme: ThemePreference) => void = undefined;

private runtimeCatalogs: Catalog<ComponentApi>[] = [];

// Core dynamic processing engine mapping actions outbox proxies
private processor = new MessageProcessor(
(this.constructor as typeof A2uiSandboxRoot).catalogs,
(action: A2uiClientAction) => {
private processor: MessageProcessor<ComponentApi> = (() => {
const baseCatalog = (this.constructor as typeof A2uiSandboxRoot).catalogs[0];
const baseComponents = extractCatalogEntries<ComponentApi>(baseCatalog?.components);
const baseFunctions = extractCatalogEntries<FunctionImplementation>(baseCatalog?.functions);
const procRef: {current?: MessageProcessor<ComponentApi>} = {};
const mcpFunctions = createMcpCatalogFunctions(
{
processMessages: msgs => procRef.current?.processMessages(msgs),
},
async () => a2uiBridge.getMcpClient(),
);
const mcpCatalog = new Catalog(BASIC_WITH_MCP_CATALOG_ID, baseComponents, [
...baseFunctions,
...mcpFunctions,
]);
this.runtimeCatalogs = [mcpCatalog, ...(this.constructor as typeof A2uiSandboxRoot).catalogs];
const proc = new MessageProcessor(this.runtimeCatalogs, (action: A2uiClientAction) => {
a2uiBridge.sendAction(action);
},
);
});
procRef.current = proc;
return proc;
})();

private markdownProvider = new ContextProvider(this, {
context: Context.markdown,
Expand Down Expand Up @@ -132,7 +163,10 @@ export class A2uiSandboxRoot extends LitElement {
getComponentUsages: (this.constructor as typeof A2uiSandboxRoot).getComponentUsages,
onThemeChange: (this.constructor as typeof A2uiSandboxRoot).onThemeChange,
onCatalogResolved: catalogId => {
for (const catalog of (this.constructor as typeof A2uiSandboxRoot).catalogs) {
for (const catalog of [
...this.runtimeCatalogs,
...(this.constructor as typeof A2uiSandboxRoot).catalogs,
]) {
if (catalog) {
(catalog as unknown as CatalogDetails).id = catalogId;
}
Expand Down
Loading
Loading