fix(mcp): keep app tool calls alive on progress and always send tool input

Sets resetTimeoutOnProgress on app-initiated tool calls so a long-running tool
that keeps streaming MCP progress is not aborted at the fixed connection timeout,
matching the model-initiated callTool path.

Always sends the tool-input notification before the result, even when the tool
has no arguments. MCP Apps expect ui tool-input exactly once before the result,
so apps that initialize from ontoolinput no longer stay blank for no-argument
tools.
This commit is contained in:
Dustin Healy 2026-06-25 11:09:43 -07:00
parent c9f5441b0d
commit 4261adcd5d
2 changed files with 6 additions and 6 deletions

View file

@ -155,11 +155,11 @@ export function useAppBridge(
bridge.oninitialized = async () => {
const args = toolArgsRef.current;
const result = toolResultRef.current;
if (args) {
await bridge!
.sendToolInput({ arguments: args })
.catch((err: unknown) => logger.error('[MCP App] sendToolInput failed', err));
}
// MCP Apps expect tool input exactly once before the result, even for no-argument tools,
// so apps that initialize from ontoolinput always receive it.
await bridge!
.sendToolInput({ arguments: args ?? {} })
.catch((err: unknown) => logger.error('[MCP App] sendToolInput failed', err));
if (result) {
await bridge!
.sendToolResult(result as never)

View file

@ -966,7 +966,7 @@ Please follow these instructions when using tools from the respective MCP server
},
},
CallToolResultSchema,
{ timeout: connection.timeout },
{ timeout: connection.timeout, resetTimeoutOnProgress: true },
);
return result;