Skip to main content
Glama
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.

[![Python 3.10+](https://img.shields.io/badge/python-3.10+-blue.svg)](https://www.python.org/downloads/)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![MCP](https://img.shields.io/badge/MCP-1.0+-green.svg)](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**