Skip to content
Conduit

mcp server

DocSync-MemGuard

Code-Document Linked Memory Guard System - Bridging source code and documentation with bidirectional sync, intelligent retrieval, and AI self-optimization

luo1chen/DocSync-MemGuardcommunitylistedunreviewed

Set up

Runs on your computer. Pick your agent and operating system.

Before you start

  • uv (`curl -LsSf https://astral.sh/uv/install.sh | sh`)
~/Library/Application Support/Claude/claude_desktop_config.json
{
  "mcpServers": {
    "docsync-memguard": {
      "command": "uvx",
      "args": [
        "docsync-memguard"
      ]
    }
  }
}

same format Cursor, GitHub Copilot CLI, Junie, JetBrains AI Assistant, Augment (Auggie CLI), Factory Droid, Kiro, Devin CLI +12

Values in angle brackets are placeholders. Restart Claude Desktop after editing its config.Claude Desktop docs

README

synced Oct 22, 2026

DocSync-MemGuard

GitHub stars GitHub forks License Python

Code-Document Linked Memory Guard System - Bridging source code and documentation with bidirectional sync, intelligent retrieval, and AI self-optimization

中文文档 | English


📋 Overview

DocSync-MemGuard is a subproject of DocGuard-AI, focused on unified source code + full-format documentation knowledge base, version-linked validation, and local offline memory, designed for developers and AI coding agents.

🌟 Key Features

FeatureDescription
🔄 Dual-Source ImportConvert PDF/Word/Excel/PPT to Markdown + generate source code knowledge graph, store in vector memory
🔍 Joint RetrievalNatural language query across both documentation and code implementation
🛡️ Consistency GuardAuto-validate doc-code matching on Git commits
🧬 Self-EvolutionAuto-optimize knowledge base from user corrections
🔒 Fully LocalOllama local LLM + Embedding, data never leaves your machine
⚡ Advanced CachingIn-memory caching with TTL and LRU eviction for optimal performance
🔄 Rate LimitingToken bucket rate limiter to prevent API overload
📊 Performance MonitoringBuilt-in performance metrics tracking and timing decorators
🤖 MCP ProtocolModel Context Protocol for seamless AI Agent integration

🎯 Four Core Modules

1️⃣ ds-import | Dual-Source Knowledge Base Import

docsync import ./myproject
  • Batch convert non-MD format documents to standard Markdown
  • Scan project source code and generate code knowledge graph
  • Local Ollama generates vectors and stores in LanceDB
  • Auto-generate memory_index.md

2️⃣ ds-query | Cross-Document & Code Joint Retrieval

docsync query ./myproject "Find user login API documentation and backend code"
  • Natural language dual-query
  • Hierarchical memory scheduling: hot data stays in context, cold data loads on demand

3️⃣ ds-guard | Code-Document Consistency Guard

docsync guard ./myproject --check-commits HEAD~1
  • Git commit hooks auto-trigger
  • Detect outdated docs, parameter mismatches, missing comments
  • Output fix checklist and quality score report

4️⃣ ds-mem-evolve | Knowledge Base Self-Evolution Engine

docsync evolve ./myproject
  • Record user query corrections
  • Auto-merge redundant memories, remove expired data
  • Optimize chunking rules and retrieval weights

🛠️ Technology Stack

CategoryDependencyPurpose
Document ParsingMicrosoft MarkItDownPDF/Word/Excel/PPT to Markdown
Code ParsingCodeGraphSource code knowledge graph generation
Local LLMOllama + Qwen3.5Local LLM inference + Embedding
Memory StorageAgentMemory + LanceDBHierarchical persistent vector memory
Git IntegrationGitPythonMonitor Git commits, auto-snapshot

🚀 Quick Start

Installation

# Python dependencies
pip install docsync-memguard

# Install Ollama models
ollama pull qwen3.5:14b
ollama pull nomic-embed-text

Initialize Project

# Initialize in project root
docsync init

# Check status
docsync status

Basic Usage

# Dual-source import
docsync import ./myproject

# Intelligent retrieval
docsync query ./myproject "User login logic"

# Consistency check
docsync guard ./myproject

# Setup Git hooks
docsync setup-hooks

🔧 Configuration

Create config.yaml:

ollama:
  base_url: "http://localhost:11434"
  model: "qwen3.5:14b"
  embedding: "nomic-embed-text"

storage:
  vector_db: "./.project_memory/index"
  doc_store: "./.project_memory/docs"
  code_graph_store: "./.project_memory/code_graph"

memory:
  hot_threshold: 10
  cold_retention_days: 30

git:
  auto_snapshot: true
  hook_precommit: true

guard:
  auto_check_on_commit: true
  score_threshold: 80

📁 Project Structure

DocSync-MemGuard/
├── docsync_memguard/
│   ├── __init__.py              # Main entry
│   ├── core/                    # Core modules
│   │   ├── doc_parser.py        # MarkItDown document conversion
│   │   ├── code_graph.py        # CodeGraph source parsing
│   │   ├── memory_store.py      # AgentMemory + vector DB
│   │   ├── git_listen.py        # Git commit listener hooks
│   │   ├── guard_check.py       # Doc-code consistency check
│   │   └── embedder.py          # Ollama vectorization
│   ├── cli/                     # CLI entry
│   │   └── docsync-cli.py
│   └── agent_rules/             # Cursor/Claude config
│       ├── cursor_rules.yaml
│       └── claude_commands.yaml
├── config.yaml                  # Configuration file
├── pyproject.toml
├── requirements.txt
└── README.md

🔌 Multi-Platform Integration

Cursor / Claude Code

# Cursor
cp docsync_memguard/agent_rules/cursor_rules.yaml ~/.cursor/rules/

# Claude Code
cp docsync_memguard/agent_rules/claude_commands.yaml ~/.claude/commands/

OpenClaw / MCP Protocol

{
  "mcpServers": {
    "docsync": {
      "command": "npx",
      "args": ["docsync-cli", "--mode", "mcp"]
    }
  }
}

Advanced Caching System

DocSync-MemGuard includes an advanced in-memory caching system for optimal performance:

from docsync_memguard.core.embedder import Embedder

embedder = Embedder.from_config(config)
# Cache is automatically enabled with TTL and LRU eviction

Features:

  • TTL (Time-To-Live): Cache entries expire after 24 hours
  • LRU Eviction: Least Recently Used entries are evicted when cache is full
  • Configurable Size: Set cache size in config.yaml

Performance Monitoring

Track operation performance with built-in metrics:

memguard = DocSyncMemGuard("./myproject")
result = memguard.import_knowledge()

# Get performance report
metrics = memguard.get_performance_report()
print(f"Total operations: {metrics['total_operations']}")
print(f"Average duration: {metrics['average_duration_seconds']}s")

MCP Protocol Integration

Connect with AI coding agents using the Model Context Protocol:

from docsync_memguard import create_mcp_server

mcp = create_mcp_server("./myproject")
message = MCPMessage(method="tools/list")
response = mcp.handle_request(message)

Available MCP Tools:

  • docsync_import: Import documents and code
  • docsync_query: Query the knowledge base
  • docsync_guard: Check consistency
  • docsync_evolve: Self-evolve knowledge base
  • docsync_snapshot: Create snapshots
  • docsync_status: Get system status

🧪 Development

# Clone project
git clone https://github.com/DocGuard-AI/DocSync-MemGuard.git
cd DocSync-MemGuard

# Install dev dependencies
pip install -e ".[dev]"

# Run tests
pytest tests/

# Code formatting
ruff format .
ruff check .

📊 Quality Report Example

## 🛡️ DocSync-MemGuard Consistency Check Report

**Check Time:** 2024-01-15T10:30:00
**Files Checked:** 5
**Quality Score:** 85/100

### ⚠️ Issues Found

| File | Type | Severity | Description | Suggestion |
|------|------|----------|-------------|------------|
| auth/login.py | missing_comment | low | Function at line 45 lacks docstring | Add function purpose description |
| docs/api.md | outdated_doc | high | Doc not synced with code changes | Update doc content |

### 📊 Summary

- Total Issues: 2
- By Type: {'missing_comment': 1, 'outdated_doc': 1}
- By Severity: {'high': 1, 'medium': 0, 'low': 1}

🚀 Advanced Features

For detailed information about advanced features, see ADVANCED_FEATURES.md.

Quick highlights:

  • ⚡ Advanced Caching: In-memory cache with TTL and LRU eviction
  • 🔄 Rate Limiting: Token bucket algorithm prevents API overload
  • 📊 Performance Monitoring: Built-in metrics and timing decorators
  • 🤖 MCP Protocol: Full Model Context Protocol implementation for AI Agent integration
  • 🔁 Retry Mechanism: Exponential backoff for transient failures

📝 License

MIT License - See LICENSE


If this project helps you, please give us a ⭐

↑↓ navigate openesc close