Documentation
¶
Index ¶
- type BaseJSONRPCError
- type BaseJSONRPCErrorInner
- type BaseJSONRPCNotification
- type BaseJSONRPCRequest
- type BaseJSONRPCResponse
- type BaseJsonRpcMessage
- func NewBaseMessageError(error *BaseJSONRPCError) *BaseJsonRpcMessage
- func NewBaseMessageNotification(notification *BaseJSONRPCNotification) *BaseJsonRpcMessage
- func NewBaseMessageRequest(request *BaseJSONRPCRequest) *BaseJsonRpcMessage
- func NewBaseMessageResponse(response *BaseJSONRPCResponse) *BaseJsonRpcMessage
- type BaseMessageType
- type JSONRPCMessage
- type JsonRpcBody
- type RequestId
- type Transport
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BaseJSONRPCError ¶
type BaseJSONRPCError struct {
// Error corresponds to the JSON schema field "error".
Error BaseJSONRPCErrorInner `json:"error" yaml:"error" mapstructure:"error"`
// Id corresponds to the JSON schema field "id".
Id RequestId `json:"id" yaml:"id" mapstructure:"id"`
// Jsonrpc corresponds to the JSON schema field "jsonrpc".
Jsonrpc string `json:"jsonrpc" yaml:"jsonrpc" mapstructure:"jsonrpc"`
}
A response to a request that indicates an error occurred.
type BaseJSONRPCErrorInner ¶
type BaseJSONRPCErrorInner struct {
// The error type that occurred.
Code int `json:"code" yaml:"code" mapstructure:"code"`
// 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" yaml:"data,omitempty" mapstructure:"data,omitempty"`
// A short description of the error. The message SHOULD be limited to a concise
// single sentence.
Message string `json:"message" yaml:"message" mapstructure:"message"`
}
type BaseJSONRPCNotification ¶
type BaseJSONRPCNotification struct {
// Jsonrpc corresponds to the JSON schema field "jsonrpc".
Jsonrpc string `json:"jsonrpc" yaml:"jsonrpc" mapstructure:"jsonrpc"`
// Method corresponds to the JSON schema field "method".
Method string `json:"method" yaml:"method" mapstructure:"method"`
// Params corresponds to the JSON schema field "params".
// It is stored as a []byte to enable efficient marshaling and unmarshaling into custom types later on in the protocol
Params json.RawMessage `json:"params,omitempty" yaml:"params,omitempty" mapstructure:"params,omitempty"`
}
func (*BaseJSONRPCNotification) UnmarshalJSON ¶
func (m *BaseJSONRPCNotification) UnmarshalJSON(data []byte) error
Custom Notification unmarshaling Requires a Jsonrpc and Method
type BaseJSONRPCRequest ¶
type BaseJSONRPCRequest struct {
// Id corresponds to the JSON schema field "id".
Id RequestId `json:"id" yaml:"id" mapstructure:"id"`
// Jsonrpc corresponds to the JSON schema field "jsonrpc".
Jsonrpc string `json:"jsonrpc" yaml:"jsonrpc" mapstructure:"jsonrpc"`
// Method corresponds to the JSON schema field "method".
Method string `json:"method" yaml:"method" mapstructure:"method"`
// Params corresponds to the JSON schema field "params".
// It is stored as a []byte to enable efficient marshaling and unmarshaling into custom types later on in the protocol
Params json.RawMessage `json:"params,omitempty" yaml:"params,omitempty" mapstructure:"params,omitempty"`
}
func (*BaseJSONRPCRequest) UnmarshalJSON ¶
func (m *BaseJSONRPCRequest) UnmarshalJSON(data []byte) error
Custom Request unmarshaling Requires an Id, Jsonrpc and Method
type BaseJSONRPCResponse ¶
type BaseJSONRPCResponse struct {
// Id corresponds to the JSON schema field "id".
Id RequestId `json:"id" yaml:"id" mapstructure:"id"`
// Jsonrpc corresponds to the JSON schema field "jsonrpc".
Jsonrpc string `json:"jsonrpc" yaml:"jsonrpc" mapstructure:"jsonrpc"`
// Result corresponds to the JSON schema field "result".
Result json.RawMessage `json:"result" yaml:"result" mapstructure:"result"`
}
func (*BaseJSONRPCResponse) UnmarshalJSON ¶
func (m *BaseJSONRPCResponse) UnmarshalJSON(data []byte) error
Custom Response unmarshaling Requires an Id, Jsonrpc and Result
type BaseJsonRpcMessage ¶
type BaseJsonRpcMessage struct {
Type BaseMessageType
JsonRpcRequest *BaseJSONRPCRequest
JsonRpcNotification *BaseJSONRPCNotification
JsonRpcResponse *BaseJSONRPCResponse
JsonRpcError *BaseJSONRPCError
}
func NewBaseMessageError ¶
func NewBaseMessageError(error *BaseJSONRPCError) *BaseJsonRpcMessage
func NewBaseMessageNotification ¶
func NewBaseMessageNotification(notification *BaseJSONRPCNotification) *BaseJsonRpcMessage
func NewBaseMessageRequest ¶
func NewBaseMessageRequest(request *BaseJSONRPCRequest) *BaseJsonRpcMessage
func NewBaseMessageResponse ¶
func NewBaseMessageResponse(response *BaseJSONRPCResponse) *BaseJsonRpcMessage
func (*BaseJsonRpcMessage) MarshalJSON ¶
func (m *BaseJsonRpcMessage) MarshalJSON() ([]byte, error)
type BaseMessageType ¶
type BaseMessageType string
const ( BaseMessageTypeJSONRPCRequestType BaseMessageType = "request" BaseMessageTypeJSONRPCNotificationType BaseMessageType = "notification" BaseMessageTypeJSONRPCResponseType BaseMessageType = "response" BaseMessageTypeJSONRPCErrorType BaseMessageType = "error" )
type JSONRPCMessage ¶
type JSONRPCMessage interface{}
type JsonRpcBody ¶
type JsonRpcBody interface{}
type Transport ¶
type Transport interface {
// Start starts processing messages on the transport, including any connection steps that might need to be taken.
//
// This method should only be called after callbacks are installed, or else messages may be lost.
//
// NOTE: This method should not be called explicitly when using Client, Server, or Protocol classes,
// as they will implicitly call start().
Start(ctx context.Context) error
// Send sends a JSON-RPC message (request, notification or response).
Send(ctx context.Context, message *BaseJsonRpcMessage) error
// Close closes the connection.
Close() error
// SetCloseHandler sets the callback for when the connection is closed for any reason.
// This should be invoked when Close() is called as well.
SetCloseHandler(handler func())
// SetErrorHandler sets the callback for when an error occurs.
// Note that errors are not necessarily fatal; they are used for reporting any kind of exceptional condition out of band.
SetErrorHandler(handler func(error))
// SetMessageHandler sets the callback for when a message (request, notification or response) is received over the connection.
// Partially deserializes the messages to pass a BaseJsonRpcMessage
SetMessageHandler(handler func(ctx context.Context, message *BaseJsonRpcMessage))
}
Transport describes the minimal contract for a MCP transport that a client or server can communicate over.
Directories
¶
| Path | Synopsis |
|---|---|
|
internal/sse
/* Package mcp implements Server-Sent Events (SSE) transport for JSON-RPC communication.
|
/* Package mcp implements Server-Sent Events (SSE) transport for JSON-RPC communication. |
|
internal/stdio
This file implements the stdio transport layer for JSON-RPC communication.
|
This file implements the stdio transport layer for JSON-RPC communication. |
Click to show internal directories.
Click to hide internal directories.