Documentation
¶
Overview ¶
Package jsonrpc implements a tolerant JSON-RPC 2.0 envelope used by the MCP gateway. It parses only what the inspector needs (id, method, params, result, error) and preserves unknown fields verbatim so protocol revisions pass through untouched.
Index ¶
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInternalError = -32603 // CodePolicyDenied is returned when the gateway blocks a request by // policy. The session stays alive; the client sees a readable refusal. CodePolicyDenied = -32010 // CodeApprovalRejected is returned when a human reviewer rejects a held // tool call. CodeApprovalRejected = -32011 // CodeBudgetExceeded is returned when a session/tool budget is exhausted. CodeBudgetExceeded = -32012 )
Standard and gateway-specific error codes.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Error ¶
type Error struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
Error is a JSON-RPC error object.
type ID ¶
type ID struct {
Raw json.RawMessage
}
ID is a JSON-RPC id: string, integer, or null. The zero value means "absent" (notification). Raw preserves the exact wire bytes so the gateway can correlate responses and re-emit the id byte for byte.
func (ID) Key ¶
Key returns a map key for correlation. Distinct wire encodings ("1" vs "\"1\"") produce distinct keys, matching JSON-RPC semantics where ids are compared by value and type.
func (ID) MarshalJSON ¶
MarshalJSON re-emits the exact bytes received.
func (*ID) UnmarshalJSON ¶
UnmarshalJSON captures the raw id bytes.
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID ID `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
// Extra holds unrecognized top-level fields, re-emitted on Marshal.
Extra map[string]json.RawMessage `json:"-"`
}
Message is a single JSON-RPC 2.0 message. Exactly one of Method (request / notification) or Result/Error (response) is set. Extra carries any fields beyond the standard five so re-serialization drops nothing.
func Parse ¶
Parse decodes a single JSON-RPC message, tolerating and preserving unknown top-level fields. It returns an error only for malformed JSON or a message that is neither request, notification, nor response.
func (*Message) IsNotification ¶
IsNotification reports whether m is a notification (no response expected).
func (*Message) IsResponse ¶
IsResponse reports whether m answers an earlier request.