Sign in

    moonbitstack/moonmcp/resources does not have a README file

    ContentPayload

    pub(all) enum ContentPayload {
    Text(String)
    Blob(Bytes)
    } derive(Eq,
    Debug
    )

    The payload of a resource content item: inline text or raw bytes.

    ContentPayload::equal

    ContentPayload::not_equal

    fn ContentPayload::not_equal(x : ContentPayload, y : ContentPayload) -> Bool

    RawResourceValue

    pub(all) enum RawResourceValue {
    Text(String)
    Blob(Bytes)
    Ready(ResourceResult)
    }

    What a resource read function may return: text, bytes or a full result.

    Resource

    A registered resource.

    Resource::binary

    fn Resource::binary(uri : String, data~ : Bytes, name? : String, version? : String, title? : String, description? : String, icons? : Array[
    Icon
    ], mime_type? : String, tags? :
    Set
    [String], meta? : Map[String, Json], annotations? :
    Annotations
    ) -> Resource

    A resource backed by inline bytes.

    Resource::convert_result

    fn Resource::convert_result(self : Resource, raw_value : RawResourceValue) -> ResourceResult

    Convert a raw result to a ResourceResult, forwarding this resource's declared MIME type and component metadata to each content item.

    Resource::from_function

    fn Resource::from_function(uri : String, read_fn~ : async () -> RawResourceValue raise
    FastMCPError
    , name? : String, version? : String, title? : String, description? : String, icons? : Array[
    Icon
    ], mime_type? : String, tags? :
    Set
    [String], meta? : Map[String, Json], annotations? :
    Annotations
    ) -> Resource

    A resource backed by a closure computing its value on read.

    Resource::get_meta

    fn Resource::get_meta(self : Resource) -> Map[String, Json]

    Resource::identifier

    fn Resource::identifier(self : Resource) -> String

    Resource::key

    fn Resource::key(self : Resource) -> String

    Resource::new

    fn Resource::new(uri : String, read_fn~ : async () -> RawResourceValue raise
    FastMCPError
    , name? : String, version? : String, title? : String, description? : String, icons? : Array[
    Icon
    ], mime_type? : String, tags? :
    Set
    [String], meta? : Map[String, Json], annotations? :
    Annotations
    ) -> Resource

    Register a resource at uri. The name defaults to the URI when absent.

    Resource::read

    Read the resource content.

    Resource::read_result

    Server entry point for resource reads.

    Resource::text

    fn Resource::text(uri : String, text~ : String, name? : String, version? : String, title? : String, description? : String, icons? : Array[
    Icon
    ], mime_type? : String, tags? :
    Set
    [String], meta? : Map[String, Json], annotations? :
    Annotations
    ) -> Resource

    A resource backed by inline text.

    Resource::to_mcp_resource

    Convert the resource to its wire representation.

    ResourceContent

    pub(all) struct ResourceContent {
    content : ContentPayload
    mime_type : String?
    meta : Map[String, Json]?
    } derive(Eq,
    Debug
    )

    A single resource content item with optional MIME type and metadata.

    ResourceContent::equal

    ResourceContent::new

    fn ResourceContent::new(content : ContentPayload, mime_type? : String, meta? : Map[String, Json]) -> ResourceContent

    Create a resource content item, defaulting the MIME type by payload: text/plain for text, application/octet-stream for bytes.

    ResourceContent::not_equal

    fn ResourceContent::not_equal(x : ResourceContent, y : ResourceContent) -> Bool

    ResourceContent::to_mcp_resource_contents

    Convert to the wire resource contents type; bytes are base64-encoded.

    ResourceResult

    pub(all) struct ResourceResult {
    contents : Array[ResourceContent]
    meta : Map[String, Json]?
    input_required :
    InputRequiredResult
    ?
    } derive(Eq,
    Debug
    )

    The canonical result of a resource read.

    ResourceResult::equal

    ResourceResult::input_required

    Wrap a client-input ask (SEP-2322) as an ordinary resource result.

    ResourceResult::is_input_required

    fn ResourceResult::is_input_required(self : ResourceResult) -> Bool

    Whether this result carries a client-input ask (SEP-2322).

    ResourceResult::new

    fn ResourceResult::new(contents : Array[ResourceContent], meta? : Map[String, Json]) -> ResourceResult

    Create a resource result from content items.

    ResourceResult::not_equal

    fn ResourceResult::not_equal(x : ResourceResult, y : ResourceResult) -> Bool

    ResourceResult::to_mcp_result

    Convert to the wire read-resource result.

    ResourceSecurity

    pub(all) struct ResourceSecurity {
    reject_path_traversal : Bool
    reject_absolute_paths : Bool
    reject_null_bytes : Bool
    exempt_params :
    Set
    [String]
    } derive(Eq,
    Debug
    )

    Security policy applied to extracted resource template parameters.

    The checks run after a URI has matched a template and its parameter values have been extracted and percent-decoded; they catch path-traversal and absolute-path injection regardless of how the value was encoded in the URI.

    ResourceSecurity::default

    Secure-by-default policy: traversal, absolute paths and null bytes all rejected.

    ResourceSecurity::equal

    ResourceSecurity::not_equal

    fn ResourceSecurity::not_equal(x : ResourceSecurity, y : ResourceSecurity) -> Bool

    ResourceSecurity::validate

    fn ResourceSecurity::validate(self : ResourceSecurity, params : Map[String, Json]) -> String?

    Check all parameter values against the policy. String values (and lists of strings, from wildcard parameters) are screened; non-string values are ignored. Returns the name of the first failing parameter, if any.

    ResourceSecuritySetting

    pub(all) enum ResourceSecuritySetting {
    Inherit
    Explicit(ResourceSecurity)
    Disabled
    } derive(Eq,
    Debug
    )

    Per-component security setting: inherit the server-wide default, apply an explicit policy, or disable screening.

    ResourceSecuritySetting::equal

    ResourceSecuritySetting::not_equal

    ResourceTemplate

    pub(all) struct ResourceTemplate {
    component :
    ComponentBase

    uri_template : String
    mime_type : String
    parameters : Json
    annotations :
    Annotations
    ?
    security : ResourceSecuritySetting
    list_query_params :
    Set
    [String]
    segments : Array[TemplateSegment]
    read_fn : async (Map[String, Json]) -> RawResourceValue raise
    FastMCPError

    }

    A template for dynamically creating resources.

    ResourceTemplate::convert_result

    fn ResourceTemplate::convert_result(self : ResourceTemplate, raw_value : RawResourceValue) -> ResourceResult

    Convert a raw result to a ResourceResult, forwarding the template's declared MIME type so reads match what it advertises in listings.

    ResourceTemplate::create_resource

    fn ResourceTemplate::create_resource(self : ResourceTemplate, uri : String, params : Map[String, Json]) -> Resource

    Create a concrete resource from the template for the given parameters.

    ResourceTemplate::from_mcp_template

    Create a template from a raw wire template, for remote servers whose original function is lost.

    ResourceTemplate::get_meta

    fn ResourceTemplate::get_meta(self : ResourceTemplate) -> Map[String, Json]

    ResourceTemplate::identifier

    fn ResourceTemplate::identifier(self : ResourceTemplate) -> String

    ResourceTemplate::key

    fn ResourceTemplate::key(self : ResourceTemplate) -> String

    ResourceTemplate::matches

    Check if a URI matches this template and extract its parameters, screening extracted values against the effective security policy.

    ResourceTemplate::new

    fn ResourceTemplate::new(uri_template : String, parameters~ : Json, read_fn~ : async (Map[String, Json]) -> RawResourceValue raise
    FastMCPError
    , name? : String, version? : String, title? : String, description? : String, icons? : Array[
    Icon
    ], mime_type? : String, tags? :
    Set
    [String], meta? : Map[String, Json], annotations? :
    Annotations
    , security? : ResourceSecuritySetting, list_query_params? :
    Set
    [String]) -> ResourceTemplate raise
    FastMCPError

    Register a resource template; read_fn receives the parameters matched from the request URI.

    ResourceTemplate::read

    Read the resource content with the matched parameters.

    ResourceTemplate::read_result

    async fn ResourceTemplate::read_result(self : ResourceTemplate, _uri : String, params : Map[String, Json]) -> ResourceResult raise
    FastMCPError

    Server entry point for template reads.

    ResourceTemplate::resolve_security

    fn ResourceTemplate::resolve_security(self : ResourceTemplate, server_default : ResourceSecurity?) -> ResourceSecurity?

    Resolve the effective security policy for this template.

    ResourceTemplate::to_mcp_template

    Convert the template to its wire representation.

    TemplateSegment

    pub(all) enum TemplateSegment {
    Literal(Array[Char])
    PathVar(name~ : String, wildcard~ : Bool)
    }

    One parsed chunk of a template's path portion.

    contains_path_traversal

    fn contains_path_traversal(value : String) -> Bool

    Whether value contains .. as a path component, considering both separators. Dots inside a single segment are not traversal.

    convert_raw_to_resource_result

    fn convert_raw_to_resource_result(raw_value : RawResourceValue, mime_type? : String, meta? : Map[String, Json]) -> ResourceResult

    Wrap a resource function's return value in a ResourceResult.

    Shared by Resource and ResourceTemplate so both honour the MIME type the component declares in listings: a component that advertises text/csv must not serve text/plain on read.

    encode_literal

    fn encode_literal(text : String) -> String

    Percent-encode literal template text per RFC 6570 section 3.1.

    Existing %XX triplets pass through so an already-encoded literal is not encoded twice; everything else keeps reserved and unreserved characters and encodes the rest.

    expand_uri_template

    fn expand_uri_template(uri_template : String, params : Map[String, Json]) -> String

    Expand a URI template with parameters — the inverse of match_uri_template. Params use underscored keys but templates may use hyphens, so both spellings are tried.

    extract_exploded_query_params

    fn extract_exploded_query_params(uri_template : String) -> Array[String]

    Extract query parameter names declared with the explode modifier: {?tags*} marks tags as repeatable.

    extract_query_params

    fn extract_query_params(uri_template : String) -> Array[String]

    Extract query parameter names from RFC 6570 {?param1,param2} syntax.

    The explode modifier is stripped, so {?tags*} yields tags.

    forward_uri

    fn forward_uri(uri_template : String, params : Map[String, Json], uri : String) -> String

    Build the URI a forwarding layer (mount or proxy) sends to the server behind it: the path is expanded from the template, but the query string is carried over from the incoming URI byte for byte.

    is_absolute_path

    fn is_absolute_path(value : String) -> Bool

    Whether value looks like an absolute filesystem path: rooted at / or \\, UNC-prefixed, or a Windows drive letter path.

    match_uri_template

    fn match_uri_template(uri : String, uri_template : String, list_params? : Array[String], segments? : Array[TemplateSegment]) -> Map[String, Json]?

    Match a URI against a template and extract both path and query parameters, percent-decoded.

    list_params names non-exploded query parameters that hold lists; their first value is comma-split per RFC 6570 section 3.2.8. Pass pre-parsed segments when the caller already holds them.

    parse_template

    fn parse_template(uri_template : String) -> Array[TemplateSegment]

    Parse the path portion of a URI template into literal and variable segments; query blocks are dropped for path matching.

    parse_template_params

    fn parse_template_params(uri_template : String) ->
    Set
    [String]

    All parameter names a template declares, hyphens normalised to underscores, path and query parameters combined.

    pct_encode

    fn pct_encode(text : String, safe? : String) -> String

    Percent-encode text, keeping unreserved characters plus safe.

    resolve_security

    fn resolve_security(setting : ResourceSecuritySetting, server_default : ResourceSecurity?) -> ResourceSecurity?

    Resolve the effective policy for a component.