jsonrpc

package
v1.0.430 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 13, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package jsonrpc is the MCP kernel's single strict JSON / JSON-RPC 2.0 decoder and envelope classifier. It has no second, lenient path: every inbound message is validated once by this package, and the classification it returns is the only one the rest of the kernel acts on (MCP-PROTO-001, no parser differential).

The decoder is peer-role- and direction-agnostic on purpose: the SAME strict parser serves both the client-facing and the upstream-server-facing legs (MCP-PROTO-015); admission (which methods/versions are allowed) is layered on top by the protocol package, never by forking the parser.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Class

type Class int

Class is the JSON-RPC message class the strict decoder assigns. Every valid message is exactly one class; an ambiguous or malformed envelope is ClassInvalid and is never forwarded (MCP-PROTO-002).

const (
	// ClassInvalid is the zero value: not a valid, classifiable message.
	ClassInvalid Class = iota
	// ClassRequest — has a method and a correlatable id.
	ClassRequest
	// ClassNotification — has a method and NO id (one-way).
	ClassNotification
	// ClassResponse — no method, a correlatable id, and exactly one of result/error.
	ClassResponse
)

func (Class) String

func (c Class) String() string

String returns the class label (request/notification/response/invalid).

type ErrorObject

type ErrorObject struct {
	Code    int64
	Message string
	Data    json.RawMessage
}

ErrorObject is a validated JSON-RPC error member of a response. Data is kept as raw bytes (a view into the original frame) and is length-bounded; the kernel never re-parses business content.

type ID

type ID struct {
	Kind IDKind
	Int  int64
	Str  string
}

ID is a decoded JSON-RPC id. Integer ids are kept as int64 — never routed through float64 — so a large integer id cannot be silently rounded into a different value and mis-correlate (MCP-PROTO-003).

func (ID) Absent

func (id ID) Absent() bool

Absent reports whether no id member was present (notification shape).

func (ID) Correlatable

func (id ID) Correlatable() bool

Correlatable reports whether the id can key an outstanding-request entry — true only for a concrete integer or string id, never absent or null.

func (ID) Key

func (id ID) Key() string

Key returns a stable, collision-free correlation key for a correlatable id. Integer and string ids live in disjoint key spaces ("i:" vs "s:") so the integer id 7 and the string id "7" never collide. Panics on a non-correlatable id — callers must gate on Correlatable first.

func (ID) String

func (id ID) String() string

String renders the id for debugging. It never echoes raw hostile bytes beyond a bounded, sanitized form of a string id.

type IDKind

type IDKind int

IDKind is the shape of a JSON-RPC id member.

const (
	// IDAbsent — the message carried no "id" member (a notification).
	IDAbsent IDKind = iota
	// IDNull — an explicit JSON null id. Not correlatable; only ever legitimate on
	// an outbound "unparseable input" error, never accepted as a request id.
	IDNull
	// IDInt — an integer id preserved exactly as int64 (no float precision loss).
	IDInt
	// IDString — a string id.
	IDString
)

type Message

type Message struct {
	Class  Class
	Method string          // request/notification only
	ID     ID              // request/response only
	Params json.RawMessage // request/notification only (may be nil)
	Result json.RawMessage // response only (present iff Error==nil)
	Error  *ErrorObject    // response only (present iff Result==nil)
	Raw    []byte          // the exact validated frame; forward THIS, never a re-encoding
}

Message is the result of decoding one frame. It carries the classification and the envelope fields; Params/Result are raw views into the ORIGINAL frame bytes so the message forwarded downstream is byte-identical to the one validated here (MCP-PROTO-001, no parser differential). Raw is the whole original frame.

func Decode

func Decode(raw []byte, lim limits.Limits) (Message, error)

Decode strictly validates and classifies a single JSON-RPC frame under the given limits. It returns a Message whose Raw is the exact validated frame (forward Raw downstream — never a re-encoding — to preserve MCP-PROTO-001's no-differential guarantee) or a typed *mcperr.Error. It never panics on arbitrary input (MCP-PROTO-009) and never echoes raw hostile bytes.

func (Message) IsNotification

func (m Message) IsNotification() bool

IsNotification reports whether the message is a notification.

func (Message) IsRequest

func (m Message) IsRequest() bool

IsRequest / IsNotification / IsResponse are convenience predicates.

func (Message) IsResponse

func (m Message) IsResponse() bool

IsResponse reports whether the message is a response.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL