The result of clientTool execution is not included in the stream response

The tool is executed, but the results cannot be retrieved.

You can try it with the following sample code
import { MastraClient } from '@mastra/client-js';
import { weatherTool } from './mastra/tools/weather';

const client = new MastraClient({ baseUrl: 'http://localhost:4111' });

const weatherAgent = client.getAgent('weatherAgent');

const res = await weatherAgent.stream({
  messages: [
    {
      role: 'user',
      content: 'How is the weather in Tokyo?',
    },
  ],
  clientTools: {
    weatherTool,
  },
});

const reader = res.body?.getReader();

if (!reader) {
  throw new Error('Reader is not available');
}

const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const text = decoder.decode(value, { stream: true });
  console.log(text);
} 
Was this page helpful?