Two example clients that demonstrate different approaches to connecting to the neo4j-cypher MCP server:
- Basic Client with Ollama (
mcp_neo4j_client.py) - Simple client using Ollama for one-shot query generation - Interactive Agent with ReAct Pattern (
interactive_agent.py) - Advanced agent using Ollama with schema context for interactive queries (same pattern as the backend)
This client is located in sample-client/ directory.
- Python 3.10+
uvpackage manager (>= 0.4.0)- Neo4j MCP server running in HTTP mode
- Ollama running locally with the
gpt-oss:120b-cloudmodel
# Using the standalone installer (recommended)
curl -LsSf https://astral.sh/uv/install.sh | sh
# Or using Homebrew on macOS
brew install uv
# Or using pip
pip install uvNavigate to the sample-client directory:
cd sample-clientThen sync dependencies (this creates the venv and installs everything):
# Sync dependencies - creates .venv and installs all dependencies
uv syncThis will:
- Create a
.venvvirtual environment if it doesn't exist - Install all dependencies from
pyproject.toml - Generate/update
uv.lockfor reproducible builds
You can also run directly without syncing:
uv run mcp_neo4j_client.pyThis automatically handles the environment and dependencies.
Using Docker (recommended):
docker run -p 8000:8000 \
-e NEO4J_URI=bolt://host.docker.internal:7687 \
-e NEO4J_USERNAME=neo4j \
-e NEO4J_PASSWORD=password \
-e NEO4J_TRANSPORT=http \
-e NEO4J_MCP_SERVER_HOST=0.0.0.0 \
-e NEO4J_MCP_SERVER_PORT=8000 \
-e NEO4J_MCP_SERVER_PATH=/api/mcp/ \
mcp/neo4j-cypher:latestOr using the local server from ../mcp-neo4j/servers/mcp-neo4j-cypher/:
cd ../mcp-neo4j/servers/mcp-neo4j-cypher
uv run mcp-neo4j-cypher \
--transport http \
--server-host 127.0.0.1 \
--server-port 8000 \
--server-path /api/mcp/Make sure you have Ollama installed and the model available:
ollama pull gpt-oss:120b-cloud
ollama serveThe simplest client that generates a single query:
# Run directly - uv handles everything
uv run mcp_neo4j_client.py
# Or use the installed command
uv run mcp-neo4j-clientWhat it does:
- Fetches Neo4j schema from MCP server
- Uses Ollama to generate a Cypher query for finding companies
- Executes the query and displays results
An interactive agent that demonstrates the same pattern used in the backend:
# Run the interactive agent (uses Ollama gpt-oss:120b-cloud)
uv run interactive-agent
# Or run directly
uv run interactive_agent.py
# Use a different Ollama model
OLLAMA_MODEL=llama3.1 uv run interactive-agentWhat it does:
- Connects to MCP Neo4j server
- Fetches the complete database schema
- Creates a ReAct agent with schema-enhanced context
- Enters an interactive loop where you can ask natural language questions
- Translates your questions to Cypher queries using the schema
- Executes queries and presents formatted results
Example queries you can try:
- "Show me all the node types in the database"
- "List all companies"
- "Find all relationships in the graph"
- "Show me the first 5 records of any type"
Features:
- ✅ Schema-aware query generation (uses exact property names)
- ✅ ReAct pattern for reasoning about queries
- ✅ Interactive chat loop for multiple queries
- ✅ Well-formatted markdown responses
- ✅ Same pattern as the production backend in
databricks-neo4j-mcp-demo
Create a .env file from the example:
cp .env.example .envEnvironment variables:
MCP_SERVER_URL: URL of the MCP server (default:http://localhost:8000/api/mcp/)OLLAMA_MODEL: Ollama model to use for interactive agent (default:gpt-oss:120b-cloud)
# Add a new dependency
uv add package-name
# Add a development dependency
uv add --dev pytest
# Add with version constraint
uv add "package-name>=1.0.0"# Update all dependencies
uv sync --upgrade
# Update a specific package
uv sync --upgrade-package package-nameThe uv.lock file is automatically generated and should be committed to version control. It ensures reproducible builds across different environments.
To verify everything is set up correctly:
-
Check that the MCP server is running:
curl http://localhost:8000/api/mcp/
-
Check that Ollama is running and has the model:
ollama list | grep gpt-oss:120b-cloud -
Run the client:
uv run mcp_neo4j_client.py
This client is based on the examples from:
/Users/ryanknight/projects/graphathon-snippets/examples/mcp/client- MCP Python SDK streamable HTTP transport