feat(errors): standardize MCP JSON-RPC codes into -32020..-32099 range - #223
feat(errors): standardize MCP JSON-RPC codes into -32020..-32099 range#223JayDS22 wants to merge 1 commit into
Conversation
|
This is a clear improvement over the coarse 404→InvalidParams / else→InternalError mapping — typed, specific codes are the right direction, and Three things worth a look before merge: 1. This is a wire-visible change — call it out. Any MCP client currently branching on the numeric 2. Confirm the fallback for non- 3. Standard codes where they fit? Note: for |
The MCP spec reserves `-32020..-32099` for implementation-defined error codes. Previously the ServiceError -> McpError mapping in `serviceErrorToResourceError` was a coarse 2-way split (404 -> InvalidParams, else -> InternalError), losing per-subclass identity. This threads a `jsonRpcCode: number` through the `ServiceError` hierarchy so each subclass carries its own MCP code: TEMPLATE_NOT_FOUND -> -32020 AGREEMENT_NOT_FOUND -> -32021 TEMPLATE_DUPLICATE -> -32022 AGREEMENT_CONVERSION_FAILED -> -32023 AGREEMENT_TRIGGER_FAILED -> -32024 INVALID_PAYLOAD -> -32025 VALIDATION_ERROR -> -32026 UPSTREAM_API_ERROR -> -32027 (bare ServiceError default) -> -32028 MCP clients can now branch on the integer code without parsing message strings; the string `code` field (e.g. `TEMPLATE_NOT_FOUND`) stays as the machine-readable form for REST + MCP consumers. Central codes live in `MCP_ERROR_CODES` (`services/errors.ts`), with tests asserting all values sit inside the reserved range and that no two subclasses collide on the same code. Validation: - npm run build: clean - npm test: 10 suites / 153 tests, all pass Signed-off-by: Jay Guwalani <guwalanijj@gmail.com>
fb63e7b to
990704f
Compare
|
Amended 1. Wire-visibility change flagged. Confirmed: any MCP client that was branching on the numeric 2. Non- 3. On the
|
Summary
The MCP spec reserves
-32020..-32099for implementation-defined error codes. Previously theServiceError -> McpErrormapping inserviceErrorToResourceErrorwas a coarse 2-way split (404 ->InvalidParams, else ->InternalError), losing per-subclass identity.This threads a
jsonRpcCode: numberthrough theServiceErrorhierarchy so each subclass carries its own MCP code:TemplateNotFoundError-32020AgreementNotFoundError-32021TemplateDuplicateError-32022AgreementConversionError-32023AgreementTriggerError-32024InvalidPayloadError-32025ValidationError-32026UpstreamApiError-32027ServiceError(bare default)-32028MCP clients can now branch on the integer code without parsing message strings; the string
codefield (e.g.TEMPLATE_NOT_FOUND) stays as the machine-readable form for REST + MCP consumers.What this PR does
MCP_ERROR_CODEScentral constant table inservices/errors.ts, with tests asserting all values sit inside the reserved range and no two subclasses collide on the same code.jsonRpcCodethrough everyServiceErrorsubclass constructor.serviceErrorToResourceErrorandserviceErrorToCallToolResultinhandlers/mcp.tsto emit the typed code instead of the coarse 2-way split.services/errors.test.tswith per-subclass code assertions + range-invariant tests.Stack
Base of a three-PR chain that closes Proposal Core and aligns MCP with the 2026-07-28 spec finalisation:
SubscriptionInvalidUriError -32029in this range)Merge earliest first; later branches will rebase forward.
Validation
npm ciinserver/: cleannpm run build: clean (tsc -p .)npm test: 10 suites / 153 tests, all pass (was 141 pre-branch, +12 fromerrors.test.ts)Related
Sets the JSON-RPC code convention that Issue #221 ("MCP SDK upgrade") builds on for the 2.0-beta.5 migration.
Author Checklist
mainnpm testgreen locally