Skip to content

[BUG] Scorer save fails with "toJSON" error when using mastra dev with getPlatformProxy #12301

@owk-owk130

Description

@owk-owk130

Describe the Bug

Thank you for the great framework!

When running Mastra Studio via mastra dev with getPlatformProxy from wrangler, scorer execution completes successfully but saving results to mastra_scorers table fails with an RPC serialization error.

Scorer calculation succeeds but save operation fails with:

{
  "message": "The RPC receiver does not implement the method \"toJSON\".",
  "domain": "SCORER",
  "category": "USER",
  "code": "MASTRA_SCORER_FAILED_TO_RUN_HOOK",
  "details": {
    "scorerId": "knowledge-accuracy-scorer",
    "entityId": "nep-chan",
    "entityType": "AGENT"
  },
  "cause": {
    "message": "The RPC receiver does not implement the method \"toJSON\".",
    "domain": "STORAGE",
    "category": "THIRD_PARTY",
    "code": "MASTRA_STORAGE_LIBSQL_SAVE_SCORE_FAILED",
    "details": {},
    "cause": {
      "message": "The RPC receiver does not implement the method \"toJSON\".",
      "name": "TypeError"
    }
  }
}

Code Example

// mastra/index.ts
import { Mastra } from "@mastra/core/mastra";
import { LibSQLStore } from "@mastra/libsql";
import { getPlatformProxy } from "wrangler";

const { env: cloudflareEnv } = await getPlatformProxy<CloudflareBindings>({
remoteBindings: true,
});

export const mastra = new Mastra({
agents: { myAgent },
scorers: { myScorer },
storage: new LibSQLStore({
  id: "mastra-storage",
  url: "file:mastra.db",
}),
server: {
  middleware: [
    async (c, next) => {
      c.get("requestContext").set("env", cloudflareEnv);
      await next();
    },
  ],
},
});

// scorers/my-scorer.ts
import { createScorer } from "@mastra/core/evals";
import { z } from "zod";

export const myScorer = createScorer({
id: "my-scorer",
name: "My Scorer",
description: "Example scorer",
type: "agent",
judge: {
  model: "google/gemini-2.5-flash",
  instructions: "Evaluate the response.",
},
})
.preprocess(({ run }) => ({ answer: run.output }))
.analyze({
  description: "Analyze response",
  outputSchema: z.object({ score: z.number() }),
  createPrompt: ({ results }) => `Evaluate: ${results.preprocessStepResult.answer}`,
})
.generateScore(({ results }) => results?.analyzeStepResult?.score ?? 0)
.generateReason(({ score }) => `Score: ${score}`);

Notes

  • Tested with both LibSQLStore and D1Store - same error occurs
  • Normal storage operations (threads, messages, etc.) work correctly
  • Only scorer save operation fails

Steps To Reproduce

  1. Create a Mastra project with Cloudflare Workers integration using getPlatformProxy
  2. Define custom scorers using createScorer
  3. Attach scorers to an Agent
  4. Run mastra dev and execute the agent
  5. Observe scorer save failure in logs

Link to Minimal Reproducible Example

Reproduction requires Cloudflare Workers environment with getPlatformProxy. I can create a minimal reproduction repository if needed.

Expected Behavior

Scorer results should be saved to mastra_scorers table and visible in Mastra Studio.

Environment Information

- System:
  - OS: macOS 15.7.3
  - CPU: arm64 Apple M2 Pro
- Binaries:
  - Node: 24.1.0
  - pnpm: 10.28.1
- npmPackages:
  - @mastra/core: 1.0.4
  - @mastra/libsql: 1.0.0
  - wrangler: 4.53.0
- LLM Provider: Google Gemini

Verification

  • I have searched the existing issues to make sure this is not a duplicate
  • I have included sufficient information for the team to reproduce and understand the issue

Metadata

Metadata

Labels

AgentsIssues regarding Mastra's Agent primitiveStorageIssues with Mastra Storage adapters for databases and vector storagebugSomething isn't workingeffort:mediumimpact:hightrio-tracery

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions