moonbitstack/moonmcp/layers does not have a README file

    Bucket

    type Bucket

    One caller's bucket.

    Caching

    pub struct Caching {
    // private fields
    }

    Answers a call from memory when the same call was made recently (← FastMCP's CachingMiddleware).

    The key is the operation, the name and the arguments, with object keys sorted at every depth, so a client that sends the same arguments in another order still gets the stored answer. Errors and asks for client input are never stored: repeating them would hide the reason and replay a state the client has already answered.

    ttl_ms is how long an answer stays good — five minutes, the default of FastMCP's cache. capacity is how many answers are kept before the oldest goes; shared says whether one caller's answer may be handed to another, which is only safe when the answer does not depend on who asked.

    Caching::clear

    fn Caching::clear(self : Caching) -> Unit

    Forget everything.

    Caching::hits

    fn Caching::hits(self : Caching) -> Int

    How many calls were answered without asking the server.

    Caching::layer

    fn Caching::layer(self : Caching) -> Layer

    The layer this cache installs on a server.

    Caching::misses

    fn Caching::misses(self : Caching) -> Int

    How many went through.

    Caching::new

    fn Caching::new(ttl_ms? : Int, capacity? : Int, operations? : Array[Operation], shared? : Bool) -> Caching

    A cache of every call and every listing, kept for five minutes.

    Caching::size

    fn Caching::size(self : Caching) -> Int

    How many answers are held right now.

    Call

    pub(all) struct Call {
    operation : Operation
    name : String
    arguments : Map[String,
    Json
    ]
    context :
    Context

    }

    One request on its way through the chain: what it is, what it names, the arguments it carries, and the request context it will be served in.

    Call::fingerprint

    fn Call::fingerprint(self : Call) -> String

    The arguments as one string: keys sorted at every depth, so two calls that mean the same thing also spell the same thing. A cache keys on it, and a rate limiter that counts by argument does too.

    Call::new

    fn Call::new(operation~ : Operation, name~ : String, arguments? : Map[String,
    Json
    ], context~ :
    Context
    ) -> Call

    The call a request makes.

    Call::subject

    fn Call::subject(self : Call) -> String

    Who is calling, as the authorisation check named them; empty when the request carried no identity.

    Entry

    type Entry

    One stored answer and the moment it was made.

    Layer

    pub(all) struct Layer {
    name : String
    // private fields
    }

    One step of a chain (← FastMCP's middleware): a name for the logs and spans, and the function that sees every call passing through it.

    A layer may answer without going on, pass the call along with next.then(call), look at what came back, or refuse it by raising @exceptions.Mcp with the code it wants sent.

    Layer::new

    A layer made of a function.

    Layer::serve

    Serve the call through this layer alone, with next behind it.
    pub(all) struct Next {
    // private fields
    }

    The rest of the chain, as a layer is handed it.

    Next::then

    Serve the call with everything behind this point in the chain.

    Operation

    pub(all) enum Operation {
    ListTools
    ListResources
    ListTemplates
    ListPrompts
    CallTool
    ReadResource
    GetPrompt
    } derive(Eq,
    Debug
    )

    The request kinds a layer is asked about: the three that run a component, and the four that list them.

    Operation::code

    fn Operation::code(self : Operation) -> String

    The JSON-RPC method an operation answers.

    Operation::equal

    fn Operation::equal(Operation, Operation) -> Bool

    Operation::is_list

    fn Operation::is_list(self : Operation) -> Bool

    Whether the operation lists components rather than running one.

    Operation::not_equal

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

    RateLimiting

    pub struct RateLimiting {
    // private fields
    }

    A token bucket per caller (← FastMCP's RateLimitingMiddleware).

    Each caller starts with a full bucket of burst tokens, spends one per call, and gains rate tokens a second up to that ceiling. A caller with none left is refused with refused_code and told how long to wait; the bucket keeps no token for them, so a caller that keeps asking only waits longer.

    Ten a second, twenty at once, is FastMCP's default. The caller is the subject the authorisation check named, and everyone unauthenticated shares one bucket — give key to count by a header or a tool instead. clock reads seconds from any fixed origin; the default is the monotonic clock.

    RateLimiting::callers

    fn RateLimiting::callers(self : RateLimiting) -> Int

    How many callers are being counted.

    RateLimiting::layer

    fn RateLimiting::layer(self : RateLimiting) -> Layer

    The layer this limiter installs on a server.

    RateLimiting::new

    fn RateLimiting::new(rate? : Int, burst? : Int, operations? : Array[Operation], key? : (Call) -> String, clock? : () -> Double) -> RateLimiting

    A limiter of ten calls a second per caller, twenty in a burst.

    RateLimiting::refused

    fn RateLimiting::refused(self : RateLimiting) -> Int

    How many calls were refused.

    RateLimiting::reset

    fn RateLimiting::reset(self : RateLimiting) -> Unit

    Refill everyone to a full burst, as if no one had called yet.

    Span

    pub(all) struct Span {
    operation : Operation
    name : String
    duration_us : Double
    failed : Bool
    } derive(
    Debug
    )

    One served request, as the telemetry layer saw it.

    Span::to_repr

    Telemetry

    pub struct Telemetry {
    // private fields
    }

    Timing and counting for every request that passes through (← FastMCP's timing and logging middleware, kept as one record a caller can read or forward).

    The last capacity spans are kept in memory and every one is handed to sink, so a program can print them, write them to its logger, or forward them to a tracing system of its own. A span is recorded whether the request was answered or raised, so a failure is counted where it happened rather than where the client noticed.

    Telemetry::clear

    fn Telemetry::clear(self : Telemetry) -> Unit

    Forget every span and counter recorded so far.

    Telemetry::count

    fn Telemetry::count(self : Telemetry, operation : Operation) -> Int

    How many requests of operation were served.

    Telemetry::failures

    fn Telemetry::failures(self : Telemetry) -> Int

    How many of them ended in an error.

    Telemetry::layer

    fn Telemetry::layer(self : Telemetry) -> Layer

    The layer this recorder installs on a server.

    Telemetry::new

    fn Telemetry::new(capacity? : Int, sink? : (Span) -> Unit) -> Telemetry

    A recorder of the last 128 spans, keeping nothing else.

    Telemetry::spans

    fn Telemetry::spans(self : Telemetry) -> Array[Span]

    The spans kept so far, oldest first.

    Telemetry::total

    fn Telemetry::total(self : Telemetry) -> Int

    How many requests were served, all operations together.

    chain

    Serve call through layers in the order they were added, the first one outermost, and end in the middle. An empty list calls end directly.

    refused_code

    let refused_code : Int

    The JSON-RPC code a refusal carries: -32000, the first of the range JSON-RPC leaves to the server for errors of its own.