x
This commit is contained in:
62
internal/mcp/jsonrpc.go
Normal file
62
internal/mcp/jsonrpc.go
Normal file
@@ -0,0 +1,62 @@
|
||||
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"`
|
||||
}
|
||||
Reference in New Issue
Block a user