EP

evangstav/python-memory-mcp-server

效率工作流

本页由 AI 翻译,技术细节请以原文为准。 查看原文

16 stars 7 forks 质量 50 趋势 21MIT

A Model Context Protocol (MCP) server that provides knowledge graph functionality for managing entities, relations, and observations in memory, with strict validation rules to maintain data...

概览

A Model Context Protocol (MCP) server that provides knowledge graph functionality for managing entities, relations, and observations in memory, with strict validation rules to maintain data consistency. - Must start with a lowercase letter - Can contain lowercase letters, numbers, and hyphens - Maximum length of 100 characters - Must be unique within the graph - Example valid names: python-project, meeting-notes-2024, user-john The following entity types are supported: - person: Human entities - concept: Abstract ideas or principles - project: Work initiatives or tasks - document: Any form of documentation - tool: Software tools or utilities - organization: Companies or groups - location: Physical or virtual places - event: Time-bound occurrences - Non-empty strings - Maximum length of 500 characters - Must be unique per entity - Should be factual and objective statements - Include timestamp when relevant The following relation types are supported: - knows: Person to person...

README

以下为原文 README 节选,完整内容请查看原文。

Memory MCP Server

A Model Context Protocol (MCP) server that provides knowledge graph functionality for managing entities, relations, and observations in memory, with strict validation rules to maintain data consistency.

Installation

Install the server in Claude Desktop:

mcp install main.py -v MEMORY_FILE_PATH=/path/to/memory.jsonl

Data Validation Rules

Entity Names

  • Must start with a lowercase letter
  • Can contain lowercase letters, numbers, and hyphens
  • Maximum length of 100 characters
  • Must be unique within the graph
  • Example valid names: python-project, meeting-notes-2024, user-john

Entity Types

The following entity types are supported:

  • person: Human entities
  • concept: Abstract ideas or principles
  • project: Work initiatives or tasks
  • document: Any form of documentation
  • tool: Software tools or utilities
  • organization: Companies or groups
  • location: Physical or virtual places
  • event: Time-bound occurrences

Observations

  • Non-empty strings
  • Maximum length of 500 characters
  • Must be unique per entity
  • Should be factual and objective statements
  • Include timestamp when relevant

Relations

The following relation types are supported:

  • knows: Person to person connection
  • contains: Parent/child relationship
  • uses: Entity utilizing another entity
  • created: Authorship/creation relationship
  • belongs-to: Membership/ownership
  • depends-on: Dependency relationship
  • related-to: Generic relationship

Additional relation rules:

  • Both source and target entities must exist
  • Self-referential relations not allowed
  • No circular dependencies allowed
  • Must use predefined relation types

Usage

The server provides tools for managing a knowledge graph:

Get Entity

result = await session.call_tool("get_entity", {
    "entity_name": "example"
})
if not result.success:
    if result.error_type == "NOT_FOUND":
        print(f"Entity not found: {result.error}")
    elif result.error_type == "VALIDATION_ERROR":
        print(f"Invalid input: {result.error}")
    else:
        print(f"Error: {result.error}")
else:
    entity = result.data
    print(f"Found entity: {entity}")

Get Graph

result = await session.call_tool("get_graph", {})
if result.success:
    graph = result.data
    print(f"Graph data: {graph}")
else:
    print(f"Error retrieving graph: {result.error}")

Create Entities

# Valid entity creation
entities = [
    Entity(
        name="python-project",  # Lowercase with hyphens
        entityType="project",   # Must be a valid type
        observations=["Started development on 2024-01-29"]
    ),
    Entity(
        name="john-doe",
        entityType="person",
        observations=["Software engineer", "Joined team in 2024"]
    )
]
在 GitHub 查看完整 README

安装

This server does not publish a one-line install command.

Open the repository installation guide 新手?先看 mcpskill.org 教程 →