mcpkit-rs: WebAssembly-focused MCP SDK Fork
mcpkit-rs is a WebAssembly-focused fork of the official Rust MCP SDK. This fork extends the original implementation with WebAssembly runtime integration, allowing tools to be executed in WASM environments. It provides a complete implementation of the Model Context Protocol (MCP) for building both servers that expose capabilities to AI assistants and clients that interact with such servers.
Fork Information
This is a community fork that builds upon the official MCP Rust SDK with the following enhancements:
- WebAssembly Runtime Integration: Execute MCP tools in WASM environments using WasmEdge or other WASM runtimes
- WASM Tool Manifest Support: Define and load tools from WASM modules with manifest declarations
- Extended Transport Options: Additional transport mechanisms optimized for WASM deployment scenarios
- Full MCP Compatibility: Maintains complete compatibility with the MCP specification
For the official Rust SDK without WebAssembly extensions, please visit the original repository.
Quick Start
Server Implementation
Creating a server with tools is simple using the #[tool] macro:
use ;
use Arc;
use Mutex;
// Implement the server handler
// Run the server
async
Structured Output
Tools can return structured JSON data with schemas. Use the [Json] wrapper:
# use ;
# use JsonSchema;
# use ;
#
#
#
#
#
#
The #[tool] macro automatically generates an output schema from the CalculationResult type.
Tasks
mcpkit-rs implements the task lifecycle from SEP-1686 so long-running or asynchronous tool calls can be queued and polled safely.
- Create: set the
taskfield onCallToolRequestParamto ask the server to enqueue the tool call. The response is aCreateTaskResultthat includes the generatedtask.task_id. - Inspect: use
tasks/get(GetTaskInfoRequest) to retrieve metadata such as status, timestamps, TTL, and poll interval. - Await results: call
tasks/result(GetTaskResultRequest) to block until the task completes and receive either the finalCallToolResultpayload or a protocol error. - Cancel: call
tasks/cancel(CancelTaskRequest) to request termination of a running task.
To expose task support, enable the tasks capability when building ServerCapabilities. The #[task_handler] macro and OperationProcessor utility provide reference implementations for enqueuing, tracking, and collecting task results.
Client Implementation
Creating a client to interact with a server:
use ;
use Command;
async
For more examples, see the examples directory in the repository.
Transport Options
mcpkit-rs supports multiple transport mechanisms, each suited for different use cases:
transport-async-rw
Low-level interface for asynchronous read/write operations. This is the foundation for many other transports.
transport-io
For working directly with I/O streams (tokio::io::AsyncRead and tokio::io::AsyncWrite).
transport-child-process
Run MCP servers as child processes and communicate via standard I/O.
Example:
use TokioChildProcess;
use Command;
let transport = new?;
let service = client.serve.await?;
Access with peer interface when handling message
You can get the Peer struct from NotificationContext and RequestContext.
# use ;
# ;
Manage Multi Services
For many cases you need to manage several service in a collection, you can call into_dyn to convert services into the same type.
let service = service.into_dyn;
Feature Flags
mcpkit-rs uses feature flags to control which components are included:
client: Enable client functionalityserver: Enable server functionality and the tool systemmacros: Enable the#[tool]macro (enabled by default)- Transport-specific features:
transport-async-rw: Async read/write supporttransport-io: I/O stream supporttransport-child-process: Child process supporttransport-streamable-http-client/transport-streamable-http-server: HTTP streaming (client agnostic, seeStreamableHttpClientTransportfor details)transport-streamable-http-client-reqwest: a defaultreqwestimplementation of the streamable http client
auth: OAuth2 authentication supportschemars: JSON Schema generation (for tool definitions)
Transports
transport-io: Server stdio transporttransport-child-process: Client stdio transporttransport-streamable-http-serverstreamable http server transporttransport-streamable-http-clientstreamable http client transport
The transport type must implement the Transport trait, which allows it to send messages concurrently and receive messages sequentially.
There are 2 pairs of standard transport types:
| transport | client | server |
|---|---|---|
| std IO | TokioChildProcess |
stdio |
| streamable http | StreamableHttpClientTransport |
StreamableHttpService |
IntoTransport trait
IntoTransport is a helper trait that implicitly converts a type into a transport type.
These types automatically implement IntoTransport:
- A type that implements both
futures::Sinkandfutures::Stream, or a tuple(Tx, Rx)whereTxisfutures::SinkandRxisfutures::Stream. - A type that implements both
tokio::io::AsyncReadandtokio::io::AsyncWrite, or a tuple(R, W)whereRistokio::io::AsyncReadandWistokio::io::AsyncWrite. - A type that implements the
Workertrait. - A type that implements the
Transporttrait.
License
This project is licensed under the terms specified in the repository's LICENSE file.