Files
chatlog/internal/mcp/jsonrpc.go
Shen Junzheng 78cce92ce3 x
2025-03-19 13:11:09 +08:00

63 lines
1.1 KiB
Go

package mcp
const (
JsonRPCVersion = "2.0"
)
// Documents: https://modelcontextprotocol.io/docs/concepts/transports
// Request
//
// {
// jsonrpc: "2.0",
// id: number | string,
// method: string,
// params?: object
// }
type Request struct {
JsonRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}
// Response
//
// {
// jsonrpc: "2.0",
// id: number | string,
// result?: object,
// error?: {
// code: number,
// message: string,
// data?: unknown
// }
// }
type Response struct {
JsonRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Result interface{} `json:"result,omitempty"`
Error *Error `json:"error,omitempty"`
}
func NewResponse(id interface{}, result interface{}) *Response {
return &Response{
JsonRPC: JsonRPCVersion,
ID: id,
Result: result,
}
}
// Notifications
//
// {
// jsonrpc: "2.0",
// method: string,
// params?: object
// }
type Notification struct {
JsonRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params interface{} `json:"params,omitempty"`
}