Sponsored by Deepsite.site

🔍 MCP Server - Vector Search

Created By
miosomos6 months ago
MCP Server to improve LLM context through vector search.
Content

🔍 MCP Server - Vector Search

Python Neo4j FastMCP uv License

A blazing-fast Model Context Protocol (MCP) Server built with FastMCP that seamlessly combines Neo4j's graph database capabilities with advanced vector search using embeddings. This server enables intelligent semantic search across your knowledge graph, allowing you to discover contextually relevant information through natural language queries with lightning speed.

🏗️ Architecture

┌─────────────────┐    ┌──────────────────┐    ┌─────────────────┐
│   MCP Client    │◄──►│   Vector Search  │◄──►│      Neo4j      │
│   (Claude AI)   │    │      Server      │    │     Database    │
└─────────────────┘    └──────────────────┘    └─────────────────┘
                       ┌──────────────────┐
                       │    Embeddings    │
                       └──────────────────┘

🚀 Quick Start

Prerequisites

  • Python 3.8+
  • uv
  • Neo4j Database (v5.0+) with APOC plugin
  • OpenAI API Key

Installation with uv

  1. Install uv (if not already installed)

    # On macOS and Linux
    curl -LsSf https://astral.sh/uv/install.sh | sh
    
    # On Windows
    powershell -c "irm https://astral.sh/uv/install.ps1 | iex"
    
  2. Clone and setup the project

    git clone https://github.com/omarguzmanm/mcp-server-vector-search.git
    cd mcp-server-vector-search
    
    # Create virtual environment and install dependencies
    uv venv
    uv pip install fastmcp neo4j openai python-dotenv sentence-transformers pydantic
    
  3. Environment Configuration

    # Create .env file
    cp .env.example .env
    

    Edit .env with your configurations:

    NEO4J_URI=bolt://localhost:7687
    NEO4J_USERNAME=neo4j
    NEO4J_PASSWORD=your_neo4j_password
    NEO4J_DATABASE=neo4j
    OPENAI_API_KEY=your_openai_api_key
    
  4. Neo4j Vector Index Setup

    // Create vector index for 1536-dimensional OpenAI embeddings
    // If does not works
    CREATE VECTOR INDEX embeddableIndex FOR (n:Document) ON (n.embedding)
    OPTIONS {indexConfig: {
      `vector.dimensions`: 1536,
      `vector.similarity_function`: 'cosine'
    }}
    
  5. Launch the Server

    # Activate virtual environment
    source .venv/bin/activate  # On Linux/macOS
    # or
    .venv\Scripts\activate     # On Windows
    
    # Start the FastMCP server
    python main.py
    

🛠️ Tool

The server exposes a single, powerful tool optimized for vector search:

vector_search_neo4j(
    prompt="Find documents about machine learning and neural networks"
)

What it does:

  • Converts your natural language query into a 1536-dimensional vector using OpenAI
  • Searches your Neo4j vector index for the most semantically similar nodes
  • Returns ranked results with similarity scores

⚙️ Configuration

Environment Variables

VariableDescriptionRequiredDefault
NEO4J_URINeo4j connection URIbolt://localhost:7687
NEO4J_USERNAMENeo4j usernameneo4j
NEO4J_PASSWORDNeo4j passwordpassword
NEO4J_DATABASENeo4j database nameneo4j
OPENAI_API_KEYOpenAI API keyall-MiniLM-L6-v2 model

Neo4j Requirements

  1. APOC Plugin: Essential for advanced graph operations
  2. Vector Index: Must support 1536 dimensions for OpenAI embeddings
  3. Node Structure: Nodes should have embedding properties as vectors

Performance Optimization

  • uv Benefits: 10-100x faster dependency resolution compared to pip
  • FastMCP Advantages: Minimal overhead, optimized for MCP protocol
  • Connection Pooling: Automatic Neo4j connection management
  • Async Operations: Non-blocking I/O for maximum throughput

🤝 Integration with Claude Desktop

MCP Configuration

Add to your Claude Desktop MCP settings:

{
  "mcpServers": {
      "mcp-neo4j-vector-search": {
      "command": "python",
      "args": [
        "you\\server.py",
        "--with",
        "mcp[cli]",
        "--with",
        "neo4j",
        "--with",
        "pydantic"
      ],
      "env": {
        "NEO4J_URI": "bolt://localhost:7687",
        "NEO4J_USERNAME": "neo4j",
        "NEO4J_PASSWORD": "your_password",
        "NEO4J_DATABASE": "neo4j",
        "OPENAI_API_KEY": "your_api_key"
      }
    }
  }
}

🐛 Troubleshooting

Common Issues

  1. "Module not found" errors

    # Reinstall dependencies with uv
    uv pip install --force-reinstall fastmcp neo4j openai
    
  2. "Vector index not found"

    // Check existing indexes
    SHOW INDEXES
    
    // Create if missing
    CREATE VECTOR INDEX embeddableIndex FOR (n:Document) ON (n.embedding)
    OPTIONS {indexConfig: {`vector.dimensions`: 1536, `vector.similarity_function`: 'cosine'}}
    
  3. OpenAI API errors

    # Verify API key
    uv run python -c "
    import os
    from openai import OpenAI
    client = OpenAI(api_key=os.getenv('OPENAI_API_KEY'))
    print('API key is valid!' if client.api_key else 'API key missing!')
    "
    

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Install development dependencies: uv pip install -e ".[dev]"
  4. Make your changes and add tests
  5. Commit: git commit -m 'Add amazing feature'
  6. Push: git push origin feature/amazing-feature
  7. Open a Pull Request

📄 License

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

🙏 Acknowledgments

  • FastMCP - For the incredible MCP framework
  • uv - For blazing-fast Python package management
  • Neo4j - For powerful graph database capabilities
  • OpenAI - For state-of-the-art embedding models
  • Model Context Protocol - For the protocol specification

🚀 Made with ❤️ for the AI and Graph Database community

⬆️ Back to Top

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
ChatWiseThe second fastest AI chatbot™
DeepChatYour AI Partner on Desktop
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
CursorThe AI Code Editor
Tavily Mcp
Playwright McpPlaywright MCP server
WindsurfThe new purpose-built IDE to harness magic
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"
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.
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.
Serper MCP ServerA Serper MCP Server
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
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.
Amap Maps高德地图官方 MCP Server