http/jsonrpc.ts

JSON-RPC 2.0 envelope schemas for RPC dispatch and SAES transport.

Params are object-only following MCP (no positional arrays); per-action spec.input narrows further. Result is the full JSON-RPC valid value space per spec ยง5 ("determined by the method invoked"): object, array, string, number, boolean, or null โ€” the per-action spec.output is the actual contract. The envelope-level loose-object-only constraint inherited from MCP would reject any action with output: z.null() / z.string() / etc. on the wire, so we relax it here while keeping MCP-superset shape on params + _meta.

MCP _meta types (JsonrpcMcpMeta, JsonrpcRequestParamsMeta) are exported as building blocks for per-action schemas but are NOT validated at the envelope level โ€” _meta content validation belongs in per-action schemas where it produces the correct error code (invalid_params, not invalid_request).

@source https://github.com/modelcontextprotocol/typescript-sdk @see https://www.jsonrpc.org/specification

Declarations
#

27 declarations

view source

JSONRPC_INTERNAL_ERROR
#

JSONRPC_INVALID_PARAMS
#

JSONRPC_INVALID_REQUEST
#

JSONRPC_METHOD_NOT_FOUND
#

JSONRPC_PARSE_ERROR
#

JSONRPC_SERVER_ERROR_END
#

JSONRPC_SERVER_ERROR_START
#

JSONRPC_VERSION
#

JsonrpcErrorCode
#

http/jsonrpc.ts view source

ZodUnion<readonly [ZodLiteral<-32700>, ZodLiteral<-32600>, ZodLiteral<-32601>, ZodLiteral<-32602>, ZodLiteral<-32603>, $ZodBranded<...>]>

A valid JSON-RPC error code โ€” one of the 5 standard codes or a server-defined code in the -32000 to -32099 range.

JsonrpcErrorObject
#

http/jsonrpc.ts view source

ZodObject<{ code: ZodUnion<readonly [ZodLiteral<-32700>, ZodLiteral<-32600>, ZodLiteral<-32601>, ZodLiteral<-32602>, ZodLiteral<-32603>, $ZodBranded<...>]>; message: ZodString; data: ZodOptional<...>; }, $loose>

Error object within a JSON-RPC error response.

JsonrpcErrorResponse
#

http/jsonrpc.ts view source

ZodObject<{ jsonrpc: ZodLiteral<"2.0">; id: ZodNullable<ZodUnion<readonly [ZodString, ZodNumber]>>; error: ZodObject<{ code: ZodUnion<readonly [ZodLiteral<-32700>, ... 4 more ..., $ZodBranded<...>]>; message: ZodString; data: ZodOptional<...>; }, $loose>; }, $loose>

A response that indicates an error occurred.

JsonrpcMcpMeta
#

JsonrpcMessage
#

http/jsonrpc.ts view source

ZodUnion<readonly [ZodObject<{ jsonrpc: ZodLiteral<"2.0">; id: ZodUnion<readonly [ZodString, ZodNumber]>; method: ZodString; params: ZodOptional<ZodObject<{}, $loose>>; }, $loose>, ZodObject<...>, ZodObject<...>, ZodObject<...>]>

Any valid JSON-RPC message (request, notification, response, or error response).

JsonrpcMessageFromClientToServer
#

http/jsonrpc.ts view source

ZodUnion<readonly [ZodObject<{ jsonrpc: ZodLiteral<"2.0">; id: ZodUnion<readonly [ZodString, ZodNumber]>; method: ZodString; params: ZodOptional<ZodObject<{}, $loose>>; }, $loose>, ZodObject<...>]>

Messages a client can send to a server (request or notification).

JsonrpcMessageFromServerToClient
#

http/jsonrpc.ts view source

ZodUnion<readonly [ZodObject<{ jsonrpc: ZodLiteral<"2.0">; method: ZodString; params: ZodOptional<ZodObject<{}, $loose>>; }, $loose>, ZodObject<...>, ZodObject<...>]>

Messages a server can send to a client (notification, response, or error response).

JsonrpcMethod
#

JsonrpcNotification
#

http/jsonrpc.ts view source

ZodObject<{ jsonrpc: ZodLiteral<"2.0">; method: ZodString; params: ZodOptional<ZodObject<{}, $loose>>; }, $loose>

A notification which does not expect a response.

JsonrpcNotificationParams
#

http/jsonrpc.ts view source

ZodObject<{}, $loose>

Notification params โ€” loose object. Per-action schemas validate _meta content.

JsonrpcProgressToken
#

http/jsonrpc.ts view source

ZodUnion<readonly [ZodString, ZodNumber]>

A progress token, used to associate progress notifications with the original request.

JsonrpcRequest
#

http/jsonrpc.ts view source

ZodObject<{ jsonrpc: ZodLiteral<"2.0">; id: ZodUnion<readonly [ZodString, ZodNumber]>; method: ZodString; params: ZodOptional<ZodObject<{}, $loose>>; }, $loose>

A request that expects a response.

JsonrpcRequestId
#

http/jsonrpc.ts view source

ZodUnion<readonly [ZodString, ZodNumber]>

A uniquely identifying id for a request in JSON-RPC. Like MCP, excludes null.

JsonrpcRequestParams
#

http/jsonrpc.ts view source

ZodObject<{}, $loose>

Request params โ€” loose object. Per-action schemas validate _meta content.

JsonrpcRequestParamsMeta
#

http/jsonrpc.ts view source

ZodObject<{ progressToken: ZodOptional<ZodUnion<readonly [ZodString, ZodNumber]>>; }, $loose>

Request params metadata โ€” extends MCP meta with optional progress token.

JsonrpcResponse
#

http/jsonrpc.ts view source

ZodObject<{ jsonrpc: ZodLiteral<"2.0">; id: ZodUnion<readonly [ZodString, ZodNumber]>; result: ZodJSONSchema; }, $loose>

A successful (non-error) response to a request.

JsonrpcResponseOrError
#

http/jsonrpc.ts view source

ZodUnion<readonly [ZodObject<{ jsonrpc: ZodLiteral<"2.0">; id: ZodUnion<readonly [ZodString, ZodNumber]>; result: ZodJSONSchema; }, $loose>, ZodObject<...>]>

A successful response or an error response.

JsonrpcResult
#

http/jsonrpc.ts view source

ZodJSONSchema

Result โ€” any JSON value per JSON-RPC 2.0 ยง5. Per-action spec.output is the actual contract; the envelope only asserts presence + JSON-ness.

z.json() is required (not implicitly optional like z.unknown() / z.any(), which would let an error envelope {jsonrpc, id, error} parse successfully against the success envelope and break union discrimination).

JsonrpcServerErrorCode
#

http/jsonrpc.ts view source

$ZodBranded<ZodNumber, "JsonrpcServerErrorCode", "out">

A server-defined error code in the -32000 to -32099 range.

Imported by
#