Skip to main content
Glama

WASM MCP Server

by beekmarks

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 results

Storage System

  • Key-value storage functionality
  • Set and retrieve values using string keys
  • Persistent storage within the browser session
  • Template-based resource handling

Technical 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 substitution

Key Concepts

  1. Tools
    • Registered using server.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 zero

Storage

  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 errors

Dependencies

  • @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 errors

Future Enhancements

  • Additional calculator operations
  • Persistent storage across sessions
  • Enhanced UI/UX
  • Additional MCP tools and resources
  • WASM optimization

Development

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.

-
security - not tested
F
license - not found
-
quality - not tested

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

该服务器能够在 Web 浏览器中运行模型上下文协议,其功能包括算术运算和基于会话的键值存储。

  1. 特征
    1. 计算器工具
    2. 存储系统
  2. 技术实现
    1. 服务器组件
    2. 建筑学
    3. 关键概念
  3. 用法
    1. 计算器
    2. 贮存
  4. 依赖项
    1. 项目结构
      1. 错误处理
        1. 未来的增强功能
          1. 发展

            Related MCP Servers

            • A
              security
              F
              license
              A
              quality
              A server that provides tools for performing basic arithmetic operations (addition, subtraction, multiplication, division) via the Model Context Protocol.
              Last updated -
              4
              • Apple
            • A
              security
              F
              license
              A
              quality
              A simple Model Context Protocol server that provides basic arithmetic operations (addition, subtraction, multiplication, division) as tools that can be called by Large Language Models.
              Last updated -
              4
            • A
              security
              A
              license
              A
              quality
              A Model Context Protocol server that enables LLMs to interact with web pages, take screenshots, generate test code, scrape web pages, and execute JavaScript in a real browser environment.
              Last updated -
              29
              26
              12
              MIT License
            • -
              security
              A
              license
              -
              quality
              A simple implementation of a Model Context Protocol server that demonstrates core functionality including mathematical tools (add, subtract) and personalized greeting resources.
              Last updated -
              70
              GPL 3.0

            View all related MCP servers

            MCP directory API

            We provide all the information about MCP servers via our MCP API.

            curl -X GET 'https://glama.ai/api/mcp/v1/servers/beekmarks/mcp-wasm'

            If you have feedback or need assistance with the MCP directory API, please join our Discord server