Skip to content

[JS] MCP inputs are never exposed in streamResponse toolRequest #3938

@nicola

Description

@nicola

Describe the bug
I am trying to log all the tool calls for my agent

const { stream: streamResponse, response: finalResponsePromise } = await ai.generateStream ...
for await (const chunk of streamResponse) {
  const toolRequests = chunk.content
        .map((part: any) => part.toolRequest)
        .filter((tr: any) => {
          // Filter out empty tool requests
          if (!tr || typeof tr !== 'object' || Object.keys(tr).length === 0) return false;
          // Only include complete tool requests with a valid name
          if (!tr.name || typeof tr.name !== 'string' || tr.name.trim().length === 0) return false;
          return true;
        })
        .map((tr: any) => {
          // NOTE: Genkit's streaming API has a limitation where tool request input
          // parameters are not included in the streaming chunks - they're always {}.
          // This appears to be a bug/limitation in Genkit/MCP streaming.
          // The input is only available in the final response, not in streaming chunks.
          const toolCall = {
            name: tr.name,
            input: tr.input || {}, // Will always be {} in streaming chunks
            ref: tr.ref,
          };
          
          // Store in map for potential matching with responses
          if (tr.ref) {
            toolRequestMap.set(tr.ref, toolCall);
          }
          
          return toolCall;
        });

toolCall.input always returns {}

Expected behavior
I am expecting toolCall.input to return the inputs

Runtime (please complete the following information):

  • OS: MacOs

** Node version
v23.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingjs

    Type

    No type

    Projects

    Status

    No status

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions