protocol

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Sep 24, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 9 Imported by: 0

Documentation

Overview

Package protocol implements bounded MCP 2026-07-28 wire types.

Index

Constants

View Source
const (
	Version        = "2026-07-28"
	JSONRPCVersion = "2.0"

	MaxMessageBytes = 1 << 20
	MaxJSONDepth    = 64
	// Reflectable request scalars are smaller than a frame so every error
	// response remains independently bounded.
	MaxRequestIDBytes       = 128
	MaxProtocolVersionBytes = 64

	CodeParseError                 = -32700
	CodeInvalidRequest             = -32600
	CodeMethodNotFound             = -32601
	CodeInvalidParams              = -32602
	CodeInternalError              = -32603
	CodeUnsupportedProtocolVersion = -32022
)
View Source
const LegacyVersion = "2025-11-25"

Variables

This section is empty.

Functions

func Decode

func Decode(raw []byte) (Inbound, *DecodeError)

Decode accepts one newline-free stdio message body. Syntax, UTF-8, duplicate-key, size, and depth failures intentionally discard any ID.

func DecodeLegacyInitialize

func DecodeLegacyInitialize(params map[string]any) (RequestMeta, *RPCError)

func DecodeLegacyRequestMeta

func DecodeLegacyRequestMeta(params map[string]any) (RequestMeta, *RPCError)

Legacy requests carry optional progress metadata; modern transport metadata must never change the connection's explicitly selected protocol.

func DecodeRequestMeta

func DecodeRequestMeta(params map[string]any) (RequestMeta, *RPCError)

func ExtractVersionArgument

func ExtractVersionArgument(arguments []string) ([]string, string, bool)

ExtractVersionArgument removes the optional, closed protocol selector before the command validates its own required arguments.

Types

type DecodeError

type DecodeError struct {
	Code    int
	Message string
	ID      *ID
}

func (*DecodeError) Error

func (e *DecodeError) Error() string

type ID

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

ID preserves the type and exact integer spelling of a JSON-RPC request ID.

func NewIntegerID

func NewIntegerID(value int64) ID

func NewStringID

func NewStringID(value string) (ID, error)

func ParseIDValue

func ParseIDValue(value any) (ID, bool)

ParseIDValue validates a decoded JSON value as a protocol request ID.

func (ID) Key

func (id ID) Key() string

func (ID) MarshalJSON

func (id ID) MarshalJSON() ([]byte, error)

func (ID) Valid

func (id ID) Valid() bool

type Inbound

type Inbound struct {
	ID           *ID
	Method       string
	Params       map[string]any
	Notification bool
}

type RPCError

type RPCError struct {
	Code    int
	Message string
	Data    any
}

func DecodeCursor

func DecodeCursor(params map[string]any) (string, *RPCError)

DecodeCursor returns the optional cursor on current list requests.

func InvalidParams

func InvalidParams(message string) *RPCError

func MethodNotFound

func MethodNotFound() *RPCError

func NewError

func NewError(code int, message string) *RPCError

type Request

type Request struct {
	ID     ID
	Method string
	Params map[string]any
	Meta   RequestMeta
}

type RequestMeta

type RequestMeta struct {
	ProtocolVersion    string
	ClientCapabilities map[string]any
	ClientInfo         map[string]any
	LogLevel           string
	ProgressToken      any
}

Jump to

Keyboard shortcuts

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