wasmcp 0.0.1

Rust SDK for building MCP (Model Context Protocol) WebAssembly components
Documentation

wasmcp Rust SDK

SDK for building MCP (Model Context Protocol) handler components in Rust.

Installation

Add to your Cargo.toml:

[dependencies]
wasmcp = "0.0.1"

Usage

This SDK provides types and a macro to help you implement MCP handlers. Here's how to create a component:

1. Create a new component project

cargo component new my-mcp-handler --lib
cd my-mcp-handler

2. Add the MCP WIT files

Copy the WIT files from the wasmcp repository to your project's wit directory, or reference them in your Cargo.toml:

[package.metadata.component.target.dependencies]
"wasmcp:mcp" = { path = "../path/to/wasmcp/wit" }

3. Implement your handler

use wasmcp::{create_handler, json, Tool, Resource, Prompt};

fn get_tools() -> Vec<Tool> {
    vec![
        wasmcp::create_tool(
            "hello",
            "Says hello",
            json!({
                "type": "object",
                "properties": {
                    "name": { "type": "string" }
                }
            }),
            |args| {
                let name = args["name"].as_str().unwrap_or("World");
                Ok(format!("Hello, {}!", name))
            }
        )
    ]
}

fn get_resources() -> Vec<Resource> {
    vec![]
}

fn get_prompts() -> Vec<Prompt> {
    vec![]
}

create_handler!(
    tools: get_tools,
    resources: get_resources,
    prompts: get_prompts
);

4. Build your component

cargo component build --release

Features

The SDK provides:

  • Tool, Resource, and Prompt types
  • Builder functions: create_tool(), create_resource(), create_prompt()
  • The create_handler! macro to generate component bindings
  • Convenience macros: tool!, resource!, prompt!

Example

See the examples directory for complete working examples.