diff --git a/packages/mcp-core/src/api-client/schema.test.ts b/packages/mcp-core/src/api-client/schema.test.ts index b95b7d6223..b9c67822da 100644 --- a/packages/mcp-core/src/api-client/schema.test.ts +++ b/packages/mcp-core/src/api-client/schema.test.ts @@ -12,6 +12,7 @@ import { AutofixRunSchema, AutofixRunStateSchema, ClientKeySchema, + EventAttachmentListSchema, EventSchema, FlamegraphSchema, IssueSchema, @@ -1159,3 +1160,41 @@ describe("event packages", () => { expect(event.packages).toEqual(packages); }); }); + +describe("EventAttachmentListSchema", () => { + it("accepts attachments stored without a content type", () => { + const [attachment] = EventAttachmentListSchema.parse([ + { + id: "123", + event_id: "c2bcb3b9321c4cccb39079c8202dd082", + type: "event.attachment", + name: "log.txt", + mimetype: null, + dateCreated: "2026-11-19T10:20:13.000000Z", + size: 42, + headers: { "Content-Type": null }, + sha1: null, + }, + ]); + expect(attachment?.mimetype).toBeNull(); + expect(attachment?.headers).toEqual({ "Content-Type": null }); + }); + + it("accepts a null Content-Type header when mimetype is set", () => { + const [attachment] = EventAttachmentListSchema.parse([ + { + id: "124", + event_id: "c2bcb3b9321c4cccb39079c8202dd082", + type: "event.attachment", + name: "screenshot.png", + mimetype: "image/png", + dateCreated: "2026-11-19T10:20:13.000000Z", + size: 42, + headers: { "Content-Type": null }, + sha1: null, + }, + ]); + expect(attachment?.mimetype).toBe("image/png"); + expect(attachment?.headers).toEqual({ "Content-Type": null }); + }); +}); diff --git a/packages/mcp-core/src/api-client/schema.ts b/packages/mcp-core/src/api-client/schema.ts index 3b11b002a1..b1de692084 100644 --- a/packages/mcp-core/src/api-client/schema.ts +++ b/packages/mcp-core/src/api-client/schema.ts @@ -1578,11 +1578,14 @@ export const EventAttachmentSchema = z.object({ name: z.string(), type: z.string(), size: z.number(), - mimetype: z.string(), + // Sentry declares this as `str | None` (the attachment's `content_type`). + mimetype: z.string().nullable(), dateCreated: z.string().datetime(), // Objectstore-backed attachments do not store a usable SHA1 (checksum is // unavailable), so we neither require nor surface it from this endpoint. - headers: z.record(z.string(), z.string()).optional(), + // Legacy `{ "Content-Type": ... }` field, declared `dict[str, str | None]`. + // Sentry has returned a null Content-Type here even when `mimetype` was set. + headers: z.record(z.string(), z.string().nullable()).optional(), }); export const EventAttachmentListSchema = z.array(EventAttachmentSchema); diff --git a/packages/mcp-core/src/tools/catalog/get-event-attachment.ts b/packages/mcp-core/src/tools/catalog/get-event-attachment.ts index 44591e0df7..a56f2f55e5 100644 --- a/packages/mcp-core/src/tools/catalog/get-event-attachment.ts +++ b/packages/mcp-core/src/tools/catalog/get-event-attachment.ts @@ -227,7 +227,7 @@ export default defineTool({ output += `**Name:** ${attachment.name}\n`; output += `**Type:** ${attachment.type}\n`; output += `**Size:** ${attachment.size} bytes\n`; - output += `**MIME Type:** ${attachment.mimetype}\n`; + output += `**MIME Type:** ${attachment.mimetype ?? "unknown"}\n`; output += `**Created:** ${attachment.dateCreated}\n\n`; output += "To download this attachment with the attachmentId provided:\n"; output += `${formatToolCallInstruction({