jsonrpc

package
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2026 License: MIT Imports: 3 Imported by: 0

Documentation

Overview

Package jsonrpc defines minimal JSON-RPC 2.0 envelopes used by mcpbench and a lock-free monotonically increasing correlation-id allocator.

Index

Constants

View Source
const Version = "2.0"

Version is the JSON-RPC protocol version string.

Variables

View Source
var ErrUnknownID = errors.New("jsonrpc: unknown response id")

ErrUnknownID is returned when demuxing a response whose id is not registered.

Functions

This section is empty.

Types

type Error

type Error struct {
	Code    int    `json:"code"`
	Message string `json:"message"`
	Data    any    `json:"data,omitempty"`
}

Error is the error field inside a JSON-RPC response.

func (*Error) Error

func (e *Error) Error() string

Error implements the error interface.

type IDPool

type IDPool struct {
	// contains filtered or unexported fields
}

IDPool allocates monotonically increasing correlation IDs starting at 1.

func NewIDPool

func NewIDPool() *IDPool

NewIDPool returns a fresh IDPool.

func (*IDPool) Next

func (p *IDPool) Next() int64

Next returns the next unique id.

type Request

type Request struct {
	JSONRPC string `json:"jsonrpc"`
	ID      int64  `json:"id"`
	Method  string `json:"method"`
	Params  any    `json:"params,omitempty"`
}

Request represents a single JSON-RPC 2.0 request envelope.

func NewRequest

func NewRequest(id int64, method string, params any) *Request

NewRequest constructs a valid JSON-RPC request envelope.

func (*Request) Marshal

func (r *Request) Marshal() ([]byte, error)

Marshal serializes the request to a single line of JSON (no trailing newline).

type Response

type Response struct {
	JSONRPC string          `json:"jsonrpc"`
	ID      int64           `json:"id"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *Error          `json:"error,omitempty"`
}

Response represents a single JSON-RPC 2.0 response envelope.

func ParseResponse

func ParseResponse(data []byte) (*Response, error)

ParseResponse parses a single JSON-RPC response frame.

type ToolCallParams

type ToolCallParams struct {
	Name      string         `json:"name"`
	Arguments map[string]any `json:"arguments,omitempty"`
}

ToolCallParams is the MCP tools/call params shape.

Jump to

Keyboard shortcuts

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