Insert-data-in-to-Neo4j-mcp-server

nargesghv/Insert-data-in-to-Neo4j-mcp-server

3.1

If you are the rightful owner of Insert-data-in-to-Neo4j-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

This project integrates natural language processing with a Neo4j graph database using a Model Context Protocol (MCP) server.

Tools
1
Resources
0
Prompts
0

📘 Inserting Nodes and realations in to Neo4j(Graph Database) by applying MCP Server

A project that accepts natural language (NL) queries from Claude Desktop via MCP and uses GPT-4o + LangChain to extract structured node information and store it in a Neo4j database.


🚀 Features

  • Neo4j graph database: stores nodes extracted from NL input.
  • MCP server (FastMCP): offers an LLM-exposable tool createNode.
  • LangChain + GPT‑4o: parses NL into structured Neo4jNode.
  • Claude Desktop integration: uses MCP protocol to call your tool interactively.

🛠️ Prerequisites

  • Python 3.10+
  • Neo4j Community or Enterprise Edition (locally or via Aura)
  • Claude Desktop installed
  • uv CLI (optional but helpful for running MCP apps)

🗄️ Step 1: Install & Set Up Neo4j

  1. Download and install Neo4j Desktop from neo4j.com.

  2. Create a new database using the Neo4j Desktop UI or Neo4j Browser:

    CREATE DATABASE mydb IF NOT EXISTS;
    
  3. Set credentials during creation (neo4j username and password).

  4. Get the Bolt connection URI, typically:

    bolt://localhost:7687
    

🧩 Step 2: Project Configuration

  1. Clone or create this project directory.

  2. Create a .env file in the project root:

    uri=bolt://localhost:7687
    username=neo4j
    pwd=your_password
    
  3. Install dependencies:

    pip install neo4j neo4j_graphrag langchain langchain-core langchain-openai mcp python-dotenv
    

🧱 Step 3: Code Overview

The server.py file includes:

  • Prompt definition using LangChain's PromptTemplate and PydanticOutputParser
  • Tool chain with GPT‑4o to convert NL to structured node
  • FastMCP server exposing the createNode tool
  • Neo4jWriter to persist graph nodes

🧪 Step 4: Run the MCP Server

You can run the MCP server using Python directly:

fastmcp install server.py

Or optionally using uv:

uv add mcp
uv run python server.py

💬 Step 5: Use with Claude Desktop (Client)

  1. Launch Claude Desktop.

  2. Connect it to your running MCP server (via standard I/O or HTTP).

  3. Send a message like:

    Create a person node with name Alice and age 30
    
  4. The tool will:

    • Generate a Neo4jNode from GPT‑4o

    • Write it to the Neo4j database

    • Respond with:

      ✅ Node successfully added to db — Label: Person, Properties: name:Alice, age:30
      

🔍 Step 6: Inspect Data in Neo4j

You can explore the created nodes using Neo4j Browser or Neo4j Bloom:

MATCH (n) RETURN n;

🔧 Step 7: Customize & Extend

  • Add more tools (e.g., createRelationship, queryGraph)
  • Integrate a FastAPI or Gradio UI for user interaction
  • Use Claude with structured function calling via MCP

📚 References


✅ Summary

This project brings together:

  • 💬 Natural Language → Graph with GPT‑4o
  • 📡 MCP tool exposed to Claude Desktop
  • 🌐 Neo4j for persistent graph storage
  • 🔁 Fully extendable graph-based RAG architecture

For any issues or ideas, feel free to open an issue or PR!