Skip to content

akvo/vector-knowledge-base-mcp-server

Repository files navigation

Vector Knowledge Base MCP Server

Repo Size Languages Issues Last Commit

A high-performance FastAPI/FastMCP-based Model Context Protocol (MCP) server that provides vector-based knowledge management with document storage, similarity search, and intelligent retrieval capabilities.


πŸ“– Table of Contents


πŸš€ Features

  • FastAPI Backend: High-performance async API server
  • Vector Database: ChromaDB integration for semantic search
  • Document Storage: MinIO object storage for file management
  • PostgreSQL Database: Structured data storage and metadata
  • MCP Protocol: Model Context Protocol server implementation using FastMCP
  • Admin Interface: PgAdmin for database management (development only)
  • Development Ready: Hot-reload and development tools included

πŸ—οΈ Architecture

β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚   FastAPI App   │────│   ChromaDB      │────│   PostgreSQL    β”‚
β”‚   (Port 8100)   β”‚    β”‚   (Port 8101)   β”‚    β”‚   (Port 5432)   β”‚
│─────────────────│    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
β”‚   FastMCP App   β”‚
β”‚ (Port 8100/mcp) β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
         β”‚
         β”‚
β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”    β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
β”‚     MinIO       β”‚    β”‚    PgAdmin      β”‚
β”‚ (Ports 9100/01) β”‚    β”‚   (Port 5550)   β”‚
β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜    β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

All port described in above schema are for development

πŸ› οΈ Tech Stack

  • Backend: FastAPI with Python 3.11+
  • Vector Database: ChromaDB for embeddings and similarity search
  • Database: PostgreSQL 12 with Alpine Linux
  • Object Storage: MinIO for file storage
  • Containerization: Docker & Docker Compose
  • MCP Protocol: FastMCP for model context protocol implementation

πŸ“‹ Prerequisites

  • Docker and Docker Compose
  • Python 3.11+ (for local development)
  • Git

πŸš€ Quick Start

Environment Variables

Before running the application, create a .env file based on .env.example:

cp .env.example .env

Fill in the variables according to your environment:

APP_ENV=dev
APP_PORT=8100

DATABASE_URL=postgresql://akvo:password@db:5432/kb_mcp

# MinIO settings
MINIO_ENDPOINT=minio:9000
MINIO_ACCESS_KEY=minioadmin
MINIO_SECRET_KEY=minioadmin
MINIO_BUCKET_NAME=documents

# Chroma DB settings
CHROMA_DB_HOST=chromadb
CHROMA_DB_PORT=8000
VECTOR_STORE_BATCH_SIZE=100

# OpenAI settings
OPENAI_API_KEY=your-openai-api-key-here
OPENAI_API_BASE=https://api.openai.com/v1
OPENAI_MODEL=gpt-4
OPENAI_EMBEDDINGS_MODEL=text-embedding-ada-002

# Admin Auth
ADMIN_API_KEY=your-admin-api-key-here

Notes

  • APP_ENV accepts two values: prod or dev.
  • This variable controls the startup command in entrypoint.sh, determining whether the application runs in reload mode (dev) or in production mode (prod).
  • VECTOR_STORE_BATCH_SIZE controls how many documents are processed in a single batch when adding to the vector store. There is a trade off between performance and hitting limits on the number of chunks that can be stored at once default is 100 but you can tune this setting here.
  • ADMIN_API_KEY currently used for authentication to access the CRUD API keys endpoint. With this, the script can create an API key that will be used as the authentication token to access the CRUD Knowledge Base.

Development Setup

  1. Clone the repository

    git clone [email protected]:akvo/vector-knowledge-base-mcp-server.git
    cd vector-knowledge-base-mcp-server
  2. Set up environment variables

    cp .env.example .env
    # Edit .env with your configurations
  3. Start the development environment

    ./dev.sh up -d
  4. Verify services are running

    docker compose ps
  5. Running pytest

    • Running FastAPI endpoint test
    ./dev.sh exec main ./test.sh api
    • Running e2e test
    ./dev.sh exec main ./test.sh e2e
    • Running FastMCP test
    ./dev.sh exec main ./test.sh mcp
    • Running All test
    ./dev.sh exec main ./test.sh all

Production Setup

  1. Build and start production services
    docker compose -f docker-compose.yml up -d

Service Ports (dev)

Service Development Production Description
FastAPI 8100 8000 Main application API
ChromaDB 8101 8001 Vector database
PostgreSQL 5432 5432 Primary database
MinIO API 9100 9000 Object storage API
MinIO Console 9101 9001 MinIO web interface
PgAdmin 5550 - Database admin (dev only)

πŸ”‘ Authentication and API Keys

This project uses API keys for authentication to access the Knowledge Base and Admin APIs. There are two types of keys:

  1. Admin API Key (ADMIN_API_KEY) – Used for administrative actions, such as creating or revoking other API keys.
  2. API Key – Generated via the Admin API to access the Knowledge Base endpoints.

Using the Admin API Key

  • Your ADMIN_API_KEY is defined in your .env file.
  • To perform administrative tasks, include it in the Authorization header:
Authorization: Admin-API-Key <your_admin_api_key>

Example: Create a new API key via Admin endpoint

curl -X POST http://localhost:8100/api/v1/api-key \
  -H "Authorization: Admin-Key sk_xxxxxxx" \
  -H "Content-Type: application/json" \
  -d '{"name": "app-name", "is_active": true}'

Using the API Key

  • The generated API key is used to access protected Knowledge Base endpoints.
  • Include it in the Authorization header:
Authorization: API-Key <your_api_key>

Example: Query the Knowledge Base

curl -X GET http://localhost:8100/api/v1/knowledge-base \
  -H "Authorization: API-Key sk_xxxxxxx"

πŸ‘‰ For the detail of API-Key usage, please read: SECURITY.md

Summary Table

Key Type Header Name Purpose
Admin API Key Authorization: Admin-Key <key> Manage API keys and administrative tasks
User/API Key Authorization: API-Key <key> Access Knowledge Base and perform CRUD ops

πŸ“– API Documentation

Once the application is running (uvicorn app.main:app --reload or via Docker), the API documentation is automatically available through FastAPI docs:

From these interfaces, you can:

  • Try out endpoints directly
  • View request and response schemas
  • Test the API interactively

πŸ“ Project Structure

vector-knowledge-base-mcp-server/
β”œβ”€β”€ main/                          # FastAPI application
β”‚   β”œβ”€β”€ app/
β”‚   β”‚   β”œβ”€β”€ api/                   # API routes (endpoint FastAPI)
β”‚   β”‚   β”œβ”€β”€ core/                  # Core configuration (settings, logging, security)
β”‚   β”‚   β”œβ”€β”€ mcp/                   # MCP related files (FastMCP server, tools)
β”‚   β”‚   β”œβ”€β”€ models/                # Pydantic models / ORM models
β”‚   β”‚   β”œβ”€β”€ schemas/               # API schemas (Pydantic / base)
β”‚   β”‚   β”œβ”€β”€ services/              # Business logic / service layer
β”‚   β”‚   β”œβ”€β”€ utils/                 # Helpers / utilities
β”‚   β”œβ”€β”€ tests/                     # Unit / integration tests
β”‚   β”œβ”€β”€ Dockerfile
β”‚   └── requirements.txt
β”œβ”€β”€ db/
β”‚   β”œβ”€β”€ docker-entrypoint-initdb.d/ # Init SQL scripts
β”‚   └── script/                    # Migration / seed
β”œβ”€β”€ pgadmin4/
β”‚   └── servers.json               # GUI config
β”œβ”€β”€ docker-compose.yml             # Compose prod
β”œβ”€β”€ docker-compose.override.yml    # Override dev
β”œβ”€β”€ .env.example                   # Env vars
└── README.md

🚨 Troubleshooting

Health Checks

# Check all services
curl http://localhost:8100/health

# Check individual components
curl http://localhost:8101/api/v2/heartbeat  # ChromaDB
curl http://localhost:9100/minio/health/live # MinIO

🀝 Contributing

  1. Fork the repository
  2. Create your 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

Development Guidelines

  • Follow PEP 8 style guide
  • Add tests for new features
  • Update documentation for API changes
  • Use conventional commits for commit messages

πŸ“„ License

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

πŸ†˜ Support

  • Issues: Open an issue on GitHub
  • Documentation: Check the /docs endpoint when server is running
  • Community: Join our discussions in GitHub Discussions

Built with ❀️ using FastAPI and FastMCP

About

No description, website, or topics provided.

Resources

License

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •  

Languages