fastapi-mcp-server

fastapi-mcp-server

2

FastAPI MCP Server is a robust and lightweight server designed to facilitate interaction between AI models and user applications using the Model Context Protocol. It leverages FastAPI for asynchronous communication, supporting multi-user sessions, and tool registrations to enhance AI-powered applications.

🚀 FastAPI MCP Server

A high-performance Model Context Protocol (MCP) integration application designed for large language models, using the FastAPI framework. It features server-side events communication, intelligent tool registration, and comprehensive session management.

Project Highlights

  • FastAPI + MCP Integration: Seamless integration providing standardized model interaction interfaces.
  • Efficient SSE Real-time Communication: Millisecond-level response unidirectional data flow using server-sent events.
  • Multi-user Session Isolation: Robust session management ensuring data isolation for multiple users.
  • Flexible Authentication Mechanisms: Supports token, path, and query parameter authentication.
  • Fully Asynchronous Architecture: Asynchronous design for request handling and database operations supporting high concurrency.
  • Intelligent Tool Registration System: Simplifies registration and management of AI tool functions.

Installation Guide

Prerequisites

  • Python 3.13+
  • Asynchronous supporting database (optional)
  • UV package manager (recommended)

Installation Steps

  1. Clone the repository.
  2. Create and activate a virtual environment.
  3. Install dependencies using UV.
  4. Configure environment variables.
  5. Create database session file.
  6. Customize authentication logic.

Usage Guide

Start Server

  • Use Python or UV to start the server, running on http://localhost:8000.
  • Use inspector mode for debugging.

Custom Tools

Add custom tools in the tools/ directory and register in server.py.