WASM MCP Server
About
A proof-of-concept implementation of a Model Context Protocol (MCP) server that runs in WebAssembly (WASM) within a web browser. This project demonstrates the integration of MCP tools and resources in a browser environment.
Details
- Author
- beekmarks
- GitHub stars
- 40
- Downloads
- 395
- Categories
- Other
Jump to
- Calculator tool with basic arithmetic (add, subtract, multiply, divide)
- Key-value storage with set and retrieve operations
- Persistent storage within the current browser session
- Template-based resource paths (e.g., storage://{key})
- Input validation and error handling for tools and resources
- Custom browser transport layer for MCP communication
Clone the project, install dependencies (npm install), and run the development server with Vite. Open the provided web interface to interact with the calculator (select operation, enter numbers, click "Calculate") and the storage system (enter key/value, click "Set Storage" or "Get Storage").
WASM MCP Server
A proof-of-concept implementation of a Model Context Protocol (MCP) server that runs in WebAssembly (WASM) within a web browser. This project demonstrates the integration of MCP tools and resources in a browser environment.
Features
Calculator Tool
- Performs basic arithmetic operations (addition, subtraction, multiplication, division) - Input validation and error handling - Real-time calculation resultsStorage System
- Key-value storage functionality - Set and retrieve values using string keys - Persistent storage within the browser session - Template-based resource handlingTechnical Implementation
Server Components
-server.ts: Core MCP server implementation with tool and resource definitions
- main.ts: Client-side integration and UI interaction handling
- browser-transport.ts: Custom transport layer for browser communication
Architecture
- Uses the Model Context Protocol SDK for server implementation - Implements a custom browser transport layer - Tools are registered with callback functions - Resources use template paths with parameter substitutionKey Concepts
1. Tools - Registered usingserver.tool()
- Execute via callback functions
- Schema validation using Zod
2. Resources
- Template-based paths (e.g., storage://{key})
- Accessed via readCallback
- Parameterized resource handling
Usage
Calculator
1. Select an operation (add, subtract, multiply, divide) 2. Enter two numbers 3. Click "Calculate" to see the result 4. Error handling for invalid inputs and division by zeroStorage
1. Enter a key and value in the respective fields 2. Click "Set Storage" to store the value 3. Enter a key and click "Get Storage" to retrieve a value 4. Feedback provided for successful operations and errorsDependencies
- @modelcontextprotocol/sdk - Zod (for schema validation) - TypeScript - Vite (for development and building)Project Structure
mcp-wasm-poc/
├── src/
│ └── web/
│ ├── server.ts # MCP server implementation
│ ├── main.ts # Client-side logic
│ └── browser-transport.ts # Browser transport layer
├── index.html # Web interface
└── package.json # Project dependencies
Error Handling
- Server initialization errors - Tool execution errors - Resource access errors - Input validation - Transport layer errorsFuture Enhancements
- Additional calculator operations - Persistent storage across sessions - Enhanced UI/UX - Additional MCP tools and resources - WASM optimizationDevelopment
This is a proof-of-concept implementation demonstrating the feasibility of running an MCP server in a web browser using WebAssembly. The implementation focuses on demonstrating core MCP concepts while maintaining simplicity and clarity.Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



