FastAPI CRUD MCP

FastAPI CRUD MCP

A minimal CRUD API for items that exposes FastAPI endpoints as MCP tools, enabling natural language interaction with a database through PydanticAI agents.

Category
Visit Server

README

codecov Python Version License: MIT

FastAPI CRUD MCP

A minimal CRUD API for “items,” built with FastAPI and exposed as MCP tools via FastAPI-MCP. Includes a scenario-driven client harness using PydanticAI and Rich.


🚀 Features

  • FastAPI: high-performance HTTP API
  • SQLAlchemy + Pydantic: ORM models + input/output schemas
  • FastAPI-MCP: auto-expose your endpoints as MCP tools (/mcp/tools, /mcp/events)
  • Rich CLI: beautiful, colored terminal output for scenario runs
  • Scenario Runner: client harness that drives and validates your API via PydanticAI agents
  • SQLite backend for demo; easily swap to PostgreSQL, MySQL, etc.

📦 Project Layout


.
├── backend
│   ├── server
│   │   ├── main.py            # FastAPI + FastAPI-MCP wiring
│   │   ├── models.py          # SQLAlchemy + Pydantic schemas
│   │   ├── routes.py          # CRUD endpoints
│   │   ├── crud.py            # DB operations
│   │   ├── db.py              # session & engine
│   │   └── logger.py          # stdlib logging setup
│   └── client
│       ├── scenarios.py       # Scenario definitions
│       └── main.py            # run\_scenarios.py harness
├── .env                       # example environment variables
├── pyproject.toml             # Project dependencies
└── README.md                  # this file


⚙️ Installation & Setup

  1. Clone & enter directory

    git clone https://github.com/yourusername/fastapi-crud-mcp.git
    cd fastapi-crud-mcp
    
  2. Create & activate a virtualenv

    uv venv
    source .venv/bin/activate
    
  3. Install dependencies

    uv sync
    
  4. Environment variables Copy the example and adjust if needed:

    cp .env.example .env
    
    MCP_HOST_URL='http://127.0.0.1:8000/mcp'
    
    LLM_PROVIDER='openai'
    LLM_MODEL_NAME='gpt-4o-mini'
    LLM_MODEL=${LLM_PROVIDER}:${LLM_MODEL_NAME}
    
    OPENAI_API_KEY=sk-proj-your-api-key-here
    

🏃 Running the Server

docker compose up -d --build
  • API docshttp://localhost:8000/docs
  • OpenAPI JSONhttp://localhost:8000/openapi.json

🤖 Running the Scenario Client

python3 -m backend.client.main

This harness will:

  1. Load your .env settings
  2. Spin up a PydanticAI agent against MCP_HOST_URL
  3. Execute each scenario (create/list/get/update/delete)
  4. Display rich panels for prompts & outputs

🚨 Notes & Tips

  • Switch DB: edit backend/server/db.py for PostgreSQL or MySQL.
  • Add auth: protect /mcp or /api via FastAPI dependencies.
  • Extend scenarios: drop new entries into backend/client/scenarios.py.
  • Production: add Alembic for migrations, and monitor with Prometheus.

🤝 Contributing

  1. Fork 🔱

  2. Create a feature branch:

    git checkout -b feature/my-feature
    
  3. Commit & push:

    git commit -am "Add awesome feature"
    git push origin feature/my-feature
    
  4. Open a PR and we’ll review!


📄 License

This project is MIT-licensed—see the LICENSE file for details.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured