Sign in

    #shiguri-01/mcp/jsonrpc

    JSON-RPC 2.0 wire envelopes and parser.

    #Usage

    // Parse message
    match try! @jsonrpc.decode(json) {
    Request(req) => ...
    Notification(notif) => ...
    Response(res) => ...
    }

    // Build response
    let res = @jsonrpc.Response::Success(id~, result~)

    JsonRpcDecodeError

    pub(all) suberror JsonRpcDecodeError {
    InvalidMessage(String)
    } derive(Eq,
    Debug
    )

    Decode the JSON-RPC envelope only. MCP semantic errors are intentionally handled by the caller after this syntax boundary.

    JsonRpcValidationError

    pub(all) suberror JsonRpcValidationError {
    InvalidEnvelope(String)
    } derive(Eq,
    Debug
    )

    ErrorObject

    pub struct ErrorObject {
    code : Int
    message : String
    data : Json?
    } derive(Eq,
    Debug
    )

    ErrorObject::ErrorObject

    fn ErrorObject::ErrorObject(code~ : Int, message~ : String, data? : Json) -> ErrorObject

    Message

    pub enum Message {
    Request(Request[Json])
    Notification(Notification[Json])
    Response(Response[Json])
    }

    Notification

    pub struct Notification[Params] {
    method_name : String
    params : Params
    } derive(Eq,
    Debug
    )

    A JSON-RPC notification envelope. Notifications never carry an id.
    impl ToJson for Notification[Params]

    Notification::Notification

    fn[Params] Notification::Notification(method_name~ : String, params~ : Params) -> Notification[Params] raise JsonRpcValidationError

    Request

    pub struct Request[Params] {
    id : RequestId
    method_name : String
    params : Params
    } derive(Eq,
    Debug
    )

    A JSON-RPC request envelope. Params is intentionally unconstrained at this layer; the MCP protocol package supplies the method-specific type.
    impl ToJson for Request[Params]

    Request::Request

    fn[Params] Request::Request(id~ : RequestId, method_name~ : String, params~ : Params) -> Request[Params] raise JsonRpcValidationError

    RequestId

    pub enum RequestId {
    String(String)
    Number(value~ : Double, repr~ : String)
    } derive(Eq,
    Debug
    )

    impl ToJson for RequestId

    RequestId::as_json

    fn RequestId::as_json(self : RequestId) -> Json

    RequestId::number

    fn RequestId::number(value : Double, repr? : String) -> RequestId raise JsonRpcValidationError

    RequestId::string

    fn RequestId::string(value : String) -> RequestId

    RequestId::to_routing_key

    fn RequestId::to_routing_key(self : RequestId) -> String

    Response

    pub(all) enum Response[Result] {
    Success(id~ : RequestId, result~ : Result)
    Failure(id~ : RequestId?, error~ : ErrorObject)
    } derive(Eq,
    Debug
    )

    impl ToJson for Response[Result]

    INTERNAL_ERROR

    let INTERNAL_ERROR : Int

    INVALID_PARAMS

    let INVALID_PARAMS : Int

    INVALID_REQUEST

    let INVALID_REQUEST : Int

    JSON_RPC_VERSION

    let JSON_RPC_VERSION : String

    JSON-RPC 2.0 wire types used by MCP.

    This package deliberately knows nothing about MCP methods, transports, or HTTP headers. It only validates the JSON-RPC envelope and preserves the payload for the protocol layer.

    METHOD_NOT_FOUND

    let METHOD_NOT_FOUND : Int

    PARSE_ERROR

    let PARSE_ERROR : Int

    decode

    fn decode(value : Json) -> Message raise JsonRpcDecodeError

    Source Files

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io