Sponsored by Deepsite.site

Qdrant MCP Server

Created By
davidwynter9 months ago
A simple MCP server to access Qdrant
Content

A FastAPI client and a MCPServer client for Qdrant access as a service

The file main.py is the entry point and a command line argument selects which server you want to run.

main.py

import argparse
import uvicorn
from fastapi_server import app as fastapi_app
from fastmcp_server import app as fastmcp_app
from config import settings

def run_fastapi():
    """Run the FastAPI server"""
    print(f"Starting FastAPI server on port {settings.port}")
    uvicorn.run(
        fastapi_app,
        host="0.0.0.0",
        port=settings.port,
        log_level="info"
    )

def run_fastmcp():
    """Run the FastMCP server"""
    print(f"Starting FastMCP server on port {settings.mcp_port}")
    fastmcp_app.run(port=settings.mcp_port)

if __name__ == "__main__":
    parser = argparse.ArgumentParser(description="Run Qdrant MCP Server")
    parser.add_argument(
        "--server-type",
        choices=["fastapi", "fastmcp"],
        default="fastmcp",
        help="Type of server to run (default: fastmcp)"
    )
    args = parser.parse_args()

    if args.server_type == "fastapi":
        run_fastapi()
    else:
        run_fastmcp()

Qdrant MCP Server

A dual-protocol server for Qdrant knowledge graph operations, supporting both FastAPI and FastMCP protocols.

Project Structure

src/qdrant_mcpserver/
├── __init__.py
├── config.py          # Configuration settings
├── qdrant_client.py   # Qdrant operations
├── fastapi_server.py  # FastAPI implementation
├── fastmcp_server.py  # FastMCP implementation
└── main.py            # CLI entry point

File Descriptions

config.py

  • Loads environment variables
  • Contains settings for:
    • Qdrant connection (URL, API key)
    • OpenAI API key
    • Collection names
    • Server ports
  • Uses pydantic for validation

qdrant_client.py

  • Implements core Qdrant operations:
    • Collection management
    • Node upsert/delete
    • Vector search
  • Handles embedding generation via OpenAI
  • Provides service layer for both server types

fastapi_server.py

  • FastAPI implementation with:
    • RESTful endpoints
    • CORS middleware
    • OpenAPI documentation
  • Endpoints:
    • POST /nodes/upsert
    • POST /nodes/search
    • DELETE /nodes
    • GET /health

fastmcp_server.py

  • FastMCP implementation with:
    • MCP protocol compliance
    • Authentication support
    • Standardized response formats
  • Same endpoints as FastAPI but with MCP envelope

main.py

  • CLI entry point with:
    • Server type selection (--server-type)
    • Unified logging
    • Port configuration
  • Runs either FastAPI or FastMCP server

Installation

  1. Install Poetry (if not installed):
curl -sSL https://install.python-poetry.org | python3 -
  1. Clone repository:
git clone https://github.com/your-repo/qdrant-mcpserver.git
cd qdrant-mcpserver
  1. Install dependencies:
poetry install
  1. Configure environment:
cp .env.example .env
# Edit .env with your actual values

Usage

Running the Server

# Run FastMCP server (default)
poetry run python -m qdrant_mcpserver.main

# Run FastAPI server
poetry run python -m qdrant_mcpserver.main --server-type fastapi

Environment Variables

VariableRequiredDescription
QDRANT_URLYesQdrant server URL
QDRANT_API_KEYNoQdrant API key
OPENAI_API_KEYYesOpenAI API key
COLLECTION_NAMENoDefault: "knowledge_graph"
PORTNoFastAPI port (default: 8000)
MCP_PORTNoFastMCP port (default: 8080)
MCP_SECRETNoAuthentication secret

API Endpoints

Both servers provide the same endpoints:

  • POST /nodes/upsert - Upsert knowledge graph nodes
  • POST /nodes/search - Semantic search across nodes
  • DELETE /nodes - Delete nodes by IDs
  • GET /health - Health check

Development

Code Formatting

These commands ensure consistent code style:

# Formats code according to Black's style guide (PEP 8 compliant)
poetry run black .

Organizes imports properly (groups standard lib, third-party, local)

poetry run isort .Format code:

poetry run black .
poetry run isort .

Testing

Using pytest for comprehensive test coverage. Test files should mirror the main code structure:

Setup tests

poetry install --with test
poetry run pytest --cov --cov-report=html
# Run all tests
poetry run pytest -v

# Run with coverage report
poetry run pytest --cov=qdrant_mcpserver --cov-report=term-missing
Setup tests (one time):

Type checking:

poetry run mypy .

Deployment

Build production package:

poetry build

Install system-wide:

pip install dist/*.whl

Run as service:

python -m qdrant_mcpserver.main --server-type fastmcp

Key Features:

  1. Flexible Server Selection:

    • CLI argument chooses between FastAPI and FastMCP
    • Shared configuration and Qdrant client
    • Consistent endpoints across both
  2. Comprehensive Documentation:

    • Clear file structure explanation
    • Installation and usage instructions
    • Environment variable reference
    • Development workflow
  3. Production-Ready:

    • Poetry for dependency management
    • Configuration via environment variables
    • Build and deployment instructions
  4. Maintainable Structure:

    • Separation of concerns
    • Shared core functionality
    • Clear development practices

The implementation allows you to switch between server protocols while maintaining the same underlying Qdrant operations.

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Amap Maps高德地图官方 MCP Server
ChatWiseThe second fastest AI chatbot™
Playwright McpPlaywright MCP server
DeepChatYour AI Partner on Desktop
Serper MCP ServerA Serper MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
WindsurfThe new purpose-built IDE to harness magic
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
Tavily Mcp
CursorThe AI Code Editor
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.