kgraph-mcp
Enables dynamic entity and relationship management, natural-language/Cypher querying, graph analytics, and subgraph retrieval against a Neo4j graph database.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
๐ KnowledgeGraphMCP - Model Context Protocol Knowledge Graph System
A complete Model Context Protocol (MCP)-based system that enables LLMs to dynamically construct, query, and update knowledge graphs using Neo4j or Memgraph as the backend. Build complex knowledge graphs through natural language without hardcoding entities or relationships.
๐ Overview
KnowledgeGraphMCP allows AI assistants to interact with graph databases in real-time, enabling:
Dynamic Entity Management: Add entities (nodes) on-the-fly with custom types and metadata
Relationship Creation: Connect entities with typed relationships
Natural Language Querying: Convert natural language to Cypher queries automatically
Graph Analytics: Get insights, statistics, and find patterns in your knowledge graph
External Data Integration: Fetch and integrate data from external APIs
Real-time Updates: Modify graph structure based on LLM interactions
Related MCP server: Neo4j Agent Memory MCP Server
โจ Features
๐ Dynamic Graph Construction - No hardcoded schemas, create entities and relationships on demand
๐ง Natural Language Interface - Query graphs using plain English
๐ Built-in Analytics - Graph statistics, top connections, distribution analysis
๐ External Data Integration - Pull data from APIs and automatically create graph structures
๐ Security First - Input sanitization and safe query validation
๐ Production Ready - Connection pooling, error handling, and graceful shutdowns
๐ Multiple Graph DBs - Supports both Neo4j and Memgraph
๐ฏ Domain Agnostic - Works for legal aid, startups, research, and any domain
๐๏ธ Architecture
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ LLM Client โ
โ (Issues natural language commands) โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ MCP Protocol (JSON-RPC over stdio)
โ
โโโโโโโโโโโโโโโโโโดโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Knowledge Graph MCP Server โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Tools: addEntity, addRelationship, queryGraph, โ โ
โ โ searchEntities, graphAnalytics, etc. โ โ
โ โโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ โ
โ โโโโโโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โ โ Database Connection Manager โ โ
โ โ (Neo4j Driver / Memgraph) โ โ
โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โ Bolt Protocol
โ
โโโโโโโโโโโโโโโโโโผโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Neo4j / Memgraph Database โ
โ (Graph storage with Cypher query language) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ๐ Prerequisites
Node.js 18+
Neo4j or Memgraph database (local or cloud)
An MCP-compatible client (Claude Desktop, Cline, etc.)
๐ Installation
Quick Start with npx (Recommended)
Configure your MCP client:
{
"mcpServers": {
"knowledge-graph": {
"command": "npx",
"args": ["-y", "kgraph-mcp"],
"env": {
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USERNAME": "neo4j",
"NEO4J_PASSWORD": "your_password"
}
}
}
}That's it! The server will auto-connect to your graph database.
Local Development
For contributing or modifying the code:
git clone https://github.com/gyash1512/KnowledgeGraphMCP.git
cd KnowledgeGraphMCP
npm install
npm run buildDatabase Setup
Using Neo4j Desktop (Easiest)
Download Neo4j Desktop
Create a new project and database
Start the database (default:
bolt://localhost:7687)Note your username and password
Using Docker
# Neo4j
docker run -d \
--name neo4j \
-p 7474:7474 -p 7687:7687 \
-e NEO4J_AUTH=neo4j/your_password \
neo4j:latest
# Or Memgraph
docker run -d \
--name memgraph \
-p 7687:7687 \
memgraph/memgraph:latest๐ฎ Usage
MCP Configuration
For Claude Desktop:
Edit your Claude Desktop config file:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
{
"mcpServers": {
"knowledge-graph": {
"command": "npx",
"args": ["-y", "kgraph-mcp"],
"env": {
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USERNAME": "neo4j",
"NEO4J_PASSWORD": "your_password"
}
}
}
}For local development:
{
"mcpServers": {
"knowledge-graph": {
"command": "node",
"args": ["./dist/server.js"],
"cwd": "/absolute/path/to/KnowledgeGraphMCP",
"env": {
"NEO4J_URI": "bolt://localhost:7687",
"NEO4J_USERNAME": "neo4j",
"NEO4J_PASSWORD": "your_password"
}
}
}
}๐ Available Tools
1. addEntity
Add a new entity (node) to the knowledge graph.
Parameters:
name(string, required): Unique entity nametype(string, required): Entity type/categorymetadata(object, optional): Additional properties
Example:
{
"name": "NutriGuide AI",
"type": "Startup",
"metadata": {
"founded": "2024",
"founder": "Yash Gupta",
"location": "Delhi",
"industry": "HealthTech"
}
}2. addRelationship
Create a relationship between two existing entities.
Parameters:
source(string, required): Source entity nametarget(string, required): Target entity nametype(string, required): Relationship typemetadata(object, optional): Relationship properties
Example:
{
"source": "NutriGuide AI",
"target": "Yash Gupta",
"type": "FOUNDED_BY",
"metadata": {
"date": "2024-01-15",
"role": "CEO"
}
}3. queryGraph
Query the graph using natural language or Cypher.
Parameters:
query(string, required): Natural language or Cypher queryuseNaturalLanguage(boolean, optional): Auto-convert to Cypher (default: true)
Examples:
// Natural language
{
"query": "Show all startups founded by Yash Gupta"
}
// Cypher query
{
"query": "MATCH (s:Startup)-[:FOUNDED_BY]->(p:Person {name: 'Yash Gupta'}) RETURN s",
"useNaturalLanguage": false
}4. searchEntities
Search for entities by name or type.
Parameters:
searchTerm(string, required): Search termentityType(string, optional): Filter by type
5. graphAnalytics
Get comprehensive graph statistics.
Parameters:
nodeType(string, optional): Filter by node typerelationshipType(string, optional): Filter by relationship type
Returns:
Node and relationship counts
Type distributions
Top connected entities
Graph density and average degree
6. externalData
Fetch data from external APIs and integrate into graph.
Parameters:
source(string, required): API source namequery(string, required): Query parametersendpoint(string, optional): Custom API endpointapiKey(string, optional): API authentication
7. deleteEntity
Remove an entity and its relationships.
Parameters:
name(string, required): Entity name to delete
8. getSubgraph
Get a subgraph starting from a specific entity.
Parameters:
entityName(string, required): Starting entitymaxDepth(number, optional): Max traversal depth (default: 2)relationshipTypes(array, optional): Filter relationship types
๐ก Example Queries
Example 1: Building a Startup Ecosystem
Natural language commands:
1. "Add entity: Startup 'NutriGuide AI' with founder 'Yash Gupta'"
2. "Add entity: Investor 'Sequoia Capital' with metadata type 'VC Firm'"
3. "Add relationship: 'Sequoia Capital' invested in 'NutriGuide AI' with amount '1M USD'"
4. "Show all startups and their investors"Expected workflow:
Creates Startup node
Creates Investor node
Creates INVESTED_IN relationship
Returns graph showing connections
Example 2: Legal Aid System
Natural language commands:
1. "Add entity: Prisoner 'John Doe' in 'Tihar Jail'"
2. "Add entity: Volunteer 'Jane Smith' specializing in 'criminal law'"
3. "Add relationship: 'Jane Smith' assigned to 'John Doe'"
4. "Show all prisoners connected to volunteers in Delhi"Example 3: Knowledge Graph Analytics
Query:
"Get analytics for all Person entities"Returns:
{
"nodeCount": 150,
"relationshipCount": 320,
"nodeTypeDistribution": {
"Person": 150
},
"topConnectedNodes": [
{
"name": "Yash Gupta",
"type": "Person",
"connectionCount": 25
}
],
"averageDegree": 4.27,
"graphDensity": 0.0143
}๐ง API Response Schemas
Entity Object
{
id: string; // Database-generated ID
name: string; // Entity name
type: string; // Entity type
metadata: object; // Custom properties
createdAt: string; // ISO timestamp
updatedAt: string; // ISO timestamp
}Relationship Object
{
id: string; // Database-generated ID
source: string; // Source entity name
target: string; // Target entity name
type: string; // Relationship type
metadata: object; // Custom properties
createdAt: string; // ISO timestamp
}Query Result
{
nodes: Entity[]; // Matching nodes
relationships: Relationship[]; // Matching relationships
metadata: {
executionTime: number; // Query time in ms
query: string; // Executed query
resultCount: number; // Number of results
}
}๐ฏ Use Cases
Startup/Investment Tracking
Map startup founders, investors, and funding rounds
Track connections between companies
Analyze investment patterns
Legal Aid Management
Connect prisoners with legal volunteers
Track case assignments and progress
Map legal case relationships
Research Networks
Build academic collaboration graphs
Track paper citations and co-authorships
Find research communities
Social Networks
Map person-to-person relationships
Analyze influence and connections
Build organizational hierarchies
Knowledge Management
Create interconnected knowledge bases
Map concepts and relationships
Build decision trees
๐ ๏ธ Development
Project Structure
KnowledgeGraphMCP/
โโโ src/
โ โโโ server.ts # Main MCP server
โ โโโ database.ts # Graph DB connection
โ โโโ types.ts # TypeScript types
โ โโโ utils.ts # Utility functions
โ โโโ cli.ts # CLI entry point
โโโ dist/ # Compiled output
โโโ package.json
โโโ tsconfig.json
โโโ README.mdBuilding
npm run build # Compile TypeScript
npm run watch # Watch mode for development
npm run clean # Clean dist folderTesting
# Start the server locally
npm run start
# Or with development build
npm run dev๐ Security
Input Sanitization: All user inputs are sanitized
Query Validation: Dangerous Cypher operations are blocked
Connection Security: Supports encrypted connections
Environment Variables: Credentials stored securely in .env
๐ Troubleshooting
Database Connection Failed
Verify Neo4j/Memgraph is running:
http://localhost:7474Check credentials in config
Ensure bolt port (7687) is accessible
Entity Already Exists
Entity names must be unique
Search for existing entity first
Update metadata instead of recreating
Query Returns Empty
Verify entities exist: use
searchEntitiesCheck relationship types match
Try simpler query first
๐ Support
For issues, questions, or contributions:
Open an issue on GitHub
Check Neo4j Documentation
Review MCP Specification
๐ค Contributing
Contributions welcome! Please read CONTRIBUTING.md for guidelines.
๐ License
MIT License - see LICENSE for details.
๐ Acknowledgments
Built with Model Context Protocol SDK
Uses Neo4j graph database
Compatible with Memgraph
Inspired by the research at ResearchMCP
Built with โค๏ธ using TypeScript, MCP, and Graph Databases
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelogโฆ
This server cannot be deployed
Maintenance
Related MCP Connectors
Persistent knowledge graph for AI agents. Remember, recall, and forget facts.
Persistent memory and knowledge graphs for AI agents. Hybrid search, context checkpoints, and more.
End-to-end agent-managed company brain. Docs, diagrams, plans, databases, agents, Knowledge Graph.
Shared long-term memory for AI agents: save and recall context as a searchable knowledge graph.
Related MCP Servers
- FlicenseNot gradedqualityDmaintenanceEnables storage and retrieval of knowledge in a graph database format, allowing users to create, update, search, and delete entities and relationships in a Neo4j-powered knowledge graph through natural language.5-
- AlicenseAqualityCmaintenanceEnables AI agents to store, retrieve, and connect information in a Neo4j graph database as persistent memory, with semantic relationships, natural language search, and temporal tracking across conversations.9150 npm67MIT
- AlicenseBqualityDmaintenanceEnables storing and querying memories in a Neo4j knowledge graph with automatic entity extraction. Supports adding episodes, searching entities and relationships, and managing graph data through natural language.8MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to interact with Neo4j graph databases through natural language, supporting Cypher queries, schema management, data manipulation, and graph algorithms.MIT