mcp-server

A library for implementing mcp servers in MoonBit.

moon add peter-jerry-ye/mcp-server@0.3.5
Download zip
Version
0.3.5
License
Apache-2.0
Last updated
last year
Downloads
88

Dependencies

README

#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 Compare for LogLevel
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 raise Error) -> Unit

#
Server::list_roots

fn Server::list_roots(self : Server) -> Array[Root] raise 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

#
new

fn new(seed : Bytes) -> Server

#
prompt_argument

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

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io