DEV Community

Cover image for 🔥 Only 2 Lines of code to create an MCP server from a FastAPI - Major updates 🚀
Miki Makhlevich
Miki Makhlevich

Posted on

🔥 Only 2 Lines of code to create an MCP server from a FastAPI - Major updates 🚀

Just released a huge update to FastAPI-MCP, our zero-configuration tool that lets you expose FastAPI endpoints as Model Context Protocol (MCP) tools with a completely revamped architecture! Only 2 lines of code and you have a configurable and reliable MCP server!

major success

Two Powerful Improvements You Need To Know About:

🎯 NEW: Selective Endpoint Exposure

We had such great adoption, which came with a lot of requests and pressure to support this feature. You asked, we delivered! Now you can precisely control which endpoints become MCP tools with simple include/exclude configurations.

💪 Class-Based Architecture For Better Extensibility

We've completely refactored the implementation to use a new FastApiMCP class for better usability and extensibility. This gives you more control and prevents edge-case in complex FastAPI configurations. No more frustration over endless bugs!

frustrating bugs

Implementation Is Still Super Simple:

from fastapi import FastAPI
from fastapi_mcp import FastApiMCP

app = FastAPI()

mcp = FastApiMCP(app)

# Mount the MCP server directly to your FastAPI app
mcp.mount()
Enter fullscreen mode Exit fullscreen mode

To control which endpoints are exposed, play with the FastApiMCP arguments:

  • include_operations
  • exclude_operations
  • include_tags
  • exclude_tags

This update is available now on PyPI!

Finally

You can read more about our refactor journey here.
Don't forget to star our repo FastAPI-MCP !

Top comments (0)