Skip to main content
Glama

WASM MCP 服务器

一个概念验证实现,用于在 Web 浏览器中以 WebAssembly (WASM) 运行的模型上下文协议 (MCP) 服务器。该项目演示了如何在浏览器环境中集成 MCP 工具和资源。

特征

计算器工具

  • 执行基本算术运算(加法、减法、乘法、除法)

  • 输入验证和错误处理

  • 实时计算结果

存储系统

  • 键值存储功能

  • 使用字符串键设置和检索值

  • 浏览器会话中的持久存储

  • 基于模板的资源处理

技术实现

服务器组件

  • server.ts :核心 MCP 服务器实现,包含工具和资源定义

  • main.ts :客户端集成和 UI 交互处理

  • browser-transport.ts :用于浏览器通信的自定义传输层

建筑学

  • 使用模型上下文协议 SDK 进行服务器实现

  • 实现自定义浏览器传输层

  • 工具已注册回调函数

  • 资源使用带有参数替换的模板路径

关键概念

  1. 工具

    • 使用server.tool()注册

    • 通过回调函数执行

    • 使用 Zod 进行模式验证

  2. 资源

    • 基于模板的路径(例如, storage://{key}

    • 通过readCallback访问

    • 参数化资源处理

用法

计算器

  1. 选择运算(加、减、乘、除)

  2. 输入两个数字

  3. 点击“计算”查看结果

  4. 无效输入和除以零的错误处理

贮存

  1. 在相应的字段中输入键和值

  2. 点击“设置存储”来存储值

  3. 输入密钥并单击“获取存储”以检索值

  4. 为成功操作和错误提供反馈

依赖项

  • @modelcontextprotocol/sdk

  • Zod(用于模式验证)

  • TypeScript

  • Vite(用于开发和建设)

项目结构

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

错误处理

  • 服务器初始化错误

  • 工具执行错误

  • 资源访问错误

  • 输入验证

  • 传输层错误

未来的增强功能

  • 附加计算器操作

  • 跨会话的持久存储

  • 增强的 UI/UX

  • 其他 MCP 工具和资源

  • WASM 优化

发展

这是一个概念验证实现,演示了使用 WebAssembly 在 Web 浏览器中运行 MCP 服务器的可行性。该实现侧重于演示 MCP 的核心概念,同时保持简洁明了。

-
security - not tested
-
license - not tested
-
quality - not tested

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
  • -
    security
    -
    license
    -
    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.
  • A
    security
    -
    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
    9
    13
    MIT License
  • -
    security
    -
    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 -
    76
    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