注意: 此项目目前正在进行中(WIP)。功能和实现可能会有显著变化。
这是一个使用Web Workers和服务器发送事件(SSE)实现的模型上下文协议(MCP)客户端的演示。
localhost:3020运行的与MCP兼容的服务器npm install
启动开发服务器:
npm run dev
test.htmlsrc/
├── worker.ts # MCP客户端Worker实现
├── worker-test.ts # Worker测试接口
├── types.ts # 类型定义
└── App.tsx # 主React应用程序
Worker接受以下命令:
connect:与MCP服务器建立连接disconnect:关闭连接listTools:获取可用工具列表callTool:执行特定工具Worker以以下格式发送响应:
type WorkerResponse =
| {
type: "status";
status: WorkerStatus;
}
| {
type: "result";
result: ListToolsResult | CallToolResult;
}
| {
type: "error";
error: string;
details?: Record<string, unknown>;
};
构建项目:
npm run build
运行ESLint:
npm run lint