Cover image
Try Now
2025-03-10

Un ejemplo de trabajo para crear un servidor Fastapi con soporte MCP basado en SSE

3 years

Works with Finder

2

Github Watches

4

Github Forks

28

Github Stars

FastAPI MCP SSE

English | 简体中文

A Server-Sent Events (SSE) implementation using FastAPI framework with Model Context Protocol (MCP) integration.

What is MCP?

The Model Context Protocol (MCP) is an open standard that enables AI models to interact with external tools and data sources. MCP solves several key challenges in AI development:

  • Context limitations: Allows models to access up-to-date information beyond their training data
  • Tool integration: Provides a standardized way for models to use external tools and APIs
  • Interoperability: Creates a common interface between different AI models and tools
  • Extensibility: Makes it easy to add new capabilities to AI systems without retraining

This project demonstrates how to implement MCP using Server-Sent Events (SSE) in a FastAPI web application.

Description

This project demonstrates how to implement Server-Sent Events (SSE) using the FastAPI framework while integrating Model Context Protocol (MCP) functionality. The key feature is the seamless integration of MCP's SSE capabilities within a full-featured FastAPI web application that includes custom routes.

Features

  • Server-Sent Events (SSE) implementation with MCP
  • FastAPI framework integration with custom routes
  • Unified web application with both MCP and standard web endpoints
  • Customizable route structure
  • Clean separation of concerns between MCP and web functionality

Architecture

This project showcases a modular architecture that:

  1. Integrates MCP SSE endpoints (/sse and /messages/) into a FastAPI application
  2. Provides standard web routes (/, /about, /status, /docs, /redoc)
  3. Demonstrates how to maintain separation between MCP functionality and web routes

Installation & Usage Options

Prerequisites

Install UV Package Manager - A fast Python package installer written in Rust:

powershell -ExecutionPolicy ByPass -c "irm https://astral.sh/uv/install.ps1 | iex"

Option 1: Quick Run Without Installation

Run the application directly without cloning the repository using UV's execution tool:

uvx --from git+https://github.com/panz2018/fastapi_mcp_sse.git start

Option 2: Full Installation

Create Virtual Environment

Create an isolated Python environment for the project:

uv venv

Activate Virtual Environment

Activate the virtual environment to use it:

.venv\Scripts\activate

Install Dependencies

Install all required packages:

uv pip install -r pyproject.toml

Start the Integrated Server

Launch the integrated FastAPI server with MCP SSE functionality:

python src/server.py

or

uv run start

Available Endpoints

After starting the server (using either Option 1 or Option 2), the following endpoints will be available:

Debug with MCP Inspector

For testing and debugging MCP functionality, use the MCP Inspector:

mcp dev ./src/weather.py

Connect to MCP Inspector

  1. Open MCP Inspector at http://localhost:5173
  2. Configure the connection:

Test the Functions

  1. Navigate to Tools section
  2. Click List Tools to see available functions:
    • get_alerts : Get weather alerts
    • get_forcast : Get weather forecast
  3. Select a function
  4. Enter required parameters
  5. Click Run Tool to execute

Extending the Application

Adding Custom Routes

The application structure makes it easy to add new routes using FastAPI's APIRouter:

  1. Define new route handlers in routes.py using the APIRouter:

    @router.get("/new-route")
    async def new_route():
        return {"message": "This is a new route"}
    
  2. All routes defined with the router will be automatically included in the main application

Customizing MCP Integration

The MCP SSE functionality is integrated in server.py through:

  • Creating an SSE transport
  • Setting up an SSE handler
  • Adding MCP routes to the FastAPI application

Integration with Continue

To use this MCP server with the Continue VS Code extension, add the following configuration to your Continue settings:

{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "name": "weather",
          "type": "sse",
          "url": "http://localhost:8000/sse"
        }
      }
    ]
  }
}

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

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

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

  • 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.

  • ANGEL LEON
  • A world class elite tech co-founder entrepreneur, expert in software development, entrepreneurship, marketing, coaching style leadership and aligned with ambition for excellence, global market penetration and worldy perspectives.

  • INFOLAB OPERATIONS 2
  • A medical specialist offering assistance grounded in clinical guidelines. Disclaimer: This is intended for research and is NOT safe for clinical use!

  • Callycode Limited
  • A geek-themed horoscope generator blending Bitcoin prices, tech jargon, and astrological whimsy.

  • Yasir Eryilmaz
  • AI scriptwriting assistant for short, engaging video content.

  • apappascs
  • Descubra la colección más completa y actualizada de servidores MCP en el mercado. Este repositorio sirve como un centro centralizado, que ofrece un extenso catálogo de servidores MCP de código abierto y propietarios, completos con características, enlaces de documentación y colaboradores.

  • ShrimpingIt
  • Manipulación basada en Micrypthon I2C del expansor GPIO de la serie MCP, derivada de AdaFruit_MCP230xx

  • OffchainLabs
  • Implementación de la prueba de estaca Ethereum

  • huahuayu
  • Una puerta de enlace de API unificada para integrar múltiples API de explorador de blockchain similar a Esterscan con soporte de protocolo de contexto modelo (MCP) para asistentes de IA.

  • deemkeen
  • Controle su MBOT2 con un combo de potencia: MQTT+MCP+LLM

  • zhaoyunxing92
  • 本项目是一个钉钉 MCP (Protocolo del conector de mensajes )服务 , 提供了与钉钉企业应用交互的 API 接口。项目基于 Go 语言开发 支持员工信息查询和消息发送等功能。 支持员工信息查询和消息发送等功能。

  • pontusab
  • La comunidad de cursor y windsurf, encontrar reglas y MCP

    Reviews

    1 (1)
    Avatar
    user_I6cgoO9s
    2025-04-15

    As a loyal user of the Weather Java SSE Transport MCP Service by stantonk, I am extremely impressed with its seamless integration and real-time data transmission capabilities. It has significantly enhanced my application's performance, making weather updates more reliable and faster. Highly recommended for any developer in need of a robust SSE solution! Check it out here: https://mcp.so/server/mcp-server-java-sse-http-demo/stantonk.