Repository navigation
fix(mcp): Accept null dashboard environment filters from Sentry API - #2171
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
There was a problem hiding this comment.
Looks good to me. I checked the premise against the producer in getsentry/sentry. The dashboard validator declares environment as a ListField(..., allow_null=True), and update_dashboard_filters stores whatever was sent in Dashboard.filters. Then DashboardFiltersMixin.get_filters reads it back with dashboard_filters.get("environment", []), which returns None when the key is saved as null. Both the list and the details serializers return that value, so environment: null is a real API shape for both DashboardListItemSchema and DashboardSchema, not malformed data. The linked issue shows exactly this failure in listDashboards (10.environment: expected array, received null), so one dashboard breaks find_dashboards for the whole org.
The z.preprocess((value) => value ?? [], z.array(z.string())) shape matches the existing urls field in this file. Only nullish values are coerced, and non-string entries are still rejected. I merged the branch with current main (which now has no-unnecessary-condition enabled for mcp-core) and ran the checks there: mcp-core tsc and oxlint on the changed files are clean, and schema.test.ts, find-dashboards.test.ts, and get-dashboard-details.test.ts pass. The new find_dashboards regression test fails on main's schema.
|
This PR has had no activity for 3 days. It closes in 2 days unless someone pushes, comments, or adds the |
Resolve the schema.test.ts conflict with #2425 by keeping both the dashboard environment tests and the EventAttachmentListSchema tests.
There was a problem hiding this comment.
This branch conflicted with main after #2425 added EventAttachmentListSchema tests to the same spot in schema.test.ts. I merged main in 5871970 and kept both sets of tests. The fix itself didn't change.
It's still needed: DashboardListItemSchema and DashboardSchema on main still use z.array(z.string()).default([]), which rejects null. With main's schema.ts swapped in, the 3 null-environment tests fail. With this branch they pass, along with the rest of schema.test.ts, find-dashboards.test.ts and get-dashboard-details.test.ts. The mcp-core typecheck is clean.
|
The red |
BYK
left a comment
There was a problem hiding this comment.
Shouldn't we fix this on the server side over at getsentry/sentry?
|
@BYK I don't think a server-side change would replace this. On current getsentry/sentry Sentry could normalize that on read, or stop allowing null on write. Even then, dashboards that already have On checks: the red |
…ll-environment Co-Authored-By: BYK <126780+BYK@users.noreply.github.com>
…er is null (#133056) The dashboard write serializer declares `environment` as `ListField(..., allow_null=True)`, and `update_dashboard_filters` stores the value as-is, so `Dashboard.filters` can hold `{"environment": null}`. On read, `DashboardFiltersMixin.get_filters` used `dashboard_filters.get("environment", [])`, which only falls back when the key is missing, so both the dashboard list and details endpoints returned `"environment": null` even though the response types declare `list[str]`. That null broke clients that trust the declared shape: the frontend crashed mounting the dashboard view (fixed client-side in #121066), and the Sentry MCP `find_dashboards` / `get_dashboard_details` tools failed schema validation for whole orgs (fixed client-side in getsentry/toolkit#2171). This normalizes a saved null to `[]` in `get_filters`, which both the list and details serializers read from. The client-side guards stay, since dashboards already saved with null on older self-hosted versions will keep returning it. Write-side validation (rejecting null, or coercing it on save) is left out: the frontend may still send null, and changing that contract needs a check of current callers first. <!-- junior-request-attribution:start --> via @BYK. <!-- junior-request-attribution:end --> <!-- junior-session-footer:start --> <!-- junior-conversation-id:local%3Aweb%3A47e2a10ae313cb586712b7a4 --> -- [View Session](https://junior-prod.sentry.dev/conversations/local%3Aweb%3A47e2a10ae313cb586712b7a4) [[Sentry]](https://sentry.sentry.io/explore/conversations/local%3Aweb%3A47e2a10ae313cb586712b7a4/?project=4510944073809921) <!-- junior-session-footer:end --> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: BYK <126780+BYK@users.noreply.github.com>
The Sentry API can return
"environment": nullon saved dashboard objects when the dashboard's environment filter was saved with a null value. Previously,DashboardListItemSchemaandDashboardSchemadefinedenvironment: z.array(z.string()).default([]). Because Zod's.default()only substitutes values forundefined, an explicitnullfrom the Sentry API resulted in anApiResponseValidationError("expected array, received null"), causingfind_dashboardsandget_dashboard_detailsto fail for entire organizations containing such dashboards.Changes:
z.preprocess((value) => value ?? [], z.array(z.string()))for theenvironmentfield inDashboardListItemSchemaandDashboardSchemaso bothnullandundefinedare coerced to[].packages/mcp-core/src/api-client/schema.test.tsverifying thatnull,undefined, and string array environments parse as string arrays.packages/mcp-core/src/tools/catalog/find-dashboards.test.tsverifying that a dashboard withenvironment: nullis processed without error and returnsenvironments: [].Fixes MCP-SERVER-GNF
@sentry <feedback>: Autofix iterates on these changes@sentry stop iterating: Autofix stops iterating on this runThis PR was automatically generated by Sentry. You can adjust this setting at any time.