MCP cover image
See in Github
2025-03-17

1

Github Watches

7

Github Forks

26

Github Stars

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:

  1. Express.js as the web server
  2. SSEServerTransport from the MCP SDK to handle the SSE protocol
  3. 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) => {
  transport = new SSEServerTransport("/messages", res);
  await server.connect(transport);
});

app.post("/messages", async (req, res) => {
  await transport.handlePostMessage(req, res);
});

app.listen(3001);

Compatible Clients

Many MCP clients support the SSE transport protocol, including:

Debugging

When debugging your MCP SSE implementation:

# Follow logs in real-time (for MacOS)
tail -n 20 -F ~/Library/Logs/Claude/mcp*.log

For more detailed debugging instructions, see the MCP debugging guide.

Contribution

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related Resources

相关推荐

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • Contraband Interactive
  • Emulating Dr. Jordan B. Peterson's style in providing life advice and insights.

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • rustassistant.com
  • Your go-to expert in the Rust ecosystem, specializing in precise code interpretation, up-to-date crate version checking, and in-depth source code analysis. I offer accurate, context-aware insights for all your Rust programming questions.

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • Mintplex-Labs
  • L'application tout-en-un desktop et Docker AI avec chiffon intégré, agents AI, constructeur d'agent sans code, compatibilité MCP, etc.

  • ravitemer
  • Un puissant plugin Neovim pour gérer les serveurs MCP (Protocole de contexte modèle)

  • jae-jae
  • MCP Server pour récupérer le contenu de la page Web à l'aide du navigateur sans tête du dramwright.

  • patruff
  • Pont entre les serveurs Olllama et MCP, permettant aux LLM locaux d'utiliser des outils de protocole de contexte de modèle

  • n8n-io
  • Plateforme d'automatisation de workflow à code équitable avec des capacités d'IA natives. Combinez le bâtiment visuel avec du code personnalisé, de l'auto-hôte ou du cloud, 400+ intégrations.

  • WangRongsheng
  • 🧑‍🚀 全世界最好的 LLM 资料总结 (数据处理、模型训练、模型部署、 O1 模型、 MCP 、小语言模型、视觉语言模型) | Résumé des meilleures ressources LLM du monde.

  • pontusab
  • La communauté du curseur et de la planche à voile, recherchez des règles et des MCP

    Reviews

    5 (1)
    Avatar
    user_yJzgtr0d
    2025-04-17

    As a devoted user of the mcp-sse-example by nerding-io, I find it incredibly useful for understanding server-sent events (SSE). The detailed examples and clear documentation make it a fantastic resource for developers. Highly recommend checking it out at https://github.com/nerding-io/mcp-sse-example!