This repo provides a simple example of how to build a ReAct agent with MCP and local tools.
Specifically this repo builds a Text2Cypher ReAct agent with the Neo4j Cypher MCP Server. The agent also has extended capabilities by exposing local tools for it to use.
A conversational AI agent that connects to a Neo4j Movies database and can answer movie-related questions using natural language. Built with LangGraph's implementation of a ReAct agent, the Neo4j Cypher MCP server, and a custom movie recommendations tool.
- Natural Language to Cypher: Ask questions in plain English and get answers from your Neo4j database
- ReAct Agent Pattern: Uses reasoning and acting loops for complex reasoning
- Schema-Aware: Automatically retrieves and uses database schema for accurate query generation
- Interactive CLI: Chat-based interface for easy interaction
- Python 3.10 or higher
- Neo4j Aura account or local Neo4j instance with Movies database
- OpenAI API key
uv
package manager (recommended) orpip
-
Install uv (if not already installed):
pip install uv
-
Clone and setup the project:
git clone neo4j-field/text2cypher-react-agent-example cd text2cypher-react-agent-example
-
Install dependencies:
uv sync
-
Clone and setup the project:
git clone neo4j-field/text2cypher-react-agent-example cd text2cypher-react-agent-example
-
Create and activate virtual environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate
-
Install dependencies:
pip install -r requirements.txt
-
Copy the example environment file:
cp .env.example .env
-
Edit
.env
with your credentials:OPENAI_API_KEY=your_openai_api_key_here NEO4J_USERNAME=neo4j NEO4J_PASSWORD=your_neo4j_password NEO4J_URI=neo4j+s://your-instance.databases.neo4j.io NEO4J_DATABASE=neo4j
- LangGraph ReAct Agent: Implements reasoning and acting loops for complex queries
- Neo4j Cypher MCP Server: Provides schema introspection and query execution
- Custom Recommendations Tool: Custom tool for movie recs
- Interactive CLI: Command-line chat interface
get_neo4j_schema
: Retrieves database schema for informed query writingread_neo4j_cypher
: Executes read-only Cypher queries against the databasefind_movie_recommendations
: Custom recommendation engine that finds movies liked by users who also enjoyed a target movie
make run-agent-uv
# or
uv run python3 agent.py
make run-agent
# or
python3 agent.py
Once running, you can ask questions like:
- "What movies are in the database?"
- "Tell me about The Matrix"
- "Recommend me some films like The Dark Knight."
To exit the agent, type any of:
exit
quit
q
make format
Core Libraries:
langchain
- LangChain frameworklangchain-mcp-adapters
- MCP (Model Context Protocol) adapterslangchain-openai
- OpenAI integrationlanggraph
- Graph-based agent frameworkneo4j
- Neo4j Python driveropenai
- OpenAI API clientpydantic
- Data validation
Development:
ruff
- Code formatting and linting
Connection Issues:
- Verify your Neo4j credentials in
.env
- Ensure your Neo4j instance is running and accessible
OpenAI Issues:
- Verify your OpenAI API key is valid
- Check your API usage limits
MCP Server Issues:
- Ensure
uvx
is available in your PATH - The agent automatically installs
[email protected]
via uvx
Python Issues:
- Ensure Python 3.10+ is installed
- Try recreating your virtual environment if using pip
This project is provided as an example for educational and demonstration purposes.