Skip to content

fix(mcp-common): make outcome optional in observability event schema - #419

Open
arimu1 wants to merge 1 commit into
cloudflare:mainfrom
arimu1:fix/observability-optional-outcome
Open

fix(mcp-common): make outcome optional in observability event schema#419
arimu1 wants to merge 1 commit into
cloudflare:mainfrom
arimu1:fix/observability-optional-outcome

Conversation

@arimu1

@arimu1 arimu1 commented Jul 20, 2026

Copy link
Copy Markdown

Fixes #418

zCloudflareMiniEvent in packages/mcp-common/src/types/workers-logs.types.ts declares outcome: z.string(), but outcome (ok/exception/canceled) only describes a whole invocation. console.log lines emitted inside an invocation ($metadata.type = "cf-worker") legitimately don't have it — only the invocation-summary line ($metadata.type = "cf-worker-event") does. query_worker_observability validates the whole event array with a single .parse() in packages/mcp-common/src/cloudflare-api.ts, so one non-invocation event in the response threw away the entire batch and the tool returned no logs at all.

The issue reporter measured this against real production data: 46% of all events and 86% of cron events were missing outcome and getting the whole response discarded as a result.

The fix makes outcome optional, matching how the other non-invocation-only fields on this schema are already handled.

I scoped this to the one-line schema change rather than also switching cloudflare-api.ts's .parse() to per-event .safeParse() (also suggested in the issue) — that helper is shared by several unrelated endpoints (workers-builds, IAM integrations, KV keys/values), and changing its error-swallowing behavior generically felt like a separate, riskier change from the actual bug here.

Added a regression test in packages/mcp-common/src/types/workers-logs.types.spec.ts that reproduces the issue's minimal repro shape (a cron event with no outcome) and asserts an event array containing one such event still parses. Confirmed it fails with the same invalid_union / path: ["outcome"] Zod error described in the issue when run against the old schema, and passes with the fix.

zCloudflareMiniEvent required outcome on every event, but outcome only
describes an invocation and is absent on console.log lines emitted
inside one. query_worker_observability validates the whole event array
in a single .parse(), so any response containing one of these
non-invocation events was rejected outright and no logs were returned.

Fixes cloudflare#418
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Workers Observability: required outcome field discards entire response (46% of real events, 86% of cron)

1 participant