fix(mcp-core): Allow null for externalSlug/externalId in RepositorySchema - #1236
Open
sentry[bot] wants to merge 1 commit into
Open
sentry[bot] wants to merge 1 commit into
sentry[bot] wants to merge 1 commit into
Conversation
dcramer
added a commit
that referenced
this pull request
Aug 13, 2026
…1238) ## Summary Accept nullable date fields in `EventSchema` responses that are valid according to the Sentry API contract. ## Problem On a self-hosted Sentry instance, the event API returned this payload: ```json {"id":"2d9a3f30ee5a4a95b712e78b87631f9a","eventID":"2d9a3f30ee5a4a95b712e78b87631f9a","type":"default","dateReceived":null,"occurrence":null} ``` `EventSchema.parse` then raised an `invalid_union` Zod error. In particular, the `dateReceived` branch expected a string but received `null`. This prevents `get_sentry_resource` from returning issue and breadcrumbs resources for affected events. ## API contract evidence This is a valid server response, not a server bug. The Sentry event serializer declares `dateReceived` as `datetime | None`; when `received` is absent or invalid, the serializer can return `null`: - [`getsentry/sentry` event serializer, lines 155-176](https://github.com/getsentry/sentry/blob/master/src/sentry/api/serializers/models/event.py#L155-L176) - [`getsentry/sentry` event serializer, lines 328-368](https://github.com/getsentry/sentry/blob/master/src/sentry/api/serializers/models/event.py#L328-L368) ## Related precedent - #910 made nullable `firstSeen` and `lastSeen` API dates accept `null` with `z.string().datetime().nullable()`. - #520 fixed `occurrence: null` for transaction events after an `EventSchema` Zod error. - #894 aligned event user and geo fields that can be `null`. - #1236 proposes `nullish()` for API fields where `optional()` rejects explicit `null`. ## Change - Change `dateReceived` to `z.string().datetime().nullish()`. This follows the nullable-date intent of #910 while also retaining support for omitted fields. - Change generic `occurrence` to `OccurrenceSchema.nullish()`, consistent with the `nullish()` approach proposed in #1236 and the transaction-event handling in #520. - Add a focused `EventSchema` regression test for `dateReceived: null` and generic `occurrence: null`. ## Testing and regression coverage The focused Vitest regression test was added but could not be run locally: Corepack was unable to download the repository-pinned `pnpm@11.8.0` after 120-second and 300-second attempts, so dependencies could not be installed. `git diff --check` passes. CI should run the new test with: ```sh pnpm --filter @sentry/mcp-core exec vitest run src/api-client/schema.test.ts ``` --------- Co-authored-by: TossPig <claw@tossp.com> Co-authored-by: sentry-junior[bot] <264270552+sentry-junior[bot]@users.noreply.github.com> Co-authored-by: OpenAI Codex <noreply@openai.com> Co-authored-by: David Cramer <david@sentry.io>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR addresses a
ZodErroroccurring inSentryApiService.listRepos()when processing repository data from the Sentry API.Problem:
The Sentry API's
/organizations/{org}/repos/endpoint can returnnullforexternalSlugandexternalIdfields for repositories not linked to an external SCM provider. However,RepositorySchemainpackages/mcp-core/src/api-client/schema.tsdefined these fields asz.string().optional(), which permitsundefinedbut explicitly rejectsnullvalues. This mismatch caused Zod validation to fail with aninvalid_typeerror (expected string, received null).Solution:
Changed the schema definition for
externalSlugandexternalIdinpackages/mcp-core/src/api-client/schema.tsfromz.string().optional()toz.string().nullish(). The.nullish()method allows the fields to acceptstring,null, orundefined, aligning the schema with the actual API response behavior. This approach is consistent with howintegrationIdis already handled in the same schema.Fixes MCP-SERVER-G2P
Comment
@sentry <feedback>on this PR to have Autofix iterate on the changes.