Skip to content

tinybeachthor/workers-rs-mcp

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

workers-rs-mcp

An example MCP (Model Context Protocol) server written in Rust, running on Cloudflare Workers.

The server compiles to WebAssembly and runs on Cloudflare's edge infrastructure, handling MCP JSON-RPC requests over HTTP.

How it works

HTTP routing is handled by Axum via the workers-rs SDK. MCP protocol logic is handled by the mcpserver crate.

Endpoints

Method Path Description
GET / Server name and version
GET /healthz Health check — returns OK
POST /mcp MCP JSON-RPC endpoint

Session management

  • initialize requests generate a new mcp-session-id (UUID v4) returned in the response header
  • All subsequent requests should include the mcp-session-id header

Tools

Includes one example tool:

  • echo — echoes the input message back to the caller

Getting started

Prerequisites

  • Rust with the wasm32-unknown-unknown target:
    rustup target add wasm32-unknown-unknown
  • Wrangler CLI:
    npm install -g wrangler

Local development

wrangler dev

Deploy to Cloudflare Workers

wrangler deploy

Pushing to main also deploys automatically via GitHub Actions (requires CLOUDFLARE_API_TOKEN and CLOUDFLARE_ACCOUNT_ID secrets).

Adding tools

  1. Implement the ToolHandler trait in src/lib.rs:
struct MyToolHandler;

#[async_trait]
impl ToolHandler for MyToolHandler {
    async fn call(&self, args: Value, _context: Value) -> Result<ToolResult, McpError> {
        // your logic here
        Ok(text_result("result".to_string()))
    }
}
  1. Register the tool with the MCP server:
mcp_router.handle_tool("my-tool", Arc::new(MyToolHandler));
  1. Add the tool schema to mcp/tools.json.

About

Rust MCP server template for Cloudflare workers

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages