
nerding-io/mcp-sse-example 是从 https://github.com/nerding-io/mcp-sse-example. 导入的 MCP 服务器候选
概览
nerding-io/mcp-sse-example 是从 https://github.com/nerding-io/mcp-sse-example. 导入的 MCP 服务器候选
概述(AI 翻译)
一个参考实现,用于将模型上下文协议(MCP)能力集成到使用服务器发送事件(SSE)作为传输层的Web应用中。
概述
本项目演示了如何创建一个使用 SSE 传输协议与客户端通信的 MCP 服务器。它使网页应用能够访问强大的 MCP 功能,同时保持与 AI 模型的实时通信的持久连接。
主要特点:
- 实现使用服务器发送事件的MCP服务器以实现网页兼容性
- 创建可从网页客户端访问的自定义MCP工具
- 将任何兼容MCP的客户端连接到基于SSE的服务器
- 通过标准化协议扩展基于网络的AI助手
什么是MCP SSE?
模型上下文协议(MCP)支持多种传输机制,其中SSE非常适合网络应用:
- 服务器发送事件(SSE):建立单向连接的网络标准,服务器可以向客户端推送更新
- MCP over SSE:实现使用 SSE 作为传输层的 MCP 协议,使网页客户端能够与 MCP 服务器交互
本页由 AI 翻译,技术细节请以原文为准。
README
以下为原文 README 节选,完整内容请查看原文。
MCP Server-Sent Events (SSE) - Example
A reference implementation for integrating Model Context Protocol (MCP) capabilities into web applications using Server-Sent Events (SSE) as the transport layer.
Overview
This project demonstrates how to create an MCP server that communicates with clients using the SSE transport protocol. It enables web applications to access powerful MCP capabilities while maintaining a persistent connection for real-time communication with AI models.
Key features:
- Implement MCP servers using Server-Sent Events for web compatibility
- Create custom MCP tools that can be accessed from web clients
- Connect any MCP-compatible client to your SSE-based server
- Extend AI assistants with web-based capabilities through standardized protocols
What is MCP SSE?
The Model Context Protocol (MCP) supports multiple transport mechanisms, with SSE being ideal for web applications:
- Server-Sent Events (SSE): A web standard for establishing a unidirectional connection where servers can push updates to clients
- MCP over SSE: Implements the MCP protocol using SSE as the transport layer, enabling web clients to interact with MCP servers
- Real-time AI interactions: Allows continuous streaming of AI responses while maintaining tool execution capabilities
Getting Started
Prerequisites
- Node.js (v18 or higher)
- NPM or Yarn
- A Brave Search API key for the example search tool
Installation
# Clone the repository
git clone https://github.com/yourusername/mcp-sse-example.git
cd mcp-sse-example
# Install backend dependencies
cd backend
npm install
Configuration
Create a .env file in the backend directory with your API credentials:
BRAVE_API_KEY=your_api_key_here
Usage
Starting the Server
# Build and start the server
npm run build
npm run start
The MCP SSE server will be available at http://localhost:3001.
Docker Deployment
# From the project root
docker-compose up -d
How It Works
This implementation uses:
- Express.js as the web server
- SSEServerTransport from the MCP SDK to handle the SSE protocol
- McpServer to register and manage tools
The server exposes two main endpoints:
/sse- For establishing SSE connections/messages- For receiving messages from clients
Example Implementation
The core server implementation:
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
import express from "express";
const server = new McpServer({
name: "Example SSE Server",
version: "1.0.0",
});
// Register tools
server.tool("example_tool", { param: z.string() }, async ({ param }) => ({
content: [{ type: "text", text: `Processed: ${param}` }],
}));
const app = express();
let transport: SSEServerTransport;
app.get("/sse", async (req, res) => {
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →