Mastra A2A sendStreamingMessage fails: Unexpected non-whitespace character after JSON
When calling
client.getA2A("agent").sendStreamingMessage()from@mastra/client-json Node, the call throwsSyntaxError: Unexpected non-whitespace character after JSON at position 243 (line 1 column 244)insideA2A.request, and the stream is never received. Why does the client try to parse a streaming response as JSON, and is there a fix?Originally asked on GitHub: https://github.com/mastra-ai/mastra/issues/8411
4 answers
Status: root cause explained, fix proposed but unverified. The thread shows why
A2A.sendStreamingMessage()throws, and a maintainer linked PR #10653 saying it "should fix those issues" — nobody in the thread confirmed the fix worked.The error is
SyntaxError: Unexpected non-whitespace character after JSON at position 243 (line 1 column 244), thrown byJSON.parseinsideA2A.request(@mastra/client-js/dist/index.js:176). The reporter's code in the issue shows why:sendStreamingMessagecallsthis.request(/a2a/${this.agentId}, { method: "POST", body: { method: "message/stream", params } })without astreamoption. The sharedrequest()method only returns the rawfetchresponse whenoptions.streamis truthy; otherwise it reads the full body and parses it as JSON, which fails on a streaming response. The reporter flagged that exact spot in the code with "here I think this should be true."The reproduction used
new MastraClient({ baseUrl: "http://localhost:4111/" }),client.getA2A("weatherAgent"), aMessageSendParamswithcontextId,messageId,taskId,role: "user"and a text part, then iterated the returned stream withfor await (const event of stream).No package version was given in the thread. The maintainer's reply only links the PR; it does not say which release contains it, so check whether your
@mastra/client-jsversion includes PR #10653.Did this work for you?What a GitHub user tried on GitHub (Didn't work)
Reproduced the bug by calling
a2a.sendStreamingMessage()with aMessageSendParams(contextId, messageId, taskId, role "user", text part) and iterating the result withfor await. The call threw the SyntaxError fromJSON.parseinsideA2A.request.Source: https://github.com/mastra-ai/mastra/issues/8411 (opens external site)
Did this work for you?What @abhiaiyer91 tried on GitHub (Outcome unclear)
A maintainer linked PR #10653, saying it should fix the A2A issues. No release version or verification was given.
Source: https://github.com/mastra-ai/mastra/issues/8411#issuecomment-3590574125 (opens external site)
Did this work for you?What @AndyStan112 tried on GitHub (Outcome unclear)
A commenter noted the issue classification pipeline failed and pinged a contributor to get attention.
Source: https://github.com/mastra-ai/mastra/issues/8411#issuecomment-3396104717 (opens external site)
Did this work for you?
Related questions
- Mastra dev fails on uncompiled workspace TypeScript dependencies
- Mastra AI SDK v5: MastraClient 'Failed to parse stream string' and Cloud ENOENT build errors — how to fix?
- How to register Mastra agents dynamically at runtime from a database?
- Does Mastra support Zod v4 yet?
- Mastra createStep rejects Typia StandardSchemaV1 with missing jsonSchema — supported format?