jsonrpc

package
v1.9.0 Latest Latest
Warning

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

Go to latest
Published: Aug 14, 2026 License: Apache-2.0 Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// Standard JSON-RPC error codes
	PARSE_ERROR                        = -32700
	INVALID_REQUEST                    = -32600
	METHOD_NOT_FOUND                   = -32601
	INVALID_PARAMS                     = -32602
	INTERNAL_ERROR                     = -32603
	HEADER_MISMATCH                    = -32020
	MISSING_REQUIRED_CLIENT_CAPABILITY = -32021
	UNSUPPORTED_PROTOCOL_VERSION       = -32022

	// Custom auth error codes
	UNAUTHORIZED = -401
	FORBIDDEN    = -403
)
View Source
const JSONRPC_VERSION = "2.0"

JSONRPC_VERSION is the version of JSON-RPC used by MCP.

Variables

This section is empty.

Functions

This section is empty.

Types

type BaseMessage

type BaseMessage struct {
	Jsonrpc string         `json:"jsonrpc"`
	Method  string         `json:"method"`
	Id      RequestId      `json:"id,omitempty"`
	Params  *RequestParams `json:"params,omitempty"`
}

Generic baseMessage could either be a JSONRPCNotification or JSONRPCRequest

type Error

type Error struct {
	// The error type that occurred.
	Code int `json:"code"`
	// A short description of the error. The message SHOULD be limited
	// to a concise single sentence.
	Message string `json:"message"`
	// Additional information about the error. The value of this member
	// is defined by the sender (e.g. detailed error information, nested errors etc.).
	Data interface{} `json:"data,omitempty"`
}

Error represents the error content.

func (Error) String

func (e Error) String() string

String returns the error type as a string based on the error code.

type JSONRPCError

type JSONRPCError struct {
	Jsonrpc string    `json:"jsonrpc"`
	Id      RequestId `json:"id"`
	Error   Error     `json:"error"`
}

JSONRPCError represents a non-successful (error) response to a request.

func NewError

func NewError(id RequestId, code int, message string, data any) JSONRPCError

NewError is the standard JSONRPC response sent back when an error has been encountered.

func NewHeaderMismatchedError added in v1.6.0

func NewHeaderMismatchedError(id RequestId, err error) JSONRPCError

func NewUnsupportedProtocolVersionError added in v1.6.0

func NewUnsupportedProtocolVersionError(id RequestId, v string, enableDraft bool) (JSONRPCError, error)

type JSONRPCNotification

type JSONRPCNotification struct {
	Jsonrpc string `json:"jsonrpc"`
	Notification
}

JSONRPCNotification represents a notification which does not expect a response.

type JSONRPCRequest

type JSONRPCRequest struct {
	Jsonrpc string    `json:"jsonrpc"`
	Id      RequestId `json:"id"`
	Request
	Params any `json:"params,omitempty"`
}

JSONRPCRequest represents a request that expects a response.

type JSONRPCResponse

type JSONRPCResponse struct {
	Jsonrpc string      `json:"jsonrpc"`
	Id      RequestId   `json:"id"`
	Result  interface{} `json:"result"`
}

JSONRPCResponse represents a successful (non-error) response to a request.

type Notification

type Notification struct {
	Method string `json:"method"`
	Params struct {
		Meta map[string]interface{} `json:"_meta,omitempty"`
	} `json:"params,omitempty"`
}

Notification is a one-way message requiring no response.

type ProgressToken

type ProgressToken interface{}

ProgressToken is used to associate progress notifications with the original request.

type Request

type Request struct {
	Method string `json:"method"`
}

Request represents a bidirectional message with method and parameters expecting a response.

type RequestId

type RequestId interface{}

RequestId is a uniquely identifying ID for a request in JSON-RPC. It can be any JSON-serializable value, typically a number or string.

type RequestMetaObject added in v1.6.0

type RequestMetaObject struct {
	// W3C Trace Context fields for distributed tracing
	Traceparent string `json:"traceparent,omitempty"`
	Tracestate  string `json:"tracestate,omitempty"`
}

type RequestParams added in v1.6.0

type RequestParams struct {
	Meta *RequestMetaObject `json:"_meta"`
}

type Result

type Result struct {
	// This result property is reserved by the protocol to allow clients and
	// servers to attach additional metadata to their responses.
	Meta map[string]interface{} `json:"_meta,omitempty"`
}

Result represents a response for the request query.

Jump to

Keyboard shortcuts

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