mcp-rest-sample

mcp-rest-sample

3.4

Python sample code for MCP server + REST API (FastAPI) integration.

The MCP server with REST API integration using FastAPI is a project designed to demonstrate how to effectively integrate a Model Context Protocol (MCP) server with a RESTful API using FastAPI. This project utilizes the Python SDK for MCP to handle the protocol and employs 'uv' for managing dependencies. The integration with FastAPI allows for seamless handling of both REST API requests and MCP server operations. The project structure is inspired by the 'panz2018/fastapi_mcp_sse' repository, providing a robust framework for developers looking to implement similar integrations. The documentation includes commands for local development and instructions on how to run or connect to the MCP server, making it accessible for developers to contribute or adapt the project for their own needs.

Features

  • Integration with FastAPI for REST API handling.
  • Utilizes Python SDK for MCP protocol management.
  • Dependency management using 'uv'.
  • Inspired project structure for ease of use.
  • Comprehensive documentation for development and connection.

Usage with Different Platforms

Python

python
import uvicorn
from fastapi import FastAPI
from mcp import MCPServer

app = FastAPI()
mcp_server = MCPServer()

@app.get("/")
async def root():
    return {"message": "Hello World"}

if __name__ == "__main__":
    uvicorn.run(app, host="0.0.0.0", port=8000)