Elasticsearch Knowledge Graph for MCP
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Elasticsearch Knowledge Graph for MCP
A scalable knowledge graph implementation for Model Context Protocol (MCP) using Elasticsearch as the backend. This implementation is designed to replace the previous JSON file-based approach with a more scalable, performant solution.
Key Features
- Scalable Storage: Elasticsearch provides distributed, scalable storage for knowledge graph entities and relations
- Advanced Search: Full-text search with fuzzy matching and relevancy ranking
- Memory-like Behavior: Tracks access patterns to prioritize recently viewed and important entities
- Import/Export Tools: Easy migration from existing JSON-based knowledge graphs
- Rich Query API: Advanced querying capabilities not possible with the previous implementation
- Admin Tools: Management CLI for inspecting and maintaining the knowledge graph
- Complete CRUD Operations: Full create, read, update, and delete capabilities for entities and relations
- Elasticsearch Query Support: Native support for Elasticsearch query DSL for advanced search capabilities
- Multi-Zone Architecture: Separate memory zones for organizing domain-specific knowledge
- Cross-Zone Relations: Relations between entities in different memory zones
Architecture
The knowledge graph system consists of:
- Elasticsearch Cluster: Core data store for entities and relations
- Knowledge Graph Library: TypeScript interface to Elasticsearch with all core operations
- MCP Server: Protocol-compliant server for AI models to interact with the knowledge graph
- Admin CLI: Command-line tools for maintenance and management
- Import/Export Tools: Utilities for data migration and backup
- Multiple Memory Zones: Ability to partition knowledge into separate zones/indices
Getting Started
Prerequisites
- Node.js 18+
- Docker and Docker Compose
Installation
- Clone the repository:Copy
- Install dependencies:Copy
- Start the Elasticsearch cluster:Copy
- Build the project:Copy
Migration from JSON
If you have an existing JSON-based knowledge graph, you can import it:
Running the MCP Server
Start the MCP server that connects to Elasticsearch:
Configuration
The system can be configured via environment variables:
ES_NODE
: Elasticsearch node URL (default:http://localhost:9200
)ES_USERNAME
: Elasticsearch username (if authentication is enabled)ES_PASSWORD
: Elasticsearch password (if authentication is enabled)MEMORY_FILE_PATH
: Path to memory JSON file (for import/export)KG_DEFAULT_ZONE
: Default memory zone to use (default:default
)KG_INDEX_PREFIX
: Prefix for Elasticsearch indices (default:knowledge-graph
)
Admin CLI Commands
The admin CLI provides tools for managing the knowledge graph:
Memory Zones
The knowledge graph supports multiple memory zones to organize domain-specific knowledge. This allows you to:
- Partition Knowledge: Separate data into different domains (projects, departments, etc.)
- Improve Query Performance: Search within specific zones for faster and more relevant results
- Maintain Context: Keep context-specific information isolated but connected
Working with Zones
Cross-Zone Relations
Entities in different zones can be related to each other. When creating a relation, you can specify the zones for both entities:
Automation Support
For scripting and automation, you can use the --yes
or -y
flag to skip confirmation prompts:
Search Examples
The Elasticsearch-backed knowledge graph provides powerful search capabilities:
Search results include:
- Relevancy scoring
- Highlighted matches showing where the terms were found
- Entity types and observation counts
- Sorted by most relevant first
MCP Server Tools
The MCP server exposes the following tools for interacting with the knowledge graph:
Entity Operations
Tool | Description |
---|---|
create_entities | Create one or more entities in the knowledge graph |
update_entities | Update properties of existing entities |
delete_entities | Delete one or more entities from the knowledge graph |
add_observations | Add observations to an existing entity |
mark_important | Mark an entity as important or not |
Relation Operations
Tool | Description |
---|---|
create_relations | Create relations between entities |
delete_relations | Delete relations between entities |
Query Operations
Tool | Description |
---|---|
search_nodes | Search for entities using Elasticsearch query capabilities |
open_nodes | Get details about specific entities by name |
get_recent | Get recently accessed entities |
Each tool can include an optional memory_zone
parameter to specify which zone to operate on.
Relevancy Ranking
The knowledge graph implements a sophisticated relevancy ranking system that considers:
- Text Relevance: How well entities match the search query
- Recency: Prioritizes recently accessed entities
- Importance: Entities marked as important receive higher ranking
- Usage Frequency: Entities accessed more frequently rank higher
This approach simulates memory-like behavior where important, recent, and frequently accessed information is prioritized.
Benefits Over JSON Implementation
- Scalability: Handles millions of entities efficiently
- Performance: Optimized for fast queries even with large datasets
- Rich Queries: Advanced search capabilities like fuzzy matching and relevancy ranking
- Resiliency: Better handling of concurrent operations
- Observability: Built-in monitoring and diagnostics
- Complete CRUD: Full lifecycle management for entities and relations
License
MIT
You must be authenticated.
Provides a scalable knowledge graph implementation for Model Context Protocol using Elasticsearch, enabling AI models to store and query information with advanced search capabilities, memory-like behavior, and multi-zone architecture.