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

    Mastra AI SDK v5: MastraClient 'Failed to parse stream string' and Cloud ENOENT build errors — how to fix?

    Upgraded Mastra to the AI SDK v5 beta: MastraClient throws 'Failed to parse stream string. Invalid code data.' and Mastra Cloud builds fail with ENOENT for @mastra/core's libsql module. What are the fixes?

    Originally asked on GitHub: https://github.com/mastra-ai/mastra/issues/5470

    5 answers

    • Best answerAgentArmor teamTeam3d ago

      Status: the Mastra Cloud build issue was fixed by the maintainers on 2025-07-15, and MastraClient still only works in AI SDK v4 compatibility mode for now, with frontend v5 support still in progress.

      For the MastraClient error Failed to parse stream string. Invalid code data., a maintainer explained that a header is now required so the backend knows the client wants AI SDK v4 compatibility:

      ts
      const mastraClient = new MastraClient({
        baseUrl: "http://localhost:4111",
        headers: {
          "x-ai-sdk-compat": "v4"
        }
      });
      

      One commenter confirmed the earlier beta 0.0.0-ai-v5-20250626003446 worked with MastraClient even without this header, so the requirement arrived with a later change. Another commenter hit the parse error after upgrading and reported that rolling back to the previous release fixed it.

      For the Mastra Cloud deployment failure (ENOENT when loading @mastra/core/dist/storage/libsql/index.js from a pnpm path), the reporter's template project was built from the ai-v5 dependency tag. The maintainers said Cloud was changed so ai-v5 versions deploy properly, and the issue was closed as completed.

      General advice: with pre-release beta tags, pin the exact version in package.json so client and server use matching @mastra/core builds, and re-test after each beta release — the compatibility header requirement and stream parsing behavior changed between betas.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @DanielSLew tried on GitHub (Outcome unclear)

      Maintainer stated the backend now requires a header for v4 compatibility and suggested passing x-ai-sdk-compat: "v4" when creating the MastraClient. No commenter explicitly confirmed this resolved the parse error.

      Source: https://github.com/mastra-ai/mastra/issues/5470#issuecomment-3079691200 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @izziaraffaele tried on GitHub (Worked)

      After upgrading to the ai-v5 beta, calling agent.stream from the MastraClient against a standalone server produced 'Failed to parse stream string. Invalid code data.'; rolling back to the previous release made it work.

      Source: https://github.com/mastra-ai/mastra/issues/5470#issuecomment-3062760259 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @izziaraffaele tried on GitHub (Worked)

      Reported that beta build 0.0.0-ai-v5-20250626003446 works with MastraClient without the v4 compatibility header.

      Source: https://github.com/mastra-ai/mastra/issues/5470#issuecomment-3083032409 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @FlatMapIO tried on GitHub (Didn't work)

      Upgraded a template project's dependency to the ai-v5 tag and deployed to Mastra Cloud; the build failed with ENOENT when loading @mastra/core's libsql storage module from a pnpm path.

      Source: https://github.com/mastra-ai/mastra/issues/5470#issuecomment-3062273131 (opens external site)

      Did this work for you?

    Add your answer or comment