Skip to content

Surya96t/mcp-fastapi-docs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

πŸš€ MCP FastAPI Docs

Intelligent FastAPI Documentation Search via Model Context Protocol (MCP)

A standalone MCP server that provides semantic search, topic exploration, and code ex## οΏ½ Documentation

πŸ“š Complete Documentation - Full documentation with table of contents

Quick Links

Python 3.10+ License: MIT MCP


🌟 Features

  • οΏ½ Semantic Search - Natural language queries powered by sentence transformers
  • πŸ“š Topic Listing - Browse all 104 FastAPI documentation topics
  • πŸ“– Topic Retrieval - Get full content for any specific topic
  • πŸ’» Code Examples - Extract code snippets with language and syntax highlighting
  • πŸ”„ Version Comparison - Compare features across different FastAPI versions
  • ⚑ Fast & Local - Runs entirely on your machine with ChromaDB vector storage
  • 🎯 Zero Config - Works out of the box with sensible defaults

🎯 Quick Start

Prerequisites

  • Python 3.10 or higher
  • uv (recommended) or pip

Installation

# Clone the repository
git clone https://github.com/yourusername/mcp-fastapi-docs.git
cd mcp-fastapi-docs

# Install dependencies with uv (recommended)
uv sync

# Or with pip
pip install -e .

Initial Setup

Populate the cache with FastAPI documentation:

uv run python scripts/populate_cache.py

This downloads FastAPI docs and builds the vector database (takes 2-3 minutes).


οΏ½ Usage

1. As an MCP Server (Recommended)

Configure your MCP client (Claude Desktop, VS Code, etc.):

{
  "mcpServers": {
    "fastapi-docs": {
      "command": "uv",
      "args": ["run", "mcp-fastapi-docs"],
      "env": {
        "CACHE_DIR": "/absolute/path/to/cache",
        "LOG_LEVEL": "INFO"
      }
    }
  }
}

See LLM_QUICK_START.md for detailed integration guides.

2. Direct Python API

import asyncio
from mcp_fastapi_docs.server.tools import search_docs, list_topics, get_topic

async def main():
    # Search documentation
    results = await search_docs("how to use path parameters", version="latest")

    # List all topics
    topics = await list_topics(version="latest")

    # Get specific topic
    content = await get_topic("Path Parameters", version="latest")

asyncio.run(main())

3. Interactive Testing

# Manual testing
uv run python scripts/test_mcp_manual.py

# Interactive CLI
uv run python scripts/test_interactive.py

πŸ› οΈ Available Tools

The MCP server exposes 6 powerful tools:

Tool Description Parameters
search_docs Semantic search across documentation query, version, max_results
list_versions List all available documentation versions None
list_topics List all available topics version
get_topic Get full content for a topic topic, version
get_example Extract code examples for a feature feature, version
compare_versions Compare a feature across versions feature, versions

All tools support version="latest" which automatically resolves to the newest available version.


πŸ“ Project Structure

mcp-fastapi-docs/
β”œβ”€β”€ src/mcp_fastapi_docs/
β”‚   β”œβ”€β”€ core/           # Cache, fetcher, processor
β”‚   β”œβ”€β”€ models/         # Pydantic models & config
β”‚   β”œβ”€β”€ search/         # Semantic search engine
β”‚   β”œβ”€β”€ server/         # MCP server & tool registry
β”‚   └── utils/          # Logging utilities
β”œβ”€β”€ scripts/            # Setup & testing scripts
β”œβ”€β”€ cache/              # Local documentation & embeddings
β”œβ”€β”€ docs/               # Documentation guides
β”œβ”€β”€ tests/              # Pytest test suite
└── examples/           # Usage examples

πŸ§ͺ Testing

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov=src/mcp_fastapi_docs --cov-report=html

# Test specific functionality
uv run python scripts/test_search.py

See TESTING.md for comprehensive testing guide.


πŸ”Œ VS Code Integration

This project includes VS Code MCP server configuration:

  1. Open workspace in VS Code
  2. MCP server auto-registers via .vscode/mcp.json
  3. Use Copilot or other MCP extensions to query FastAPI docs

See .vscode/README_MCP.md for details.


πŸŽ“ Learning & Extending

This project is designed as a learning template for building MCP servers:

  • Self-contained - All components in one repo
  • Well-documented - Extensive inline comments & guides
  • Modular design - Easy to adapt for other frameworks
  • Best practices - Type hints, async/await, proper error handling

Want to build similar servers for Flask or Django? This codebase serves as a complete reference implementation.


οΏ½ Documentation


🀝 Contributing

Contributions are welcome! This project follows standard open-source practices:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ› Troubleshooting

Issue: No FastAPI documentation versions available

  • Solution: Run uv run python scripts/populate_cache.py

Issue: Import errors or missing dependencies

  • Solution: Run uv sync or pip install -e .

Issue: MCP server not responding

  • Solution: Check logs in cache/logs/mcp-fastapi-docs.log

πŸ“„ License

MIT License - see LICENSE for details.


πŸ™ Acknowledgments


πŸš€ Future Plans

  • Support for multiple FastAPI versions
  • Incremental cache updates
  • Full-text search alongside semantic search
  • Web UI for documentation browsing
  • API rate limiting and caching strategies

Built with ❀️ for the FastAPI and AI community

About

No description, website, or topics provided.

Resources

License

Code of conduct

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published