Sign in

    moonbitstack/moonmcp/server does not have a README file

    Scope

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

    Who may keep a cached list result: any intermediary, or only caches inside the same authorisation context (the cacheScope of a cacheable result).

    Scope::equal

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

    Scope::not_equal

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

    Scope::to_repr

    Server

    pub struct Server {
    info :
    Implementation

    instructions : String?
    ttl_ms : Int
    scope : Scope
    // private fields
    }

    An MCP server (← FastMCP's FastMCP): the tools, resources, resource templates and prompts it offers, and who it says it is.

    It speaks both eras of the protocol. A request carrying its protocol version in _meta is served statelessly under the 2026-07-28 revision; an initialize request opens the handshake of the revisions before it. The same server is reached over Streamable HTTP with to_asgi, over stdio with run_stdio, or by any transport of your own through handle.

    ttl_ms and scope are the caching hints every list result carries under the 2026-07-28 revision. The presets say "stale at once" and "this caller only", the cautious end of both, since a server that changes what it lists per caller would otherwise leak one caller's list to the next.

    Server::add_prompt

    fn Server::add_prompt(self : Server, prompt :
    Prompt
    ) -> Unit

    Offer prompt. A second prompt under the same name replaces the first.

    Server::add_resource

    fn Server::add_resource(self : Server, resource :
    Resource
    ) -> Unit

    Offer resource at its URI. A second resource at the same URI replaces the first.

    Server::add_template

    Offer template; a URI no fixed resource answers is matched against the templates in the order they were added.

    Server::add_tool

    fn Server::add_tool(self : Server, tool :
    Tool
    ) -> Unit

    Offer tool. Its input schema is compiled here, so a call is checked against it before the tool runs. A schema that does not compile is a mistake in the program, not in a request, so it aborts now rather than failing the first call. A second tool under the same name replaces the first.

    Server::handle

    async fn Server::handle(self : Server, message : Json) -> Json?

    Answer one JSON-RPC message, the way every transport does (← the low-level server's message loop). None is the answer to a notification. A message that is not JSON-RPC at all is answered with the error JSON-RPC prescribes, under a null id.

    Server::new

    fn Server::new(name : String, version? : String, title? : String, instructions? : String, ttl_ms? : Int, scope? : Scope) -> Server

    Server::prompt

    fn Server::prompt(self : Server, name : String, render : async (Map[String, Json]) -> String, title? : String, description? : String, arguments? : Array[
    PromptArgument
    ]) -> Unit

    Offer a prompt rendered as one user message (← @mcp.prompt).

    Server::resource

    fn Server::resource(self : Server, uri : String, read : async () -> String, name? : String, title? : String, description? : String, mime_type? : String) -> Unit

    Offer a resource read as text (← @mcp.resource(uri)).

    Server::run_stdio

    async fn Server::run_stdio(self : Server) -> Unit

    Serve over the process's standard input and output (← FastMCP's run(transport="stdio")): one message per line each way, until standard input closes. Anything else the program prints belongs on standard error, since standard output carries nothing but messages.

    Server::serve_lines

    async fn Server::serve_lines(self : Server, read : async () -> String?, write : async (String) -> Unit) -> Unit

    Serve newline-delimited JSON-RPC: read a line with read until it gives None, answer it, and write the reply as one line (← the stdio transport, over any pair of streams). A line that is not JSON is answered with a parse error; a blank one is skipped.

    Requests are answered one at a time, in the order they arrive.

    Server::template

    fn Server::template(self : Server, uri_template : String, read : async (Map[String, Json]) -> String, name? : String, title? : String, description? : String, mime_type? : String) -> Unit

    Offer the resources an RFC 6570 template names, read as text with the parameters the URI matched (← @mcp.resource("users://{id}")). A template that does not parse aborts at registration.

    Server::to_asgi

    fn Server::to_asgi(self : Server, path? : String, origins? : Array[String]) -> (async (
    Scope
    , async () ->
    Event
    , async (
    Event
    ) -> Unit) -> Unit)

    The server as an ASGI application serving the MCP endpoint at path (← FastMCP's http_app). Run it with mooncat, or mount it beside a moonapi app.

    Every message is its own POST, answered with one JSON object, or 202 for a notification. Sessions, the GET stream and DELETE belong to the revisions before 2026-07-28 and are optional there; this server keeps no session, so GET and DELETE answer 405.

    A request whose Origin header names another site is refused with 403, as the transport requires against DNS rebinding. An origin passes when its host is the request's own Host, a loopback address, or one listed in origins.

    Server::tool

    fn Server::tool(self : Server, name : String, run : async (Map[String, Json]) -> Json, input_schema? : Json, title? : String, description? : String, output_schema? : Json, annotations? :
    ToolAnnotations
    ) -> Unit

    Offer a tool whose handler returns any JSON value (← @mcp.tool). An object becomes structured content as well as text; anything else becomes text. An error the handler raises becomes a result marked isError, which the model reads and can correct itself from. A name the protocol does not allow aborts at registration.

    decode

    The argument name of a call, read as T; the code #mcp.tool generates calls this for each required parameter. A string read where something else is wanted is read again as JSON, which is how the {id} of a resource template, always text, reaches an Int parameter.

    decode_option

    fn[T :
    FromJson
    ] decode_option(args : Map[String, Json], name : String) -> T? raise
    JsonDecodeError

    The argument name of a call when it may be left out: None when it is missing or null, else the value read as decode reads it. The code #mcp.tool generates calls this for optional parameters.