fastapi_mcp
by
tadata-org

Description: Expose your FastAPI endpoints as Model Context Protocol (MCP) tools, with Auth!

View tadata-org/fastapi_mcp on GitHub ↗

Summary Information

Updated 45 minutes ago
Added to GitGenius on August 16th, 2025
Created on March 8th, 2025
Open Issues/Pull Requests: 121 (+0)
Number of forks: 908
Total Stargazers: 11,583 (+1)
Total Subscribers: 66 (+0)
Detailed Description

fastapi_mcp is a Python library built on FastAPI, designed to simplify the creation of Microservice Communication Patterns (MCP) using asynchronous messaging. It provides a robust and flexible framework for building event-driven architectures, focusing on reliable message passing and handling between services. The core idea is to abstract away the complexities of message brokers (like RabbitMQ, Redis Pub/Sub, or Kafka) and offer a consistent, Pythonic interface for publishing and subscribing to events. It's particularly useful for scenarios where loose coupling, scalability, and resilience are paramount.

The library centers around the concepts of 'topics' and 'events'. Topics represent channels for communication, while events are the data payloads exchanged between services. fastapi_mcp doesn't *require* a specific message broker; it offers an abstract `Broker` class that allows developers to plug in different broker implementations. Currently, it provides built-in support for RabbitMQ and Redis Pub/Sub, with the architecture designed to easily accommodate others. This abstraction is a key strength, allowing you to switch brokers without significant code changes. The library handles serialization and deserialization of events, typically using JSON, but this is also configurable.

A central component is the `MCP` class, which acts as the main entry point for interacting with the messaging system. You instantiate an `MCP` object, configuring it with a broker instance and potentially custom event handlers. Services then use the `MCP` instance to publish events to specific topics and subscribe to topics to receive events. The library leverages Python's `asyncio` for asynchronous operation, ensuring non-blocking I/O and efficient handling of concurrent messages. This is crucial for building high-performance microservices.

The repository includes several examples demonstrating how to use the library in different scenarios. These examples cover basic publishing and subscribing, handling event responses (request-reply patterns), and integrating with FastAPI endpoints. The FastAPI integration is particularly noteworthy, allowing you to easily expose event-driven functionality through REST APIs. For instance, an API endpoint can publish an event when a resource is created, triggering downstream services to perform related actions. The examples also showcase how to define custom event schemas using Pydantic, ensuring data validation and consistency.

Beyond the core functionality, fastapi_mcp offers features like message acknowledgement (for reliable delivery), retry mechanisms (to handle transient broker failures), and dead-letter queues (for handling unprocessable messages). It also provides middleware for intercepting and modifying events before they are published or consumed. The library is well-documented, with clear explanations of the key concepts and API reference. It's designed to be extensible and customizable, allowing developers to tailor it to their specific needs. The project is actively maintained and welcomes contributions from the community, making it a viable option for building robust and scalable microservice architectures.

fastapi_mcp
by
tadata-orgtadata-org/fastapi_mcp

Repository Details

Fetching additional details & charts...