fastapi-mcp logo

fastapi-mcp

by KimiJL

This is a simple example web application demonstrating a Model Context Protocol (MCP) server mounted on an existing FastAPI server. It includes a sample client for communication.

View on GitHub

Last updated: N/A

What is fastapi-mcp?

This is a demonstration of how to integrate a Model Context Protocol (MCP) server as a sub-application within a FastAPI web application. It provides a basic server setup and a client to illustrate communication with the MCP server.

How to use fastapi-mcp?

  1. Use Docker: Build the Docker image using docker build -t fastapi-mcp . and run it with docker run -p 8000:8000 --net=host fastapi-mcp. 2. Alternatively, set up a Python environment: Install dependencies using pip install -r requirements.txt, run the client with python client/client.py, and start the server using uvicorn src.main:app.

Key features of fastapi-mcp

  • FastAPI integration

  • Model Context Protocol implementation

  • Sample client for communication

  • Docker support

  • Sub-application mounting

Use cases of fastapi-mcp

  • Demonstrating MCP integration with FastAPI

  • Building web applications that utilize model context

  • Testing MCP client-server communication

  • Creating microservices with MCP

FAQ from fastapi-mcp

What is Model Context Protocol (MCP)?

MCP is a protocol for managing model context in machine learning applications.

What is FastAPI?

FastAPI is a modern, high-performance web framework for building APIs with Python.

How do I run the server?

You can run the server using Docker or by setting up a Python environment and using uvicorn.

How do I run the client?

Install the required dependencies and then execute the client script using python client/client.py.

What is the known issue?

The MCP server can currently only be mounted on the root path ('/') due to limitations in the MCP Python SDK.