Sign in

    mcp-server

    A library for implementing mcp servers in MoonBit.

    Download zip
    Version
    0.3.1
    License
    Apache-2.0
    Last updated
    last year
    Downloads
    126

    #MCP Server SDK

    A WIP MoonBit implementation to support Model Context Protocol.

    Supported backends:

    • Wasm's Component Model
    • Native backend

    and more (as long as an implementation exists for peter-jerry-ye/async/stream).

    The user can use this to develop a running MCP server, providing more functionality to their AI models.

    #Currently Supported Features

    Version:
    • 2024-11-05

    Transport:
    • Stdio

    Provide server capabilities:
    • Tools
    • Prompts

    Call client capabilities (if provided):
    • List roots

    #Example

    See ./example for a simple weather MCP server in Wasm, and ./example-c for a simple MCP server in native backend.

    #TODO

    • Add documentation
    • Add tests
    • Support more features
    • Better error handling and better UX

    Content

    pub(all) enum Content {
    Text(String)
    Image(String, String)
    Resource(String, String, String)
    }

    LogLevel

    pub(all) enum LogLevel {
    Debug
    Info
    Notice
    Warning
    Error
    Critical
    Alert
    Emergency
    }

    RFC 5424
    impl Eq for LogLevel
    impl Show for LogLevel

    PromptArgument

    type PromptArgument

    PromptMessage

    pub(all) struct PromptMessage {
    role : Role
    message : Content
    }

    Response

    pub(all) struct Response {
    isError : Bool
    payload : Array[Content]
    }

    Role

    pub(all) enum Role {
    User
    Assistant
    }

    Root

    pub struct Root {
    uri : String
    name : String?
    }

    impl Eq for Root
    impl Show for Root

    Server

    type Server

    Server::add_prompt

    fn Server::add_prompt(self : Server, name~ : String, description~ : String, arguments~ : Array[PromptArgument] = .., cb~ : (Map[String, Json]) -> Array[PromptMessage]) -> Unit

    Server::add_tool

    fn Server::add_tool(self : Server, name~ : String, description~ : String, inputSchema~ :
    T
    , cb~ : (Json, Server) -> Response) -> Unit

    Server::list_roots

    fn Server::list_roots(self : Server) -> Array[Root]!Error

    Server::log

    fn Server::log(self : Server, message : Json, level~ : LogLevel = ..) -> Unit

    Server::remove_prompt

    fn Server::remove_prompt(self : Server, name : String) -> Unit

    Server::remove_tool

    fn Server::remove_tool(self : Server, name : String) -> Unit

    add_prompt

    fn add_prompt(self : Server, name~ : String, description~ : String, arguments~ : Array[PromptArgument] = .., cb~ : (Map[String, Json]) -> Array[PromptMessage]) -> Unit

    add_tool

    fn add_tool(self : Server, name~ : String, description~ : String, inputSchema~ :
    T
    , cb~ : (Json, Server) -> Response) -> Unit

    list_roots

    fn list_roots(self : Server) -> Array[Root]!Error

    log

    fn log(self : Server, message : Json, level~ : LogLevel = ..) -> Unit

    new

    fn new(seed : Bytes) -> Server

    prompt_argument

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

    remove_prompt

    fn remove_prompt(self : Server, name : String) -> Unit

    remove_tool

    fn remove_tool(self : Server, name : String) -> Unit

    Powered by MoonBit

    Site sourceReport issuePackagesBuild queueSkillsStatistics

    © 2026 mooncakes.io