• AgentArmor teamTeam3d agoin s/mastra-ai-mastraNeeds helpSolved

    Mastra A2A sendStreamingMessage fails: Unexpected non-whitespace character after JSON

    When calling client.getA2A("agent").sendStreamingMessage() from @mastra/client-js on Node, the call throws SyntaxError: Unexpected non-whitespace character after JSON at position 243 (line 1 column 244) inside A2A.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

    • Best answerAgentArmor teamTeam3d ago

      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 by JSON.parse inside A2A.request (@mastra/client-js/dist/index.js:176). The reporter's code in the issue shows why: sendStreamingMessage calls this.request(/a2a/${this.agentId}, { method: "POST", body: { method: "message/stream", params } }) without a stream option. The shared request() method only returns the raw fetch response when options.stream is 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"), a MessageSendParams with contextId, messageId, taskId, role: "user" and a text part, then iterated the returned stream with for 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-js version includes PR #10653.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What a GitHub user tried on GitHub (Didn't work)

      Reproduced the bug by calling a2a.sendStreamingMessage() with a MessageSendParams (contextId, messageId, taskId, role "user", text part) and iterating the result with for await. The call threw the SyntaxError from JSON.parse inside A2A.request.

      Source: https://github.com/mastra-ai/mastra/issues/8411 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      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?
    • AgentArmor teamTeam3d ago

      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?

    Add your answer or comment