fastapi-docs
by Surya96t
README.md
# ๐ 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](docs/README.md)** - Full documentation with table of contents
### Quick Links
- **Getting Started**
- [Installation](docs/01-getting-started/01-installation.md) - Set up your environment
- [Initial Setup](docs/01-getting-started/02-initial-setup.md) - Populate the cache
- [Quick Start](docs/01-getting-started/03-quick-start.md) - Run your first queries
- **Integration Guides**
- [LLM Quick Start](docs/03-integration/01-llm-quick-start.md) - Integrate with AI assistants
- [Claude Desktop](docs/03-integration/04-claude-desktop.md) - Claude setup guide
- [VS Code Setup](docs/03-integration/03-vscode-setup.md) - VS Code configuration
- **Development**
- [Testing Guide](docs/04-development/01-testing.md) - Run and write tests
- [Architecture](docs/04-development/02-architecture.md) - Understand the codebase
- [Contributing](docs/04-development/03-contributing.md) - How to contributextraction for FastAPI documentation. Perfect for AI assistants like Claude, Copilot, and other LLM-powered tools.
[](https://www.python.org/downloads/)
[](https://opensource.org/licenses/MIT)
[](https://modelcontextprotocol.io)
---
## ๐ 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](https://docs.astral.sh/uv/) (recommended) or pip
### Installation
```bash
# 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:
```bash
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.):
```json
{
"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](docs/LLM_QUICK_START.md) for detailed integration guides.
### 2. **Direct Python API**
```python
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**
```bash
# 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
```bash
# 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](docs/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](.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
- [LLM Quick Start](docs/LLM_QUICK_START.md) - Get started with LLM integration
- [LLM Integration Guide](docs/LLM_INTEGRATION.md) - Detailed integration patterns
- [Quick Test Guide](docs/QUICK_TEST_GUIDE.md) - Testing walkthrough
- [Testing Guide](docs/TESTING.md) - Comprehensive test documentation
- [VS Code Setup](docs/.vscode/README_MCP.md) - VS Code configuration
---
## ๐ค 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](LICENSE) for details.
---
## ๐ Acknowledgments
- [FastAPI](https://fastapi.tiangolo.com/) - The amazing framework this serves
- [Model Context Protocol](https://modelcontextprotocol.io) - The protocol powering AI integration
- [ChromaDB](https://www.trychroma.com/) - Vector database for semantic search
- [Sentence Transformers](https://www.sbert.net/) - Embedding models
---
## ๐ 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**