Cover image
Try Now
2025-04-14

3 years

Works with Finder

0

Github Watches

0

Github Forks

0

Github Stars

FastAPI SSE MCP

A FastAPI application that demonstrates Server-Sent Events (SSE) integration with the Model Context Protocol

Overview

This project showcases how to use Server-Sent Events (SSE) as a transport layer for MCP in a FastAPI application. It provides a simple echo service that can:

  • Handle FastAPI HTTP requests
  • Implement MCP tools, resources and prompts using the MCP python-sdk

Requirements

  • Python 3.12+
  • FastAPI 0.115.11+
  • MCP 1.4.1+

Installation

  1. Clone this repository:

    git clone https://github.com/ragieai/fastapi-sse-mcp.git
    cd fastapi-sse-mcp
    
  2. Install dependencies:

    uv sync --dev
    

Running the Application

Start the FastAPI server:

uv run uvicorn app.main:app --reload

The server will be available at http://127.0.0.1:8000.

API Endpoints

  • GET / - Returns a simple JSON greeting
  • GET /sse/ - SSE endpoint for establishing connections
  • POST /messages/ - Endpoint for sending messages over SSE

Examples

The application provides three example MCP functions:

  1. Tool Function: Echoes messages

    @mcp.tool()
    def echo_tool(message: str) -> str:
        """Echo a message as a tool"""
        return f"Tool echo: {message}"
    
  2. Prompt Function: Creates echo prompts

    @mcp.prompt()
    def echo_prompt(message: str) -> str:
        """Create an echo prompt"""
        return f"Please process this message: {message}"
    
  3. Resource Function: Handles resource requests

    @mcp.resource("echo://{message}")
    def echo_resource(message: str) -> str:
        """Echo a message as a resource"""
        return f"Resource echo: {message}"
    

License

MIT License

Copyright (c) 2024 Ragie Corp

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

相关推荐

  • av
  • 毫不费力地使用一个命令运行LLM后端,API,前端和服务。

  • 1Panel-dev
  • 🔥1Panel提供了直观的Web接口和MCP服务器,用于在Linux服务器上管理网站,文件,容器,数据库和LLMS。

  • rulego
  • ⛓️Rulego是一种轻巧,高性能,嵌入式,下一代组件编排规则引擎框架。

  • WangRongsheng
  • 🧑‍🚀 llm 资料总结(数据处理、模型训练、模型部署、 o1 模型、mcp 、小语言模型、视觉语言模型)|摘要世界上最好的LLM资源。

  • Onelevenvy
  • Flock是一个基于工作流程的低音平台,可快速构建聊天机器人,抹布和协调多代理团队,由Langgraph,Langchain,Langchain,Fastapi和Nextjs提供支持。(羊群工作流工作流的低代码平台,rag rag rag 用于快速构建聊天机器人、 rag temant Agent fastem temantfaster和muti-agent agagent应用

  • Byaidu
  • PDF科学纸翻译带有保留格式的pdf -基于ai完整保留排版的pdf文档全文双语翻译

  • n8n-io
  • 具有本机AI功能的公平代码工作流程自动化平台。将视觉构建与自定义代码,自宿主或云相结合,400+集成。

  • hkr04
  • 轻巧的C ++ MCP(模型上下文协议)SDK

  • sigoden
  • 使用普通的bash/javascript/python函数轻松创建LLM工具和代理。

  • RockChinQ
  • 😎简单易用、🧩丰富生态 -大模型原生即时通信机器人平台| 适配QQ / 微信(企业微信、个人微信) /飞书 /钉钉 / discord / telegram / slack等平台| 支持chatgpt,deepseek,dify,claude,基于LLM的即时消息机器人平台,支持Discord,Telegram,微信,Lark,Dingtalk,QQ,Slack

    Reviews

    2.7 (17)
    Avatar
    user_oQNcOv5D
    2025-04-23

    I recently started using fastapi-sse-mcp by fgsoap, and it has been a game-changer for my projects. The seamless integration with FastAPI and the real-time capabilities provided by SSE are outstanding. It simplifies a lot of the complexities I faced before, and the documentation is clear and helpful. Highly recommend for anyone needing efficient server-sent events in their FastAPI applications!

    Avatar
    user_HK9jd1Sf
    2025-04-23

    As a devoted user of the fastapi-sse-mcp application by fgsoap, I am thoroughly impressed with its seamless integration of server-sent events in FastAPI. The setup is straightforward, and the real-time capabilities have significantly enhanced my web applications. This product exemplifies reliability and efficiency, making it a must-have for modern web development. Highly recommended!

    Avatar
    user_eLhluiDT
    2025-04-23

    As a devoted user of fastapi-sse-mcp, I find this tool invaluable for Server-Sent Events (SSE) in my FastAPI projects. The seamless integration and excellent support by the author, fgsoap, make setting up real-time communication a breeze. Its comprehensive documentation and user-friendly features significantly streamline my development process. Highly recommended for developers looking for efficient SSE solutions in FastAPI apps!

    Avatar
    user_PSvbhMtm
    2025-04-23

    I've been using fastapi-sse-mcp and it's just incredible! The integration with FastAPI makes handling server-sent events seamless and efficient. Kudos to fgsoap for creating such a robust and easy-to-use tool. Highly recommended for anyone working with real-time data streaming!

    Avatar
    user_Uu9GWr2d
    2025-04-23

    As a dedicated MCP application user, I am thoroughly impressed with fastapi-sse-mcp by fgsoap. This innovative tool enhances server-sent events integration with FastAPI, making real-time data streaming seamless and efficient. The intuitive design and robust functionality elevate productivity and streamline an otherwise complex process. Highly recommended for any developer working with real-time applications!

    Avatar
    user_poTGFg7s
    2025-04-23

    Fastapi-sse-mcp is a brilliant tool by fgsoap! It seamlessly integrates with FastAPI applications to provide Server-Sent Events (SSE) functionality, making real-time updates a breeze. The documentation and support are top-notch, and its ease of use is impressive, even for beginners. Highly recommended for anyone looking to enhance their FastAPI projects with SSE.

    Avatar
    user_Ud1qVNo2
    2025-04-23

    I'm thoroughly impressed with fastapi-sse-mcp by fgsoap. This tool makes server-sent events integration seamless and efficient, greatly enhancing real-time capabilities for my FastAPI projects. The documentation is clear, and the setup is straightforward, making it a go-to for developers looking to boost their app's live data handling. Highly recommend!

    Avatar
    user_qEaIgXiY
    2025-04-23

    As a devoted MCP application user, I have to say that fastapi-sse-mcp by fgsoap is a game-changer! It's incredibly efficient and easy to integrate into any project. The real-time updates with SSE are seamless, and the developer support is top-notch. Highly recommend it to anyone looking to enhance their FastAPI applications with server-sent events.

    Avatar
    user_h9igGhns
    2025-04-23

    Fastapi-sse-mcp by fgsoap is a fantastic solution for scalable server-sent events in FastAPI applications. It stands out for its seamless integration and simplicity, making real-time data streaming a breeze. I've found it incredibly effective in managing live updates and notifications. Highly recommended for anyone looking to enhance their FastAPI projects with real-time capabilities!

    Avatar
    user_tns9Nr7m
    2025-04-23

    As a devoted MCP user, I find fastapi-sse-mcp by fgsoap to be immensely beneficial. This well-crafted FastAPI extension enhances server-sent events (SSE) handling, making real-time data updates seamless and efficient. The implementation is straightforward and the documentation is clear, providing a great developer experience. Highly recommended for anyone needing reliable SSE in their FastAPI projects!

    Avatar
    user_icWI8NiL
    2025-04-23

    As a loyal MCP user, I have to say that the fastapi-sse-mcp by fgsoap is an impressive solution! Its seamless integration with FastAPI and real-time capabilities through server-sent events (SSE) have significantly improved our application's performance and user experience. Highly recommend it to any developer working on dynamic web applications!

    Avatar
    user_gAeCfMmV
    2025-04-23

    As a loyal user of the fastapi-sse-mcp, I must say it has significantly simplified my real-time data streaming tasks. The seamless integration with FastAPI and the robustness provided by fgsoap's development make it a go-to choice for any developer working on server-sent events. Highly recommend for anyone looking to optimize their async workflows!

    Avatar
    user_1jrqtjEZ
    2025-04-23

    Fastapi-sse-mcp by fgsoap is an exceptional product for implementing server-sent events with FastAPI. It's efficient, reliable, and its integration is seamless. The documentation provided is clear and concise, making it easy even for beginners to get started. Highly recommend it for any FastAPI project requiring real-time data streaming.

    Avatar
    user_Upw5INey
    2025-04-23

    As a dedicated user of the fastapi-sse-mcp application by fgsoap, I am thoroughly impressed by its seamless integration and efficient performance. The ability to handle server-sent events with ease has significantly improved the responsiveness of my projects. Its functionality and reliability in real-time data communication set it apart, making it an invaluable tool in modern web development. Highly recommended for anyone looking to enhance their FastAPI applications!

    Avatar
    user_GENB0YIC
    2025-04-23

    As a dedicated user of fastapi-sse-mcp, I am extremely impressed by fgsoap's creation. This tool simplifies implementing server-sent events with FastAPI, making real-time communication effortless. Its seamless integration and robust performance have significantly enhanced my application's responsiveness. Highly recommend for anyone needing efficient and effective SSE solutions!

    Avatar
    user_qIMPcFTr
    2025-04-23

    fastapi-sse-mcp by fgsoap is a fantastic tool for real-time web applications. The seamless integration and robust performance make it a go-to for handling server-sent events efficiently. As a developer, I find it incredibly user-friendly, streamlining the process of developing dynamic web apps with ease. I highly recommend giving it a try!

    Avatar
    user_FK0Rc6Dd
    2025-04-23

    As a dedicated MCP application user, I find fastapi-sse-mcp by fgsoap absolutely impressive. Its seamless integration and real-time capabilities make it a must-have for any developer working with server-sent events. The straightforward setup through the provided URL and the welcoming guide ensured a smooth start. Highly recommend!