Cover image
Try Now
2025-03-31

Un serveur MCP simple pour accéder à Qdrant

3 years

Works with Finder

1

Github Watches

0

Github Forks

0

Github Stars

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

Variable Required Description
QDRANT_URL Yes Qdrant server URL
QDRANT_API_KEY No Qdrant API key
OPENAI_API_KEY Yes OpenAI API key
COLLECTION_NAME No Default: "knowledge_graph"
PORT No FastAPI port (default: 8000)
MCP_PORT No FastMCP port (default: 8080)
MCP_SECRET No Authentication 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.

相关推荐

  • NiKole Maxwell
  • I craft unique cereal names, stories, and ridiculously cute Cereal Baby images.

  • Joshua Armstrong
  • Confidential guide on numerology and astrology, based of GG33 Public information

  • https://suefel.com
  • Latest advice and best practices for custom GPT development.

  • Emmet Halm
  • Converts Figma frames into front-end code for various mobile frameworks.

  • Elijah Ng Shi Yi
  • Advanced software engineer GPT that excels through nailing the basics.

  • https://maiplestudio.com
  • Find Exhibitors, Speakers and more

  • lumpenspace
  • Take an adjectivised noun, and create images making it progressively more adjective!

  • https://appia.in
  • Siri Shortcut Finder – your go-to place for discovering amazing Siri Shortcuts with ease

  • Carlos Ferrin
  • Encuentra películas y series en plataformas de streaming.

  • Yusuf Emre Yeşilyurt
  • I find academic articles and books for research and literature reviews.

  • apappascs
  • Découvrez la collection la plus complète et la plus à jour de serveurs MCP sur le marché. Ce référentiel sert de centre centralisé, offrant un vaste catalogue de serveurs MCP open-source et propriétaires, avec des fonctionnalités, des liens de documentation et des contributeurs.

  • ShrimpingIt
  • Manipulation basée sur Micropython I2C de l'exposition GPIO de la série MCP, dérivée d'Adafruit_MCP230XX

  • jae-jae
  • MCP Server pour récupérer le contenu de la page Web à l'aide du navigateur sans tête du dramwright.

  • HiveNexus
  • Un bot de chat IA pour les petites et moyennes équipes, soutenant des modèles tels que Deepseek, Open AI, Claude et Gemini. 专为中小团队设计的 Ai 聊天应用 , 支持 Deepseek 、 Open Ai 、 Claude 、 Gemini 等模型。

  • patruff
  • Pont entre les serveurs Olllama et MCP, permettant aux LLM locaux d'utiliser des outils de protocole de contexte de modèle

  • ravitemer
  • Un puissant plugin Neovim pour gérer les serveurs MCP (Protocole de contexte modèle)

  • Sysc4lls
  • Lecteur de documentation IDA (Sort-of) MCP Server

    Reviews

    5 (1)
    Avatar
    user_ynqHDKke
    2025-04-16

    I've been utilizing qdrant_mcpserver by davidwynter, and it's truly impressive. The seamless MCP integration and robust features make it a standout choice for anyone needing efficient, scalable data processing solutions. The detailed documentation and active repository on GitHub are extremely helpful. Highly recommend giving it a try!