Skip to main content
Glama
FreePeak

Multi Database MCP Server

jsonrpc.go2.7 kB
package jsonrpc import ( "fmt" ) // Version is the JSON-RPC version string const Version = "2.0" // Request represents a JSON-RPC request type Request struct { JSONRPC string `json:"jsonrpc"` ID interface{} `json:"id,omitempty"` Method string `json:"method"` Params interface{} `json:"params,omitempty"` } // IsNotification returns true if the request is a notification (has no ID) func (r *Request) IsNotification() bool { return r.ID == nil } // Response represents a JSON-RPC response type Response struct { JSONRPC string `json:"jsonrpc"` ID interface{} `json:"id,omitempty"` Result interface{} `json:"result,omitempty"` Error *Error `json:"error,omitempty"` } // Error represents a JSON-RPC error type Error struct { Code int `json:"code"` Message string `json:"message"` Data interface{} `json:"data,omitempty"` } // Standard error codes const ( ParseErrorCode = -32700 InvalidRequestCode = -32600 MethodNotFoundCode = -32601 InvalidParamsCode = -32602 InternalErrorCode = -32603 ) // Error returns a string representation of the error func (e *Error) Error() string { return fmt.Sprintf("JSON-RPC error %d: %s", e.Code, e.Message) } // NewResponse creates a new response for the given request func NewResponse(req *Request, result interface{}, err *Error) *Response { resp := &Response{ JSONRPC: Version, ID: req.ID, } if err != nil { resp.Error = err } else { resp.Result = result } return resp } // NewError creates a new Error with the given code and message func NewError(code int, message string, data interface{}) *Error { return &Error{ Code: code, Message: message, Data: data, } } // ParseError creates a Parse Error func ParseError(data interface{}) *Error { return &Error{ Code: ParseErrorCode, Message: "Parse error", Data: data, } } // InvalidRequestError creates an Invalid Request error func InvalidRequestError(data interface{}) *Error { return &Error{ Code: InvalidRequestCode, Message: "Invalid request", Data: data, } } // MethodNotFoundError creates a Method Not Found error func MethodNotFoundError(method string) *Error { return &Error{ Code: MethodNotFoundCode, Message: "Method not found", Data: method, } } // InvalidParamsError creates an Invalid Params error func InvalidParamsError(data interface{}) *Error { return &Error{ Code: InvalidParamsCode, Message: "Invalid params", Data: data, } } // InternalError creates an Internal Error func InternalError(data interface{}) *Error { return &Error{ Code: InternalErrorCode, Message: "Internal error", Data: data, } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/FreePeak/db-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server