This commit is contained in:
Olivier Chafik 2025-11-24 17:27:06 +00:00
commit c800b34635
No known key found for this signature in database
3 changed files with 22 additions and 17 deletions

View file

@ -95,9 +95,7 @@ export interface AppRendererProps {
* @param props - Component props
* @returns React element containing the sandboxed tool UI iframe
*/
export const AppRenderer = (
props: AppRendererProps,
) => {
export const AppRenderer = (props: AppRendererProps) => {
const {
client,
sandboxProxyUrl,

View file

@ -5,7 +5,7 @@ import { Client } from "@modelcontextprotocol/sdk/client/index.js";
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
import { Tool } from "@modelcontextprotocol/sdk/types.js";
import { AppRenderer,AppRendererProps } from "../src/AppRenderer";
import { AppRenderer, AppRendererProps } from "../src/AppRenderer";
import { AppBridge } from "../../../dist/src/app-bridge";
const SANDBOX_PROXY_URL = URL.parse("/sandbox.html", location.href)!;
@ -94,16 +94,24 @@ function ExampleApp() {
setActiveTools((prev) => prev.filter((t) => t.id !== id));
};
const handleMessage: AppRendererProps["onmessage"] = async (params, _extra) => {
const handleMessage: AppRendererProps["onmessage"] = async (
params,
_extra,
) => {
console.log("[React Host] Message:", params);
return {};
};
const handleLoggingMessage: AppRendererProps["onloggingmessage"] = (params) => {
const handleLoggingMessage: AppRendererProps["onloggingmessage"] = (
params,
) => {
console.log("[React Host] Logging message:", params);
};
const handleOpenLink: AppRendererProps["onopenlink"] = async (params, _extra) => {
const handleOpenLink: AppRendererProps["onopenlink"] = async (
params,
_extra,
) => {
console.log("[React Host] Open link request:", params);
window.open(params.url, "_blank", "noopener,noreferrer");
return { isError: false };

View file

@ -87,15 +87,15 @@ window.addEventListener("load", async () => {
appBridge.sendToolInput({ arguments: toolInput });
};
appBridge.onopenlink = async ({url}) => {
appBridge.onopenlink = async ({ url }) => {
console.log("[Example] Open link requested:", url);
window.open(url, "_blank", "noopener,noreferrer");
return {isError: false};
return { isError: false };
};
appBridge.onmessage = async (params) => {
console.log("[Example] Message requested:", params);
return {isError: false};
return { isError: false };
};
// Handle size changes by resizing the iframe
@ -108,7 +108,7 @@ window.addEventListener("load", async () => {
}
};
appBridge.onloggingmessage = async params => {
appBridge.onloggingmessage = async (params) => {
console.log("[Tool UI Log]", params);
};