Implements a REST API with endpoints for chat completion, document search, health checks, and GitHub repository ingestion, with automatic API documentation generation.
Enables ingestion of documents from GitHub repositories with features for repository cloning, document extraction based on file patterns, and size limitations.
Provides document storage and search capabilities through MongoDB Atlas, with tools for searching documents by text query, retrieving documents, getting document counts, and filtering documents by metadata.
sample-mcp-server
MCP Server Example
AI assistant application that integrates FastMCP server, MongoDB Atlas knowledge base, and LLM endpoint with direct MCP tool calling capabilities.
🎯 Key Update: Direct MCP Integration Implemented
This version implements the exact requested flow:
Flow Implementation
- User sends chat message → FastAPI
/chat
endpoint - LLM generates JSON function call → Compatible with Llama3-8B-Instruct
- LLM service calls MCP tools directly →
await mcp._mcp_call_tool(function_name, parameters)
- MCP tools query MongoDB Atlas → Native FastMCP integration
- Documents returned through MCP → Proper MCP protocol response
- LLM processes results → Generates final response with context
- User receives response → Complete chat completion with document context
🚀 Quick Start
1. Setup project
task setup
2. Configure environment (IMPORTANT!)
Edit .env file with your actual credentials
nano .env # or your preferred editor
3. Start the server
task dev
Features
- FastMCP Server: Provides MCP tools for document search and retrieval
- REST API: Complete API with /chat and /ingest_github endpoints
- MongoDB Atlas Integration: Document storage and search capabilities
- LLM Integration: LLM endpoint
- GitHub Integration: Repository document ingestion
- Swagger/ReDoc Documentation: Auto-generated API documentation
- Production-Grade: Comprehensive error handling, logging, and async architecture
API Endpoints
GET /healthz
- Health check endpointPOST /chat
- Chat completion with MCP tool callingPOST /ingest_github
- Ingest GitHub repository documentsPOST /search
- Search documents in knowledge baseGET /documents/count
- Get total document countGET /mcp/info
- Get MCP server informationGET /docs
- Swagger UI documentationGET /redoc
- ReDoc documentation
MCP Tools
search_documents
- Search documents by text queryget_all_documents
- Get all documents with limitget_document_count
- Get total document countsearch_documents_by_metadata
- Search by metadata filters
Prerequisites
- Python 3.12+
- Poetry (for dependency management)
- MongoDB Atlas account and cluster
- GitHub token (for repository ingestion)
- Access to LLM endpoint
📋 Prerequisites
- Python 3.12+ (recommended to use pyenv)
- Poetry for dependency management
- Task (optional but recommended) for task automation
- MongoDB Atlas account and cluster
- GitHub token for repository ingestion
- Access to LLM endpoint
Access the Application
Once running, you can access:
- API Server: http://localhost:8000
- Swagger UI: http://localhost:8000/docs
- ReDoc: http://localhost:8000/redoc
- Health Check: http://localhost:8000/healthz
Manual API Testing
1. Health Check
2. MCP Server Information
3. Document Count
4. Document Search
5. Chat Completion (requires valid LLM credentials)
6. GitHub Repository Ingestion (requires valid GitHub token)
Testing with Swagger UI
- Start the server:
task dev
- Open http://localhost:8000/docs in your browser
- Use the interactive API documentation to test endpoints
- Click "Try it out" on any endpoint to test with custom parameters
Architecture
Services
- MongoDBService: Async MongoDB Atlas operations
- GitHubService: Repository cloning and document ingestion
- LLMService: LLM integration with tool calling
- MCP Server: FastMCP server with document tools
Models
- Document: Core document model with metadata
- ChatRequest/Response: Chat API models
- GitHubIngestRequest/Response: GitHub ingestion models
- DocumentSearchRequest/Response: Search API models
Configuration
- Pydantic Settings: Environment-based configuration
- Async Architecture: Full async/await support
- Error Handling: Comprehensive error management
- Logging: Structured logging throughout
📁 Project Structure
🛠️ Development
Available Tasks
This server cannot be installed
AI assistant application that integrates FastMCP server with MongoDB Atlas knowledge base, enabling direct MCP tool calling for document search and retrieval through a complete REST API.
Related MCP Servers
- AsecurityAlicenseAqualityAn MCP server implementation that provides tools for retrieving and processing documentation through vector search, enabling AI assistants to augment their responses with relevant documentation contextLast updated -713211TypeScriptMIT License
- AsecurityAlicenseAqualityAn MCP server that enables users to create and manage MongoDB Atlas clusters, users, and network access through natural language commands.Last updated -644711JavaScriptMIT License
- AsecurityFlicenseAqualityAn MCP server that integrates Apifox API documentation with AI assistants, allowing AI to extract and understand API information from Apifox projects.Last updated -2668TypeScript
- AsecurityFlicenseAqualityAn MCP server that provides AI assistants with access to Astro documentation, enabling them to search and reference Astro docs when helping users with Astro-related tasks.Last updated -11JavaScript