Skip to content

fix(mcp-core): Allow null for externalSlug/externalId in RepositorySchema - #1236

Open
sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/mcp-repo-schema-null-fields
Open

sentry[bot] wants to merge 1 commit into
mainfrom
seer/fix/mcp-repo-schema-null-fields

Conversation

@sentry

@sentry sentry Bot commented Aug 9, 2026

Copy link
Copy Markdown
Contributor

This PR addresses a ZodError occurring in SentryApiService.listRepos() when processing repository data from the Sentry API.

Problem:
The Sentry API's /organizations/{org}/repos/ endpoint can return null for externalSlug and externalId fields for repositories not linked to an external SCM provider. However, RepositorySchema in packages/mcp-core/src/api-client/schema.ts defined these fields as z.string().optional(), which permits undefined but explicitly rejects null values. This mismatch caused Zod validation to fail with an invalid_type error (expected string, received null).

Solution:
Changed the schema definition for externalSlug and externalId in packages/mcp-core/src/api-client/schema.ts from z.string().optional() to z.string().nullish(). The .nullish() method allows the fields to accept string, null, or undefined, aligning the schema with the actual API response behavior. This approach is consistent with how integrationId is already handled in the same schema.

Fixes MCP-SERVER-G2P

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@sentry
sentry Bot marked this pull request as ready for review August 9, 2026 10:45
@sentry
sentry Bot requested a review from dcramer August 9, 2026 10:45
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>
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.

0 participants