MCP SSE 服务器和客户端示例
该存储库包含基于 SSE(服务器发送事件)的 MCP(模型上下文协议)服务器和客户端的完整示例实现。
概述
模型上下文协议 (MCP) 是一种专为人工智能系统设计的通信协议。本实现演示了如何创建一个使用服务器发送事件 (SSE) 与客户端进行实时通信的 MCP 服务器。
特征
基于 SSE 的 MCP 服务器:使用 Express.js 和 MCP SDK 的 SSEServerTransport 实现服务器
交互式 MCP 客户端:提供连接到 SSE 服务器的客户端实现
工具实现:包括示例工具(加法、乘法)和适当的描述
动态资源:使用 URI 模式演示动态资源模板
调试支持:包括详细的日志记录和调试配置
成分
server.js
- 使用 StdioServerTransport 的基本 MCP 服务器sse-server.js
- 使用 SSEServerTransport 和 Express.js 的 MCP 服务器client.js
- 基本服务器的客户端sse-client.js
- SSE 服务器的客户端
入门
安装依赖项:
启动 SSE 服务器:
在另一个终端中,运行 SSE 客户端:
服务器功能
SSE 服务器提供:
加法和乘法的工具端点
具有模板支持的动态问候资源
为多个客户端提供适当的会话管理
用于调试的详细日志记录
客户端功能
SSE 客户端演示:
连接到 SSE 服务器
列出可用的工具和资源
调用带参数的工具
读取具有动态参数的资源
URI 模板
服务器演示了如何向客户端公开 URI 模板,让客户端了解如何动态构建资源 URI:
执照
麻省理工学院
Related MCP Servers
- -securityAlicense-qualityMCP Server simplifies the implementation of the Model Context Protocol by providing a user-friendly API to create custom tools and manage server workflows efficiently.Last updated -14MIT License
- -securityAlicense-qualityThis server implements the Model Context Protocol (MCP) to handle asynchronous tasks with real-time status tracking, robust error handling, and automatic resource management.Last updated -1MIT License
- AsecurityFlicenseAqualityA specialized server that helps users create new Model Context Protocol (MCP) servers by providing tools and templates for scaffolding projects with various capabilities.Last updated -81645
- AsecurityFlicenseAqualityA Model Context Protocol (MCP) server that interacts with system APIs, allowing users to check connections, search employees, register breakfast, and update chemical information by shifts.Last updated -219