jsonrpc.ts

Declarations
#

Following MCP, Zzz supports a subset of JSON-RPC 2.0 as its message format (A2A too, but I haven't looked into if they support the full spec). It can be used by multiple transports including http and websocket.

These are the JSON-RPC types from the MCP draft in May 2025, changed to include a prefix on all identifiers. It's also defined with Zod schemas instead of plain TS like the MCP library.

MCP messages are a subset of JSON-RPC:

- params does not support the positional array format, and result supports only object values, instead of being any JSON value. - MCP does not support batching, see https://github.com/modelcontextprotocol/modelcontextprotocol/pull/416 and https://github.com/modelcontextprotocol/modelcontextprotocol/pull/228

@source https://github.com/modelcontextprotocol/typescript-sdk @see https://modelcontextprotocol.io/ @license https://github.com/modelcontextprotocol/typescript-sdk/blob/main/LICENSE

MIT License

Copyright (c) 2024 Anthropic, PBC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

30 declarations

view source

JSONRPC_INTERNAL_ERROR
#

JSONRPC_INVALID_PARAMS
#

JSONRPC_INVALID_REQUEST
#

JSONRPC_LATEST_PROTOCOL_VERSION
#

JSONRPC_METHOD_NOT_FOUND
#

JSONRPC_PARSE_ERROR
#

JSONRPC_SERVER_ERROR_END
#

JSONRPC_SERVER_ERROR_START
#

JSONRPC_VERSION
#

JsonrpcErrorCode
#

jsonrpc.ts view source

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

JsonrpcErrorJson
#

jsonrpc.ts view source

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

JsonrpcErrorMessage
#

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 to a request that indicates an error occurred.

JsonrpcMcpMeta
#

JsonrpcMessage
#

jsonrpc.ts view source

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

Refers to any valid JSON-RPC object that can be decoded off the wire, or encoded to be sent.

JsonrpcMessageFromClientToServer
#

jsonrpc.ts view source

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

JsonrpcMessageFromServerToClient
#

jsonrpc.ts view source

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

JsonrpcMethod
#

JsonrpcNotification
#

jsonrpc.ts view source

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

A notification which does not expect a response.

JsonrpcNotificationParams
#

JsonrpcParams
#

jsonrpc.ts view source

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

JsonrpcProgressToken
#

jsonrpc.ts view source

ZodUnion<readonly [ZodString, ZodNumber]>

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

JsonrpcRequest
#

jsonrpc.ts view source

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

A request that expects a response.

JsonrpcRequestId
#

jsonrpc.ts view source

ZodUnion<readonly [ZodString, ZodNumber]>

A uniquely identifying id for a request in JSON-RPC.

Like MCP but unlike JSON-RPC, the type excludes null.

JsonrpcRequestParams
#

jsonrpc.ts view source

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

JsonrpcRequestParamsMeta
#

jsonrpc.ts view source

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

JsonrpcResponse
#

jsonrpc.ts view source

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

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

JsonrpcResponseOrError
#

jsonrpc.ts view source

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

Convenience helper union.

JsonrpcResult
#

JsonrpcServerErrorCode
#

JsonrpcSingularMessage
#

jsonrpc.ts view source

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

Imported by
#