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 )
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 ¶
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) Correlatable ¶
Correlatable reports whether the id can key an outstanding-request entry — true only for a concrete integer or string id, never absent or null.
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 ¶
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 ¶
IsNotification reports whether the message is a notification.
func (Message) IsResponse ¶
IsResponse reports whether the message is a response.