Elasticsearch Knowledge Graph for MCP

Elasticsearch Knowledge Graph for MCP

A powerful MCP memory using a knowledge graph powered by elastic search - j3k0/mcp-elastic-memory

知识与记忆
数据库
搜索
TypeScript
访问服务器

README

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:

  1. Elasticsearch Cluster: Core data store for entities and relations
  2. Knowledge Graph Library: TypeScript interface to Elasticsearch with all core operations
  3. MCP Server: Protocol-compliant server for AI models to interact with the knowledge graph
  4. Admin CLI: Command-line tools for maintenance and management
  5. Import/Export Tools: Utilities for data migration and backup
  6. Multiple Memory Zones: Ability to partition knowledge into separate zones/indices

Getting Started

Prerequisites

  • Node.js 18+
  • Docker and Docker Compose

Installation

  1. Clone the repository:

    git clone https://github.com/mcp-servers/mcp-servers.git cd mcp-servers/memory

  2. Install dependencies:

  3. Start the Elasticsearch cluster:

  4. Build the project:

Migration from JSON

If you have an existing JSON-based knowledge graph, you can import it:

node dist/admin-cli.js init node dist/admin-cli.js import memory.json

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:

Initialize Elasticsearch index

node dist/admin-cli.js init

Import data from JSON file to a specific zone

node dist/admin-cli.js import memory.json [zone]

Export data from a specific zone to JSON file

node dist/admin-cli.js export backup.json [zone]

Backup all zones and relations

node dist/admin-cli.js backup full-backup.json

Restore from a full backup

node dist/admin-cli.js restore full-backup.json [--yes]

Show statistics about all zones or a specific zone

node dist/admin-cli.js stats [zone]

Search the knowledge graph with optional zone parameter

node dist/admin-cli.js search "search query" [zone]

Show details about a specific entity

node dist/admin-cli.js entity "John Smith" [zone]

Show relations for a specific entity

node dist/admin-cli.js relations "John Smith" [zone]

List all memory zones

node dist/admin-cli.js zones list

Add a new memory zone

node dist/admin-cli.js zones add projectX "Project X knowledge zone"

Delete a memory zone

node dist/admin-cli.js zones delete projectX [--yes]

Show statistics for a specific zone

node dist/admin-cli.js zones stats projectX

Reset all zones or a specific zone

node dist/admin-cli.js reset [zone] [--yes]

Show help

node dist/admin-cli.js help

Memory Zones

The knowledge graph supports multiple memory zones to organize domain-specific knowledge. This allows you to:

  1. Partition Knowledge: Separate data into different domains (projects, departments, etc.)
  2. Improve Query Performance: Search within specific zones for faster and more relevant results
  3. Maintain Context: Keep context-specific information isolated but connected

Working with Zones

Create a new zone

node dist/admin-cli.js zones add projectX "Project X knowledge zone"

List all zones

node dist/admin-cli.js zones list

Import data into a specific zone

node dist/admin-cli.js import project-data.json projectX

Search within a specific zone

node dist/admin-cli.js search "feature" projectX

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:

{ "type": "relation", "from": "Project Feature", "fromZone": "projectX", "to": "General Concept", "toZone": "default", "relationType": "implements" }

Automation Support

For scripting and automation, you can use the --yes or -y flag to skip confirmation prompts:

Reset without confirmation

node dist/admin-cli.js reset --yes

Delete a zone without confirmation

node dist/admin-cli.js zones delete projectX --yes

Restore from backup without confirmation

node dist/admin-cli.js restore backup.json --yes

Search Examples

The Elasticsearch-backed knowledge graph provides powerful search capabilities:

Basic search

node dist/admin-cli.js search "cordova plugin"

Search in a specific zone

node dist/admin-cli.js search "feature" projectX

Fuzzy search (will find "subscription" even with typo)

node dist/admin-cli.js search "subscrption"

Person search

node dist/admin-cli.js search "Jean"

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:

  1. Text Relevance: How well entities match the search query
  2. Recency: Prioritizes recently accessed entities
  3. Importance: Entities marked as important receive higher ranking
  4. 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

推荐服务器

Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选
Playwright MCP Server

Playwright MCP Server

提供一个利用模型上下文协议的服务器,以实现类人浏览器的自动化,该服务器使用 Playwright,允许控制浏览器行为,例如导航、元素交互和滚动。

精选
本地
TypeScript
Apple MCP Server

Apple MCP Server

通过 MCP 协议与 Apple 应用(如“信息”、“备忘录”和“通讯录”)进行交互,从而使用自然语言发送消息、搜索和打开应用内容。

精选
本地
TypeScript
contentful-mcp

contentful-mcp

在你的 Contentful Space 中更新、创建、删除内容、内容模型和资源。

精选
TypeScript
Supabase MCP Server

Supabase MCP Server

一个模型上下文协议(MCP)服务器,它提供对 Supabase 管理 API 的编程访问。该服务器允许 AI 模型和其他客户端通过标准化的接口来管理 Supabase 项目和组织。

精选
JavaScript
serper-search-scrape-mcp-server

serper-search-scrape-mcp-server

这个 Serper MCP 服务器支持搜索和网页抓取,并且支持 Serper API 引入的所有最新参数,例如位置信息。

精选
TypeScript
The Verge News MCP Server

The Verge News MCP Server

提供从The Verge的RSS feed获取和搜索新闻的工具,允许用户获取今日新闻、检索过去一周的随机文章,以及在最近的Verge内容中搜索特定关键词。

精选
TypeScript