Sign in

    mcp

    A library for building Model Context Protocol servers and clients.

    mcp
    model-context-protocol
    agent
    llm
    Download zip
    Version
    0.2.0
    License
    Apache-2.0
    Last updated
    2 months ago
    Downloads
    53

    #shiguri-01/mcp

    A MoonBit library for building Model Context Protocol (MCP) servers and clients. It implements the 2026-07-28 specification.

    #Server

    Define typed inputs with @schema.JsonSchema and @json.FromJson, register them on @server.ServerBuilder, and serve over standard I/O or Streamable HTTP.

    struct GreetInput {
    name : String
    } derive(@json.FromJson, ToJson)

    impl @schema.JsonSchema for GreetInput with fn json_schema() {
    @schema.Schema::object(
    properties={ "name": @schema.Schema::string(min_length=1) },
    required=["name"],
    )
    }

    async fn main {
    let builder = try! @server.ServerBuilder(name="greeter", version="1.0.0")
    try! builder.tool(name="greet", fn(_ctx, input : GreetInput) {
    @mcp.Complete(@mcp.CallToolResult::text("Hello, \{input.name}!"))
    })

    // Stdio transport
    @stdio.serve(builder.build())
    }

    #Client

    Connect to a server and call tools, read resources, or fetch prompts:

    async fn main {
    @async.with_task_group(async fn(group) {
    let transport = try! @stdio.Transport(group, "path/to/server")
    let client = try! @client.Client(name="client", version="1.0.0", transport~)

    match client.call_tool(name="greet", arguments={ "name": "MoonBit" }) {
    Complete(res) => println(res.content)
    InputRequired(pending) => ... // Handle multi-round interactive requests
    ExtensionResult(kind, val) => ...
    }

    transport.shutdown()
    })
    }

    #Packages

    PackageDescription
    shiguri-01/mcpCore protocol types, content models, and error definitions (McpError)
    shiguri-01/mcp/serverTyped server builder, dispatching, and session management
    shiguri-01/mcp/clientClient runtime, discovery, typed invocation, and MRTR resolution
    shiguri-01/mcp/schemaJSON Schema (Draft 2020-12) builder, validator, and typed decoder
    shiguri-01/mcp/stdioStdio transport (server runner & subprocess client)
    shiguri-01/mcp/httpStreamable HTTP transport (SSE progress/subscriptions & OAuth 2.0)
    shiguri-01/mcp/authNative MCP Authorization (RFC 9728, PKCE S256, token caching)
    shiguri-01/mcp/jsonrpcLow-level JSON-RPC 2.0 wire envelopes and parser

    #Examples

    # Stdio Server & Client moon build --target native src/examples/stdio-server MCP_STDIO_SERVER="$PWD/_build/native/debug/build/examples/stdio-server/stdio-server" \ moon run --target native src/examples/stdio-client # HTTP Server & Client moon run --target native src/examples/http-server moon run --target native src/examples/http-client

    PromptArguments

    pub(open) trait PromptArguments {
    fn prompt_arguments() -> Array[PromptArgument]
    }

    A typed prompt declares the arguments it accepts through this trait.

    McpError

    pub(all) suberror McpError {
    ParseError(String)
    InvalidRequest(String)
    MethodNotFound(String)
    InvalidParams(String)
    InvalidParamsWithData(String, Json)
    InternalError(String)
    HeaderMismatch(String)
    MissingRequiredClientCapability(String, ClientCapabilities)
    UnsupportedProtocolVersion(requested~ : String, supported~ : Array[String])
    RemoteError(code~ : Int, message~ : String, data~ : Json?)
    } derive(Eq,
    Debug
    )

    Protocol and SDK errors. Application-level tool failures remain ordinary CallToolResult values and are not represented here.
    impl Show for McpError
    impl ToJson for McpError

    McpError::code

    fn McpError::code(self : McpError) -> Int

    McpError::data

    fn McpError::data(self : McpError) -> Json?

    McpError::from_error_object

    Decode an MCP error object from a JSON-RPC error structure.

    McpError::from_jsonrpc_decode_error

    MCP's wire layer bridges the transport layer and the canonical jsonrpc package.

    It translates JSON-RPC envelopes into MCP semantics and errors without re-implementing JSON-RPC wire parsing.

    McpError::from_rpc_parts

    fn McpError::from_rpc_parts(code : Int, message : String, data? : Json) -> McpError raise McpError

    Decode an MCP error object after a JSON-RPC implementation has separated its code, message, and optional data members.

    McpError::message

    fn McpError::message(self : McpError) -> String

    McpError::to_error_object

    McpError::to_string

    fn McpError::to_string(self : McpError) -> String

    Annotations

    pub struct Annotations {
    audience : Array[Role]
    priority : Double?
    last_modified : String?
    } derive(Eq,
    Debug
    )

    Annotations::Annotations

    fn Annotations::Annotations(audience? : Array[Role], priority? : Double, last_modified? : String) -> Annotations raise McpError

    Annotations::from_json

    CachePolicy

    pub struct CachePolicy {
    ttl_ms : Int64
    scope : CacheScope
    } derive(Eq,
    Debug
    )

    Validated caching advice for discover, list, and resource read results.

    CachePolicy::CachePolicy

    fn CachePolicy::CachePolicy(ttl_ms~ : Int64, scope? : CacheScope) -> CachePolicy raise McpError

    CachePolicy::from_json

    CacheScope

    pub(all) enum CacheScope {
    Public
    Private
    } derive(Eq,
    Debug
    )

    Cache policy scope: shared across all callers or private to this session/connection.

    CacheScope::from_json

    CallToolParams

    pub struct CallToolParams {
    name : String
    arguments : Json
    } derive(Eq,
    Debug
    )

    Parameters for tools/call.

    CallToolParams::CallToolParams

    fn CallToolParams::CallToolParams(name~ : String, arguments? : Json) -> CallToolParams raise McpError

    CallToolParams::from_json

    CallToolResult

    pub struct CallToolResult {
    content : Array[Content]
    structured_content : Json?
    is_error : Bool
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    CallToolResult::CallToolResult

    fn CallToolResult::CallToolResult(content~ : Array[Content], structured_content? : Json, is_error? : Bool, meta? : ResultMeta) -> CallToolResult

    Construct a tool result with validated ownership of its content array.

    CallToolResult::decode_structured

    Decode the optional structured content as the caller's domain type.

    CallToolResult::error_text

    fn CallToolResult::error_text(text : String, annotations? : Annotations, meta? : Json) -> CallToolResult

    Return a tool error as MCP content, not as a JSON-RPC protocol error.

    CallToolResult::from_json

    CallToolResult::json

    fn CallToolResult::json(value : Json) -> CallToolResult

    Return structured content without a text block.

    CallToolResult::structured

    fn[T : ToJson] CallToolResult::structured(value : T) -> CallToolResult

    Return typed structured content through ToJson.

    CallToolResult::text

    fn CallToolResult::text(text : String, annotations? : Annotations, meta? : Json) -> CallToolResult

    Return a plain text tool result.

    CancelledNotification

    pub struct CancelledNotification {
    params : CancelledNotificationParams
    } derive(Eq,
    Debug
    )

    Notification sent by client to cancel an in-flight request.

    CancelledNotification::CancelledNotification

    fn CancelledNotification::CancelledNotification(request_id~ : Json, reason? : String) -> CancelledNotification raise McpError

    CancelledNotification::to_json

    CancelledNotificationParams

    pub struct CancelledNotificationParams {
    request_id : Json
    reason : String?
    } derive(Eq,
    Debug
    )

    Parameters for notifications/cancelled.

    CancelledNotificationParams::CancelledNotificationParams

    fn CancelledNotificationParams::CancelledNotificationParams(request_id~ : Json, reason? : String) -> CancelledNotificationParams raise McpError

    CancelledNotificationParams::from_json

    ClientCapabilities

    pub struct ClientCapabilities {
    roots : RootsCapability?
    sampling : SamplingCapability?
    elicitation : ElicitationCapability?
    extensions : Map[String, Json]
    experimental : Map[String, Json]
    extra : Map[String, Json]
    } derive(Eq,
    Debug
    )

    Capabilities declared by an MCP client.

    ClientCapabilities::ClientCapabilities

    fn ClientCapabilities::ClientCapabilities(roots? : RootsCapability, sampling? : SamplingCapability, elicitation? : ElicitationCapability, extensions? : Map[String, Json], experimental? : Map[String, Json], extra? : Map[String, Json]) -> ClientCapabilities

    ClientCapabilities::copy

    ClientCapabilities::empty

    ClientCapabilities::from_json

    CompleteResult

    pub struct CompleteResult {
    values : Array[String]
    total : Int?
    has_more : Bool
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    CompleteResult::CompleteResult

    fn CompleteResult::CompleteResult(values~ : Array[String], total? : Int, has_more? : Bool, meta? : ResultMeta) -> CompleteResult raise McpError

    CompleteResult::from_json

    CompletionReference

    pub(all) enum CompletionReference {
    PromptRef(name~ : String, title~ : String?)
    ResourceRef(uri~ : String)
    } derive(Eq,
    Debug
    )

    CompletionReference::prompt

    fn CompletionReference::prompt(name~ : String, title? : String) -> CompletionReference

    CompletionReference::resource

    fn CompletionReference::resource(uri~ : String) -> CompletionReference

    CompletionRequest

    pub struct CompletionRequest {
    reference : CompletionReference
    argument_name : String
    argument_value : String
    context_arguments : Map[String, String]
    meta : Json?
    } derive(Eq,
    Debug
    )

    Content

    pub(all) enum Content {
    TextContent(text~ : String, annotations~ : Annotations?, meta~ : Json?)
    ImageContent(data~ : String, mime_type~ : String, annotations~ : Annotations?, meta~ : Json?)
    AudioContent(data~ : String, mime_type~ : String, annotations~ : Annotations?, meta~ : Json?)
    EmbeddedResource(resource~ : ResourceContent, annotations~ : Annotations?, meta~ : Json?)
    ResourceLink(ResourceLink)
    } derive(Eq,
    Debug
    )

    Content payload accepted by MCP prompts and tool results.

    Corresponds to Content in the MCP specification: TextContent | ImageContent | EmbeddedResource
    impl ToJson for Content

    Content::audio

    fn Content::audio(data~ : String, mime_type~ : String, annotations? : Annotations, meta? : Json) -> Content

    Construct an audio content from base64-encoded data.

    Content::embedded_resource

    fn Content::embedded_resource(resource~ : ResourceContent, annotations? : Annotations, meta? : Json) -> Content

    Construct a content that embeds resource contents inline.

    Content::from_json

    fn Content::from_json(value : Json, path? :
    JsonPath
    ) -> Content raise McpError

    Decode one official MCP content union value.

    Content::image

    fn Content::image(data~ : String, mime_type~ : String, annotations? : Annotations, meta? : Json) -> Content

    Construct an image content from base64-encoded data.
    fn Content::resource_link(resource_link : ResourceLink) -> Content

    Construct a content that links to a readable resource.

    Content::text

    fn Content::text(text : String, annotations? : Annotations, meta? : Json) -> Content

    Construct a text content.

    DiscoverResult

    pub struct DiscoverResult {
    supported_versions : Array[String]
    capabilities : ServerCapabilities
    instructions : String?
    cache_policy : CachePolicy
    meta : ResultMeta?
    } derive(
    Debug
    )

    Result of the stateless server/discover method.

    DiscoverResult::DiscoverResult

    fn DiscoverResult::DiscoverResult(supported_versions? : Array[String], capabilities~ : ServerCapabilities, instructions? : String, cache_policy~ : CachePolicy, meta? : ResultMeta) -> DiscoverResult raise McpError

    DiscoverResult::from_json

    Decode a server/discover result after the JSON-RPC envelope is removed.

    ElicitationAction

    pub(all) enum ElicitationAction {
    Accept
    Decline
    Cancel
    } derive(Eq,
    Debug
    )

    ElicitationCapability

    pub struct ElicitationCapability {
    form : Json?
    url : Json?
    } derive(Eq,
    Debug
    )

    Client support for server-initiated elicitation.

    ElicitationCapability::ElicitationCapability

    fn ElicitationCapability::ElicitationCapability(form? : Json, url? : Json) -> ElicitationCapability

    ElicitationCapability::from_json

    ElicitationCreateParams

    pub struct ElicitationCreateParams {
    message : String
    mode : ElicitationMode
    } derive(
    Debug
    )

    ElicitationCreateResult

    pub struct ElicitationCreateResult {
    action : ElicitationAction
    content : Json?
    } derive(Eq,
    Debug
    )

    ElicitationCreateResult::from_json

    ElicitationCreateResult::validate_against_request

    fn ElicitationCreateResult::validate_against_request(self : ElicitationCreateResult, request_params : Json) -> Unit raise McpError

    ElicitationMode

    pub(all) enum ElicitationMode {
    Url(String)
    Form(requested_schema~ : Json, properties~ : Map[String, ElicitationPrimitiveSchema], compiled_schema~ :
    Schema
    )
    } derive(
    Debug
    )

    ElicitationPrimitiveSchema

    pub struct ElicitationPrimitiveSchema {
    schema_type : ElicitationPrimitiveType
    raw : Json
    } derive(Eq,
    Debug
    )

    ElicitationPrimitiveType

    pub(all) enum ElicitationPrimitiveType {
    String
    Number
    Integer
    Boolean
    Enum(Array[String])
    } derive(Eq,
    Debug
    )

    GetPromptParams

    pub struct GetPromptParams {
    name : String
    arguments : Map[String, String]
    } derive(Eq,
    Debug
    )

    Parameters for prompts/get.

    GetPromptParams::GetPromptParams

    fn GetPromptParams::GetPromptParams(name~ : String, arguments? : Map[String, String]) -> GetPromptParams raise McpError

    GetPromptParams::from_json

    GetPromptResult

    pub struct GetPromptResult {
    description : String?
    messages : Array[PromptMessage]
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    GetPromptResult::GetPromptResult

    fn GetPromptResult::GetPromptResult(messages~ : Array[PromptMessage], description? : String, meta? : ResultMeta) -> GetPromptResult

    Construct a prompt result and retain an owned message array.

    GetPromptResult::from_json

    GetPromptResult::user

    fn GetPromptResult::user(text : String, description? : String) -> GetPromptResult

    Construct a single user prompt message result.

    HandlerOutcome

    pub(all) enum HandlerOutcome[T] {
    Complete(T)
    InputRequired(InputRequiredResult)
    ExtensionResult(String, Json)
    }

    A typed handler can either finish or ask the client for more input.

    HandlerOutcome::decode_response

    fn HandlerOutcome::decode_response(message : Json) -> HandlerOutcome[Json] raise McpError

    Decode a raw JSON-RPC response message into a HandlerOutcome.

    HandlerOutcome::require_complete

    fn[T] HandlerOutcome::require_complete(self : HandlerOutcome[T], context~ : String) -> T raise McpError

    Unwrap a Complete outcome or raise an error if more input is required or an extension result was returned.

    Icon

    pub struct Icon {
    src : String
    mime_type : String?
    sizes : Array[String]
    theme : IconTheme?
    } derive(Eq,
    Debug
    )

    Icon metadata for an MCP implementation.
    impl ToJson for Icon

    Icon::Icon

    fn Icon::Icon(src~ : String, mime_type? : String, sizes? : Array[String], theme? : IconTheme) -> Icon

    IconTheme

    pub(all) enum IconTheme {
    Light
    Dark
    } derive(Eq,
    Debug
    )

    impl ToJson for IconTheme

    IconTheme::to_string

    fn IconTheme::to_string(self : IconTheme) -> String

    Implementation

    pub struct Implementation {
    name : String
    title : String?
    version : String
    description : String?
    icons : Array[Icon]
    website_url : String?
    } derive(Eq,
    Debug
    )

    MCP implementation metadata repeated in each stateless request or result.

    Implementation::Implementation

    fn Implementation::Implementation(name~ : String, version~ : String, title? : String, description? : String, icons? : Array[Icon], website_url? : String) -> Implementation

    InputRequest

    pub struct InputRequest {
    method_name : String
    params : Json
    } derive(Eq,
    Debug
    )

    A server-initiated request carried inside an MRTR result. It deliberately omits JSON-RPC framing: keys in inputRequests provide correlation.

    InputRequest::InputRequest

    fn InputRequest::InputRequest(method_name~ : String, params? : Json) -> InputRequest raise McpError

    InputRequest::from_json

    InputRequiredResult

    pub struct InputRequiredResult {
    input_requests : Map[String, InputRequest]?
    request_state : String?
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    InputRequiredResult::InputRequiredResult

    fn InputRequiredResult::InputRequiredResult(input_requests? : Map[String, InputRequest], request_state? : String, meta? : ResultMeta) -> InputRequiredResult raise McpError

    InputRequiredResult::from_json

    InputRequiredResult::retry_options

    fn InputRequiredResult::retry_options(self : InputRequiredResult, responses : Map[String, InputResponse], base? : RequestOptions) -> RequestOptions raise McpError

    Build retry options while preserving the server's opaque request state. Every requested input must have exactly one response; callers never need to inspect or copy requestState themselves.

    InputResponse

    pub struct InputResponse {
    result : Json
    } derive(Eq,
    Debug
    )

    A raw client result for a server-initiated input request.

    InputResponse::InputResponse

    fn InputResponse::InputResponse(result : Json) -> InputResponse

    InputResponse::from_json

    fn InputResponse::from_json(value : Json) -> InputResponse

    InputResponse::map_from_json

    fn InputResponse::map_from_json(value : Json) -> Map[String, InputResponse] raise McpError

    ListParams

    pub struct ListParams {
    cursor : String?
    } derive(Eq,
    Debug
    )

    Parameters for pagination-supporting list requests (tools/list, resources/list, etc.).

    ListParams::ListParams

    fn ListParams::ListParams(cursor? : String) -> ListParams

    ListParams::from_json

    ListPromptsResult

    pub struct ListPromptsResult {
    prompts : Array[Prompt]
    next_cursor : String?
    cache_policy : CachePolicy
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    Canonical decoded result of prompts/list.

    ListPromptsResult::from_json

    ListResourceTemplatesResult

    pub struct ListResourceTemplatesResult {
    resource_templates : Array[ResourceTemplate]
    next_cursor : String?
    cache_policy : CachePolicy
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    ListResourcesResult

    pub struct ListResourcesResult {
    resources : Array[Resource]
    next_cursor : String?
    cache_policy : CachePolicy
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    Canonical decoded result of resources/list.

    ListResourcesResult::from_json

    ListToolsResult

    pub struct ListToolsResult {
    tools : Array[Tool]
    next_cursor : String?
    cache_policy : CachePolicy
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    Canonical decoded result of tools/list.

    ListToolsResult::from_json

    LoggingCapability

    pub struct LoggingCapability {
    } derive(Eq,
    Debug
    )

    Logging capability declared by an MCP server.

    LoggingCapability::LoggingCapability

    fn LoggingCapability::LoggingCapability() -> LoggingCapability

    LoggingCapability::from_json

    LoggingLevel

    pub(all) enum LoggingLevel {
    Debug
    Info
    Notice
    Warning
    Error
    Critical
    Alert
    Emergency
    } derive(Eq,
    Debug
    )

    Deprecated logging level retained for wire compatibility with MCP 2026-07-28. New integrations should not expose connection-wide logging APIs.

    LoggingLevel::from_json

    LoggingLevel::to_string

    fn LoggingLevel::to_string(self : LoggingLevel) -> String

    LoggingMessageNotification

    pub struct LoggingMessageNotification {
    params : LoggingMessageNotificationParams
    } derive(Eq,
    Debug
    )

    Deprecated request-scoped log notification.

    LoggingMessageNotification::LoggingMessageNotification

    fn LoggingMessageNotification::LoggingMessageNotification(level~ : LoggingLevel, data~ : Json, logger? : String) -> LoggingMessageNotification

    LoggingMessageNotification::to_json

    LoggingMessageNotificationParams

    pub struct LoggingMessageNotificationParams {
    level : LoggingLevel
    data : Json
    logger : String?
    } derive(Eq,
    Debug
    )

    Parameters for notifications/message (logging).

    LoggingMessageNotificationParams::LoggingMessageNotificationParams

    fn LoggingMessageNotificationParams::LoggingMessageNotificationParams(level~ : LoggingLevel, data~ : Json, logger? : String) -> LoggingMessageNotificationParams

    LoggingMessageNotificationParams::from_json

    ProgressNotification

    pub struct ProgressNotification {
    params : ProgressNotificationParams
    } derive(Eq,
    Debug
    )

    Notification reporting progress on a long-running request.

    ProgressNotification::ProgressNotification

    fn ProgressNotification::ProgressNotification(progress_token~ : Json, progress~ : Double, total? : Double, message? : String) -> ProgressNotification raise McpError

    ProgressNotification::to_json

    ProgressNotificationParams

    pub struct ProgressNotificationParams {
    progress_token : Json
    progress : Double
    total : Double?
    message : String?
    } derive(Eq,
    Debug
    )

    Parameters for notifications/progress.

    ProgressNotificationParams::ProgressNotificationParams

    fn ProgressNotificationParams::ProgressNotificationParams(progress_token~ : Json, progress~ : Double, total? : Double, message? : String) -> ProgressNotificationParams raise McpError

    ProgressNotificationParams::from_json

    Prompt

    pub struct Prompt {
    name : String
    title : String?
    description : String?
    arguments : Array[PromptArgument]
    icons : Array[Icon]
    meta : Map[String, Json]
    } derive(Eq,
    Debug
    )

    impl ToJson for Prompt

    Prompt::Prompt

    fn Prompt::Prompt(name~ : String, title? : String, description? : String, arguments? : Array[PromptArgument], icons? : Array[Icon], meta? : Map[String, Json]) -> Prompt raise McpError

    Prompt::from_json

    fn Prompt::from_json(value : Json, path? :
    JsonPath
    ) -> Prompt raise McpError

    PromptArgument

    pub struct PromptArgument {
    name : String
    title : String?
    description : String?
    required : Bool
    } derive(Eq,
    Debug
    )

    PromptArgument::PromptArgument

    fn PromptArgument::PromptArgument(name~ : String, title? : String, description? : String, required? : Bool) -> PromptArgument

    Construct a prompt argument descriptor.

    PromptArgument::from_json

    PromptMessage

    pub struct PromptMessage {
    role : Role
    content : Content
    } derive(Eq,
    Debug
    )

    PromptMessage::PromptMessage

    fn PromptMessage::PromptMessage(role~ : Role, content~ : Content) -> PromptMessage

    PromptMessage::assistant

    fn PromptMessage::assistant(text : String) -> PromptMessage

    PromptMessage::from_json

    PromptMessage::user

    fn PromptMessage::user(text : String) -> PromptMessage

    PromptsCapability

    pub struct PromptsCapability {
    list_changed : Bool?
    } derive(Eq,
    Debug
    )

    Prompts capability declared by an MCP server.

    PromptsCapability::PromptsCapability

    fn PromptsCapability::PromptsCapability(list_changed? : Bool) -> PromptsCapability

    PromptsCapability::from_json

    PromptsListChangedNotification

    pub struct PromptsListChangedNotification {
    params : SubscriptionNotificationParams
    } derive(Eq,
    Debug
    )

    Notification indicating available prompts have changed.

    PromptsListChangedNotification::PromptsListChangedNotification

    PromptsListChangedNotification::to_json

    ReadResourceParams

    pub struct ReadResourceParams {
    uri : String
    } derive(Eq,
    Debug
    )

    Parameters for resources/read.

    ReadResourceParams::ReadResourceParams

    fn ReadResourceParams::ReadResourceParams(uri~ : String) -> ReadResourceParams raise McpError

    ReadResourceParams::from_json

    ReadResourceResult

    pub struct ReadResourceResult {
    contents : Array[ResourceContent]
    cache_policy : CachePolicy?
    meta : ResultMeta?
    } derive(Eq,
    Debug
    )

    ReadResourceResult::ReadResourceResult

    fn ReadResourceResult::ReadResourceResult(contents~ : Array[ResourceContent], cache_policy? : CachePolicy, meta? : ResultMeta) -> ReadResourceResult

    Construct a resource read result with typed contents and caching advice.

    ReadResourceResult::from_json

    ReadResourceResult::text

    fn ReadResourceResult::text(uri~ : String, text~ : String, mime_type? : String) -> ReadResourceResult

    Construct a single text resource read result.

    RequestContext

    pub struct RequestContext {
    request_id : Json
    method_name : String
    meta : RequestMeta
    input_responses : Map[String, InputResponse]?
    request_state : String?
    transport_meta : Json?
    hooks : RequestHooks
    }

    Request-scoped protocol data passed to application handlers.

    RequestContext::RequestContext

    fn RequestContext::RequestContext(request_id~ : Json, method_name~ : String, meta~ : RequestMeta, input_responses? : Map[String, InputResponse], request_state? : String, hooks? : RequestHooks) -> RequestContext raise McpError

    RequestContext::is_cancelled

    fn RequestContext::is_cancelled(self : RequestContext) -> Bool

    RequestContext::report_progress

    async fn RequestContext::report_progress(self : RequestContext, progress~ : Double, total? : Double, message? : String) -> Unit raise McpError

    Emit request-scoped progress using the token supplied by the client.

    RequestHooks

    pub struct RequestHooks {
    // private fields
    }

    Transport-provided request hooks. Built-in defaults are inert, while streaming adapters can emit progress and expose cancellation without storing connection state on Server.

    RequestHooks::RequestHooks

    fn RequestHooks::RequestHooks(emit_notification? : async (Json) -> Unit raise McpError, is_cancelled? : () -> Bool, transport_meta? : Json) -> RequestHooks

    RequestMeta

    pub struct RequestMeta {
    protocol_version : String
    client_info : Implementation?
    client_capabilities : ClientCapabilities
    progress_token : Json?
    log_level : LoggingLevel?
    extra : Map[String, Json]
    } derive(Eq,
    Debug
    )

    Metadata required on every MCP 2026-07-28 request.

    RequestMeta::RequestMeta

    fn RequestMeta::RequestMeta(protocol_version? : String, client_info? : Implementation, client_capabilities? : ClientCapabilities, progress_token? : Json, log_level? : LoggingLevel, extra? : Map[String, Json]) -> RequestMeta raise McpError

    RequestMeta::from_json

    Decode the request _meta object at the MCP protocol boundary.

    RequestOptions

    pub struct RequestOptions {
    progress_token : Json?
    log_level : LoggingLevel?
    input_responses : Map[String, InputResponse]?
    request_state : String?
    meta : Map[String, Json]
    } derive(Eq,
    Debug
    )

    Per-call overrides and MRTR retry data used by request builders.

    RequestOptions::RequestOptions

    fn RequestOptions::RequestOptions(progress_token? : Json, log_level? : LoggingLevel, input_responses? : Map[String, InputResponse], request_state? : String, meta? : Map[String, Json]) -> RequestOptions

    RequestOptions::request_meta

    fn RequestOptions::request_meta(self : RequestOptions, client_capabilities~ : ClientCapabilities, client_info? : Implementation, protocol_version? : String) -> RequestMeta raise McpError

    RequestOptions::request_params

    fn RequestOptions::request_params(self : RequestOptions, params : Map[String, Json], client_capabilities~ : ClientCapabilities, client_info? : Implementation, protocol_version? : String) -> Json raise McpError

    Add common metadata and MRTR retry fields to method-specific parameters.

    Resource

    pub struct Resource {
    uri : String
    name : String
    title : String?
    description : String?
    mime_type : String?
    icons : Array[Icon]
    annotations : Annotations?
    size : Int64?
    meta : Map[String, Json]
    } derive(Eq,
    Debug
    )

    Resource descriptor returned by resources/list.

    size, when known, is the raw resource byte length before base64 encoding or tokenization.
    impl ToJson for Resource

    Resource::Resource

    fn Resource::Resource(uri~ : String, name~ : String, title? : String, description? : String, mime_type? : String, icons? : Array[Icon], annotations? : Annotations, size? : Int64, meta? : Map[String, Json]) -> Resource raise McpError

    Construct a resource descriptor.

    Resource::from_json

    fn Resource::from_json(value : Json, path? :
    JsonPath
    ) -> Resource raise McpError

    Resource::text

    fn Resource::text(uri~ : String, name~ : String, title? : String, description? : String, mime_type? : String, annotations? : Annotations, size? : Int64, meta? : Map[String, Json]) -> Resource raise McpError

    Construct a text resource descriptor.

    ResourceContent

    pub(all) enum ResourceContent {
    ResourceText(uri~ : String, text~ : String, mime_type~ : String?, meta~ : Json?)
    ResourceBlob(uri~ : String, blob~ : String, mime_type~ : String?, meta~ : Json?)
    } derive(Eq,
    Debug
    )

    Resource contents returned by resources/read.

    ResourceContent::blob

    fn ResourceContent::blob(uri~ : String, blob~ : String, mime_type? : String, meta? : Json) -> ResourceContent

    Construct blob resource contents from base64-encoded data.

    ResourceContent::from_json

    ResourceContent::text

    fn ResourceContent::text(uri~ : String, text~ : String, mime_type? : String, meta? : Json) -> ResourceContent

    Construct text resource contents.
    pub struct ResourceLink {
    uri : String
    name : String
    title : String?
    description : String?
    mime_type : String?
    icons : Array[Icon]
    annotations : Annotations?
    size : Int64?
    meta : Json?
    } derive(Eq,
    Debug
    )

    A link to a readable resource returned as content.

    size, when known, is the raw resource byte length before base64 encoding or tokenization.
    fn ResourceLink::ResourceLink(uri~ : String, name~ : String, title? : String, description? : String, mime_type? : String, icons? : Array[Icon], annotations? : Annotations, size? : Int64, meta? : Json) -> ResourceLink raise McpError

    ResourceLink::from_json

    ResourceTemplate

    pub struct ResourceTemplate {
    uri_template : String
    name : String
    title : String?
    description : String?
    mime_type : String?
    icons : Array[Icon]
    annotations : Annotations?
    meta : Map[String, Json]
    } derive(Eq,
    Debug
    )

    Resource template descriptor returned by resources/templates/list.

    ResourceTemplate::ResourceTemplate

    fn ResourceTemplate::ResourceTemplate(uri_template~ : String, name~ : String, title? : String, description? : String, mime_type? : String, icons? : Array[Icon], annotations? : Annotations, meta? : Map[String, Json]) -> ResourceTemplate raise McpError

    Construct a resource template descriptor.

    ResourceTemplate::from_json

    ResourceUpdatedNotification

    pub struct ResourceUpdatedNotification {
    params : ResourceUpdatedNotificationParams
    } derive(Eq,
    Debug
    )

    Notification indicating a specific resource content has updated.

    ResourceUpdatedNotification::ResourceUpdatedNotification

    fn ResourceUpdatedNotification::ResourceUpdatedNotification(uri~ : String, subscription_id~ :
    RequestId
    ) -> ResourceUpdatedNotification raise McpError

    ResourceUpdatedNotification::to_json

    ResourceUpdatedNotificationParams

    pub struct ResourceUpdatedNotificationParams {
    uri : String
    subscription_id :
    RequestId

    } derive(Eq,
    Debug
    )

    Parameters for notifications/resources/updated.

    ResourceUpdatedNotificationParams::ResourceUpdatedNotificationParams

    fn ResourceUpdatedNotificationParams::ResourceUpdatedNotificationParams(uri~ : String, subscription_id~ :
    RequestId
    ) -> ResourceUpdatedNotificationParams raise McpError

    ResourceUpdatedNotificationParams::from_json

    ResourcesCapability

    pub struct ResourcesCapability {
    subscribe : Bool?
    list_changed : Bool?
    } derive(Eq,
    Debug
    )

    Resources capability declared by an MCP server.

    ResourcesCapability::ResourcesCapability

    fn ResourcesCapability::ResourcesCapability(subscribe? : Bool, list_changed? : Bool) -> ResourcesCapability

    ResourcesCapability::from_json

    ResourcesListChangedNotification

    pub struct ResourcesListChangedNotification {
    params : SubscriptionNotificationParams
    } derive(Eq,
    Debug
    )

    Notification indicating available resources have changed.

    ResourcesListChangedNotification::ResourcesListChangedNotification

    ResourcesListChangedNotification::to_json

    ResultMeta

    pub struct ResultMeta {
    server_info : Implementation?
    extra : Map[String, Json]
    } derive(Eq,
    Debug
    )

    ResultMeta::ResultMeta

    fn ResultMeta::ResultMeta(server_info? : Implementation, extra? : Map[String, Json]) -> ResultMeta raise McpError

    ResultMeta::from_json

    ResultMeta::stamp

    fn ResultMeta::stamp(self : ResultMeta, value : Json) -> Json raise McpError

    Stamp a method-specific result object with modern metadata.

    ResultMeta::stamp_complete

    fn ResultMeta::stamp_complete(self : ResultMeta, value : Json) -> Json raise McpError

    Stamp a method-specific result object with complete resultType and modern metadata.

    ResultType

    pub(all) enum ResultType {
    Complete
    InputRequired
    Extension(String)
    } derive(Eq,
    Debug
    )

    ResultType::from_json

    ResultType::to_string

    fn ResultType::to_string(self : ResultType) -> String

    Role

    pub(all) enum Role {
    User
    Assistant
    } derive(Eq,
    Debug
    )

    impl ToJson for Role

    Role::to_string

    fn Role::to_string(self : Role) -> String

    Root

    pub struct Root {
    uri : String
    name : String?
    } derive(Eq,
    Debug
    )

    impl ToJson for Root

    Root::from_json

    fn Root::from_json(value : Json, path? :
    JsonPath
    ) -> Root raise McpError

    RootsCapability

    pub struct RootsCapability {
    list_changed : Bool?
    } derive(Eq,
    Debug
    )

    Roots capability declared by an MCP client.

    RootsCapability::RootsCapability

    fn RootsCapability::RootsCapability(list_changed? : Bool) -> RootsCapability

    RootsCapability::from_json

    RootsListResult

    pub struct RootsListResult {
    roots : Array[Root]
    } derive(Eq,
    Debug
    )

    SamplingCapability

    pub struct SamplingCapability {
    } derive(Eq,
    Debug
    )

    Sampling capability declared by an MCP client.

    SamplingCapability::SamplingCapability

    fn SamplingCapability::SamplingCapability() -> SamplingCapability

    SamplingCapability::from_json

    SamplingContentBlock

    pub(all) enum SamplingContentBlock {
    Text(text~ : String)
    Image(data~ : String, mime_type~ : String)
    Audio(data~ : String, mime_type~ : String)
    ToolUse(id~ : String, name~ : String, input~ : Map[String, Json])
    ToolResult(tool_use_id~ : String, content~ : Array[Content])
    } derive(Eq,
    Debug
    )

    SamplingCreateMessageParams

    pub struct SamplingCreateMessageParams {
    messages : Array[SamplingMessage]
    max_tokens : Double
    } derive(Eq,
    Debug
    )

    SamplingCreateMessageResult

    pub struct SamplingCreateMessageResult {
    model : String
    role : Role
    content : SamplingContent
    } derive(Eq,
    Debug
    )

    SamplingMessage

    pub struct SamplingMessage {
    role : Role
    content : SamplingContent
    } derive(Eq,
    Debug
    )

    ServerCapabilities

    pub struct ServerCapabilities {
    tools : ToolsCapability?
    resources : ResourcesCapability?
    prompts : PromptsCapability?
    logging : LoggingCapability?
    completions : Bool
    extensions : Map[String, Json]
    experimental : Map[String, Json]
    extra : Map[String, Json]
    } derive(Eq,
    Debug
    )

    Capabilities declared by an MCP server.

    ServerCapabilities::ServerCapabilities

    fn ServerCapabilities::ServerCapabilities(tools? : ToolsCapability, resources? : ResourcesCapability, prompts? : PromptsCapability, logging? : LoggingCapability, completions? : Bool, extensions? : Map[String, Json], experimental? : Map[String, Json], extra? : Map[String, Json]) -> ServerCapabilities

    ServerCapabilities::empty

    ServerCapabilities::from_json

    SubscriptionFilter

    pub struct SubscriptionFilter {
    tools_list_changed : Bool
    prompts_list_changed : Bool
    resources_list_changed : Bool
    resource_subscriptions : Array[String]
    } derive(Eq,
    Debug
    )

    Notification kinds requested by a subscriptions/listen stream.

    Every field is opt-in. False booleans and an empty resource list are omitted from the wire representation.

    SubscriptionFilter::SubscriptionFilter

    fn SubscriptionFilter::SubscriptionFilter(tools_list_changed? : Bool, prompts_list_changed? : Bool, resources_list_changed? : Bool, resource_subscriptions? : Array[String]) -> SubscriptionFilter

    SubscriptionNotificationParams

    pub struct SubscriptionNotificationParams {
    subscription_id :
    RequestId

    } derive(Eq,
    Debug
    )

    Parameters for list-changed notifications carrying a subscriptionId.

    SubscriptionNotificationParams::SubscriptionNotificationParams

    SubscriptionNotificationParams::from_json

    SubscriptionsAcknowledgedNotification

    pub struct SubscriptionsAcknowledgedNotification {
    params : SubscriptionsAcknowledgedNotificationParams
    } derive(Eq,
    Debug
    )

    Notification sent by server to acknowledge active subscription stream.

    SubscriptionsAcknowledgedNotification::SubscriptionsAcknowledgedNotification

    SubscriptionsAcknowledgedNotification::to_json

    SubscriptionsAcknowledgedNotificationParams

    pub struct SubscriptionsAcknowledgedNotificationParams {
    subscription_id :
    RequestId

    notifications : SubscriptionFilter
    } derive(Eq,
    Debug
    )

    Parameters for notifications/subscriptions/acknowledged.

    SubscriptionsAcknowledgedNotificationParams::SubscriptionsAcknowledgedNotificationParams

    SubscriptionsAcknowledgedNotificationParams::from_json

    SubscriptionsListenResult

    pub struct SubscriptionsListenResult {
    } derive(Eq,
    Debug
    )

    Domain payload for a gracefully closed subscription stream.

    The dispatcher adds resultType and the result _meta, including the required io.modelcontextprotocol/subscriptionId.

    SubscriptionsListenResult::SubscriptionsListenResult

    fn SubscriptionsListenResult::SubscriptionsListenResult() -> SubscriptionsListenResult

    Construct the empty completion value for a closed subscription stream.

    Tool

    pub struct Tool {
    name : String
    title : String?
    description : String?
    input_schema : Json
    output_schema : Json?
    annotations : ToolAnnotations?
    icons : Array[Icon]
    meta : Map[String, Json]
    } derive(Eq,
    Debug
    )

    MCP tool descriptor.
    impl ToJson for Tool

    Tool::Tool

    fn Tool::Tool(name~ : String, input_schema~ : Json, title? : String, description? : String, output_schema? : Json, annotations? : ToolAnnotations, icons? : Array[Icon], meta? : Map[String, Json]) -> Tool raise McpError

    Construct a tool descriptor.

    Tool::copy

    fn Tool::copy(self : Tool) -> Tool

    Copy a tool descriptor before handing it to an adapter.

    Tool::from_json

    fn Tool::from_json(value : Json, path? :
    JsonPath
    ) -> Tool raise McpError

    ToolAnnotations

    pub struct ToolAnnotations {
    title : String?
    read_only_hint : Bool?
    destructive_hint : Bool?
    idempotent_hint : Bool?
    open_world_hint : Bool?
    } derive(Eq,
    Debug
    )

    ToolAnnotations::ToolAnnotations

    fn ToolAnnotations::ToolAnnotations(title? : String, read_only_hint? : Bool, destructive_hint? : Bool, idempotent_hint? : Bool, open_world_hint? : Bool) -> ToolAnnotations

    Construct optional tool behavior annotations.

    ToolAnnotations::from_json

    ToolsCapability

    pub struct ToolsCapability {
    list_changed : Bool?
    } derive(Eq,
    Debug
    )

    Tools capability declared by an MCP server.

    ToolsCapability::ToolsCapability

    fn ToolsCapability::ToolsCapability(list_changed? : Bool) -> ToolsCapability

    ToolsCapability::from_json

    ToolsListChangedNotification

    pub struct ToolsListChangedNotification {
    params : SubscriptionNotificationParams
    } derive(Eq,
    Debug
    )

    Notification indicating available tools have changed.

    ToolsListChangedNotification::ToolsListChangedNotification

    ToolsListChangedNotification::to_json

    PROTOCOL_VERSION

    let PROTOCOL_VERSION : String

    The Model Context Protocol version.

    decode_json

    Decode a JSON value into a domain type using @json.FromJson, mapping any JsonDecodeError into an InvalidParams protocol error.

    decode_message

    fn decode_message(message : Json) ->
    Message
    raise McpError