diff --git a/examples/basic-host/src/implementation.ts b/examples/basic-host/src/implementation.ts index 9ce9fa63..5e67164f 100644 --- a/examples/basic-host/src/implementation.ts +++ b/examples/basic-host/src/implementation.ts @@ -60,11 +60,21 @@ export function hasAppHtml(toolCallInfo: ToolCallInfo): toolCallInfo is Required } -export function callTool( +/** + * Resolves URI template parameters like {param} with values from structuredContent + */ +function resolveUriParameters(uriTemplate: string, structuredContent: Record): string { + return uriTemplate.replace(/\{(\w+)\}/g, (match, paramName) => { + const value = structuredContent[paramName]; + return value !== undefined ? String(value) : match; + }); +} + +export async function callTool( serverInfo: ServerInfo, name: string, input: Record, -): ToolCallInfo { +): Promise { log.info("Calling tool", name, "with input", input); const resultPromise = serverInfo.client.callTool({ name, arguments: input }) as Promise; @@ -74,10 +84,17 @@ export function callTool( } const toolCallInfo: ToolCallInfo = { serverInfo, tool, input, resultPromise }; + let result = await resultPromise; const uiResourceUri = getToolUiResourceUri(tool); if (uiResourceUri) { - toolCallInfo.appResourcePromise = getUiResource(serverInfo, uiResourceUri); + // Replace URL parameters with values from structuredContent + let resolvedUri = uiResourceUri; + if (result.structuredContent && typeof result.structuredContent === 'object') { + resolvedUri = resolveUriParameters(uiResourceUri, result.structuredContent); + log.info(`Resolved URI: ${uiResourceUri} -> ${resolvedUri}`); + } + toolCallInfo.appResourcePromise = getUiResource(serverInfo, resolvedUri); } return toolCallInfo; diff --git a/examples/basic-host/src/index.tsx b/examples/basic-host/src/index.tsx index baaa7bb6..55090c33 100644 --- a/examples/basic-host/src/index.tsx +++ b/examples/basic-host/src/index.tsx @@ -160,12 +160,12 @@ function CallToolPanel({ serversPromise, addToolCall, initialServer, initialTool }; // Submit with optional override for server/tool (used by auto-call) - const handleSubmit = (overrideServer?: ServerInfo, overrideTool?: string) => { + const handleSubmit = async (overrideServer?: ServerInfo, overrideTool?: string) => { const server = overrideServer ?? selectedServer; const tool = overrideTool ?? selectedTool; if (!server) return; - const toolCallInfo = callTool(server, tool, JSON.parse(inputJson)); + const toolCallInfo = await callTool(server, tool, JSON.parse(inputJson)); addToolCall(toolCallInfo); // Update URL for easy refresh/sharing (without triggering navigation) @@ -178,7 +178,7 @@ function CallToolPanel({ serversPromise, addToolCall, initialServer, initialTool return (
-
{ e.preventDefault(); handleSubmit(); }}> + { e.preventDefault(); await handleSubmit(); }}>