MCP server for semantic search in Neo4j knowledge graphs
Project description
Semantic Search MCP Server
Universal, schema-agnostic semantic search for any Neo4j knowledge graph.
One tool. Works everywhere. No configuration needed.
What It Does
Searches across ALL vector indexes in your Neo4j database using semantic similarity. Returns anything that matches your natural language query above a threshold.
Works with:
- Any node type
- Any relationship type
- Any schema
- Any knowledge graph with embeddings
Installation
1. Install Dependencies
pip install -r mcp_servers/semantic_search/requirements.txt
2. Configure Environment Variables
# Required
export OPENAI_API_KEY="sk-..."
export NEO4J_PASSWORD="your-password"
# Optional (defaults shown)
export NEO4J_URI="bolt://localhost:7687"
export NEO4J_USER="neo4j"
export EMBEDDING_MODEL="text-embedding-3-small"
3. Register with Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):
{
"mcpServers": {
"semantic-search": {
"command": "python",
"args": ["-m", "mcp_servers.semantic_search.server"],
"cwd": "/path/to/your/e2r-rd",
"env": {
"OPENAI_API_KEY": "sk-...",
"NEO4J_PASSWORD": "your-password"
}
}
}
}
4. Restart Claude Desktop
Usage
The Tool: semantic_search
One simple tool with three parameters:
semantic_search(
query: str, # Natural language query
limit: int = 10, # Max results (max: 100)
threshold: float = 0.7 # Min similarity (0-1)
)
Examples:
semantic_search("database failures")
semantic_search("kubernetes scaling", limit=20)
semantic_search("cache problems", threshold=0.8)
Returns:
Found 5 results matching 'database failures':
1. **Redis Cache** [Service] (similarity: 0.923) - mentioned 15 times
2. **PostgreSQL** [Service] (similarity: 0.887) - mentioned 12 times
3. **cache timeout** [Action] (similarity: 0.845) - mentioned 8 times
4. **database connection pool** [GenericEntity] (similarity: 0.821)
5. **connection failures** [Metric] (similarity: 0.798) - mentioned 6 times
How It Works
- Auto-discovers all vector indexes in your database
- Generates one embedding for your query (via OpenAI)
- Searches all indexes in parallel
- Filters by threshold
- Returns top results sorted by similarity
No schema knowledge required!
Prerequisites
Your Neo4j database needs:
- Nodes with embeddings - Any nodes with an
embeddingproperty (list of floats) - Vector indexes - Created on the embedding properties
Create Vector Indexes
CREATE VECTOR INDEX my_index_name IF NOT EXISTS
FOR (n:MyNodeLabel) ON (n.embedding)
OPTIONS {indexConfig: {
`vector.dimensions`: 1536,
`vector.similarity_function`: 'cosine'
}}
Repeat for each node type that has embeddings.
Testing
# Set environment variables
export OPENAI_API_KEY="sk-..."
export NEO4J_PASSWORD="your-password"
# Run test script
python mcp_servers/semantic_search/test_search.py
Troubleshooting
No results found
Check:
- Neo4j is running
- Vector indexes are created (
SHOW INDEXESin Neo4j) - Nodes have embeddings populated
- Try lowering the threshold (default: 0.7)
Connection errors
Check:
- Neo4j URI is correct
- Neo4j password is correct
- Network connectivity
- Neo4j is running:
docker psor Neo4j Desktop
MCP server not appearing
Check:
- Claude Desktop config JSON is valid
cwdpath is absolute and correct- Claude Desktop was restarted
- Check Claude Desktop logs for errors
Architecture
semantic_search/
├── config.py # Environment configuration
├── semantic_search.py # Core search engine
├── server.py # MCP server
├── test_search.py # Test script
└── README.md # This file
Key Features
- Schema-agnostic: Discovers indexes at runtime
- Single embedding: Generated once, used everywhere
- Parallel search: Searches all indexes simultaneously
- Threshold filtering: Only returns good matches
- Error resilient: Continues if one index fails
- Simple interface: One tool, three parameters
Configuration Reference
Environment Variables
# Required
OPENAI_API_KEY # OpenAI API key for embeddings
NEO4J_PASSWORD # Neo4j password
# Optional
NEO4J_URI # Default: bolt://localhost:7687
NEO4J_USER # Default: neo4j
EMBEDDING_MODEL # Default: text-embedding-3-small
DEFAULT_LIMIT # Default: 10
MAX_LIMIT # Default: 100
Tool Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
query |
string | required | Natural language query |
limit |
integer | 10 | Max results (max: 100) |
threshold |
float | 0.7 | Min similarity (0-1) |
Threshold Guide
- 0.9+: Very strict, near-exact matches
- 0.8-0.9: Strong semantic similarity
- 0.7-0.8: Good matches (default range)
- 0.6-0.7: Loose matches, more results
- <0.6: Very loose, may include noise
Examples
Basic Search
semantic_search("monitoring alerts")
Strict Matching
semantic_search("postgresql database", threshold=0.85)
Broad Exploration
semantic_search("cloud infrastructure", limit=50, threshold=0.6)
Development
To modify the tool:
- Edit
semantic_search.pyto change search logic - Edit
server.pyto change tool interface - Run
test_search.pyto validate
License
Part of the e2r-rd project.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file neo4j_semantic_search_mcp-0.1.0.tar.gz.
File metadata
- Download URL: neo4j_semantic_search_mcp-0.1.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b707590338cb4094487e3c27f7d26ba13325911a5f9dc724a76fbba88694ffdc
|
|
| MD5 |
f057316185e4fb5791916d26c08a2a45
|
|
| BLAKE2b-256 |
aadcab44b1b08581276e1fdf84c5bd3d6ce5e57c083b4b5b32d1b0b33d2f1691
|
File details
Details for the file neo4j_semantic_search_mcp-0.1.0-py3-none-any.whl.
File metadata
- Download URL: neo4j_semantic_search_mcp-0.1.0-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e3cc35d9dbb1d17c157dec53c2d57cd9cd12cb56373b3ddcf4e18c7a8ef4654d
|
|
| MD5 |
d75c5dde4cbeec722b862068deb1678e
|
|
| BLAKE2b-256 |
eadbd613a453882e7bbc85059714de778d1681c1b66472721970078e3c48de0d
|