WebSocket MCP (模型上下文协议)
ws-mcp
简介
ws-mcp 是一个轻量级的桥接工具,旨在将原生的 MCP 服务转换为 WebSocket 协议。对于习惯于 Web 开发或需要将 AI 能力集成到浏览器端、远程客户端的开发者来说,它解决了 MCP 默认传输机制的局限性。简单来说,它就像一个协议转换适配器,让你的 MCP Server 能够通过网络套接字与前端应用(如 kibitz)通信,而无需复杂的本地进程管理。上手难度较低,只要熟悉基础的 Node.js 环境即可快速部署,是构建基于 Web 的 AI 代理工具链的实用补丁。
核心亮点
- 将 MCP 服务转换为 WebSocket 协议,支持远程调用
- 打破本地限制,让浏览器端应用能直接使用 MCP
- 极简配置,快速实现 AI 工具与 Web 端的互联
- 完美适配 kibitz 等基于 Web 的 MCP 客户端
完整文档
ws-mcp
使用 WebSocket 封装 MCP stdio 服务器。
用于配合 kibitz 使用。
快速上手
前置条件
安装 uv:
bash
curl -LsSf https://astral.sh/uv/install.sh | sh配置文件指定要运行哪些 MCP 服务器。
默认配置(未提供 --config 或 --command 参数)包括:
wcgw:用于通用系统操作和文件管理
fetch:用于发送 HTTP 请求
要创建配置文件:
1. 创建您的配置文件:
bash
cp sample.config.json config.jsonconfig.json 以添加或删除服务器。3. 使用
--config path/to/config.json 运行以使用新的配置文件。
运行 ws-mcp
使用默认配置文件(未提供 --config 或 --command)和端口的基本用法:
bash
uvx --refresh ws-mcp@latest10125) 上配置的服务器。
若要使用配置文件和端口:
bash
uvx --refresh ws-mcp@latest --config path/to/config --port 10125bash
# Example using fetch
uvx --refresh ws-mcp --command "uvx mcp-server-fetch" --port 3002
Example using wcgw
uvx --refresh ws-mcp --command "uvx --from wcgw@latest --python 3.12 wcgw_mcp" --port 3001
Example using Brave search
export BRAVE_API_KEY=YOUR_API_KEY_HERE
uvx --refresh ws-mcp --env BRAVE_API_KEY=$BRAVE_API_KEY --command "npx -y @modelcontextprotocol/server-brave-search" --port 3003
Or, with a .env file:
uvx --refresh ws-mcp --env-file path/to/.env --command "npx -y @modelcontextprotocol/server-brave-search" --port 3003
--command can be supplied multiple times!
Example serving multiple servers at once:
uvx --refresh ws-mcp --env-file path/to/.env --command "npx -y @modelcontextprotocol/server-brave-search" --command "uvx mcp-server-fetch" --port 3004
Servers can also be specified in a .json file following the standard MCP format
uvx --refresh ws-mcp --env-file path/to/.env --config path/to/config.json --port 3005