feat: adopt @sentry/api SDK for 38 of 40 API call sites
Adds @sentry/api@^0.175.0 and migrates 38 of 40 API methods in SentryApiService from raw fetch (via requestJSON) to the typed SDK functions. The remaining 2 methods use internal/undocumented endpoints with no SDK equivalent.
What changed
Two helper methods added to SentryApiService:
getSdkConfig(opts?)— buildsbaseUrl+ auth headers (includingX-Sentry-MCP-Client-*identity headers) per call, supporting multi-region host overridesunwrapSdkResult(result, context)— converts SDK discriminated-union results to the existing MCP error hierarchy (ApiError,ApiNotFoundError,ApiServerError, etc.), using the API detail text as the user-facing message when available
17 direct replacements (no casts)
listOrganizations, getOrganization, listTeams, createTeam, listProjects, getProject, createProject, updateProject, addTeamToProject, createClientKey, listClientKeys, listReleases, listIssues, getEventForIssue, getLatestEventForIssue, listEventsForIssue, startAutofix, getAutofixState
11 replacements with type casts
searchReplays, getIssue, getIssueTagValues, getIssueExternalLinks, getReplayDetails, listReplayIdsForIssue, getReplayRecordingSegments, updateIssue, searchErrors, searchSpans, searchEvents
10 new replacements (from SDK v0.171.0+)
listTags→listAnOrganization_sTags(with cast foruseCacheparam)listTraceItemAttributes→listTraceItemAttributes(replacesfetchTraceItemAttributesByTypeprivate helper)listEventAttachments→listAnEvent_sAttachmentsgetEventAttachment— metadata vialistEventAttachments; binary download stays on rawrequest()getTraceMeta→retrieveTraceMetadatagetTrace→retrieveATrace(with cast forlimit/projectparams)getFlamegraph→retrieveAFlamegraphForAnOrganizationgetTransactionProfile→retrieveAProfilegetProfileChunk→retrieveProfileChunksForAnOrganizationlistReleases(project-level) →listAProject_sReleaseslistIssues(project-level) →listAProject_sIssues(with cast for extra query params)
2 methods still on requestJSON
getAuthenticatedUser, regions endpoint — no SDK equivalent exists for these.
Schema improvements
TagSchema/TagListSchemarebased onzTagKeyDetailsDictfrom@sentry/api/zodEventsResponseSchema,ExternalIssueListSchema,AutofixRunSchemause SDK-generated Zod schemas
Preserved behavior
- Zod validation: All responses still pass through existing Zod schemas after SDK unwrapping
- Error handling:
unwrapSdkResultmaps HTTP errors to the existingApiError/ApiNotFoundError/ApiServerErrortypes, using API detail text as the message - Multi-region:
getSdkConfigbuilds per-call base URLs fromopts.hostoverrides - Client identity:
X-Sentry-MCP-Client-Id/Name/Familyheaders forwarded through SDK calls
Testing
- TypeScript: clean (no new errors in
client.ts) - Full test suite: 1033 tests passed, 4 skipped
- Lint: clean
Dependencies
@sentry/api@^0.175.0— latest version, includes SDK wrappers for organization tags, trace, profiling, project-level issues/releases, and event attachment endpoints
fix-ci: starting attempt 1/3
fix-ci: result — fixed 7 test failures across 5 test files.
Root causes:
- Agent provider conflict:
ANTHROPIC_API_KEYenv var leaked into tests alongsideOPENAI_API_KEY, causinghasAgentProvider()to return false and routing tests through the direct (non-agent) code path. Fixed by clearing the env var in beforeEach/afterEach. - MSW handler assertions: SDK sends
limitnotper_pagefor issues, and doesn't exposesort/per_pageas query params on issue events. Updated handler assertions. - Path traversal tests: SDK URL-encodes path params, neutralizing traversal attacks. Updated tests to verify the encoding works correctly instead of expecting errors.
- addTeamToProject mock: SDK sends POST with no body; removed
request.json()call that threwSyntaxError.
All 69 tests in the 5 affected files pass. Client unit tests (72/72) still pass.
One f/u - i was hoping we'd be able to remove a bunch of typed schemas. Im not sure what we need to do to solve it, but it'd be great if @sentry/api had native zod structs that we could use that were either autogenerated or at minimum, we maintain them in one place vs here and cli etc
Bumped @sentry/api to ^0.141.0 — this picks up the new @sentry/api/zod subpath export with auto-generated Zod v3 schemas from the OpenAPI spec (sentry-api-schema#70). These schemas can eventually replace the hand-written ones in packages/mcp-core/src/api-client/schema.ts.