Skip to main content
Glama
Luiguard

mcp-sqlite-graph-memory

by Luiguard

mcp-sqlite-graph-memory

许可证:MIT Python:3.10+ MCP:2024-11-05

通用模型上下文协议(MCP)服务器,为 AI 编码助手和自主代理提供基于 SQLite 的动态代码知识图谱内存。

自动检测活动工作区,将多语言 AST 和结构依赖解析为隔离的本地 SQLite 知识图谱,并通过精确的 MCP 工具来检查符号、计算最短调用/导入路径以及导航代码拓扑。


🌟 核心能力

  • 零运行时依赖:完全使用 Python 标准库编写(ast、sqlite3、json、re、hashlib、threading)。

  • 动态多工作区隔离:为每个工作区根目录生成确定性 SHA-256 哈希;将隔离的 SQLite 数据库存储在 ~/.mcp-graph-memory/storage/graph_<hash>.db 中。

  • 增量统计缓存:通过校验文件 mtime 和 size,在重新索引时实现亚毫秒级跳过未变更文件。

  • 多语言 AST 与结构解析器:

    • Python:类、方法、函数、异步函数、装饰器、导入(from x import y、import z)、继承层次、调用点。

    • TypeScript / JavaScript:类、接口、类型、函数、箭头函数、ES6 导入/导出、CommonJS require()。

    • Go:包、导入、结构体、接口、函数、方法。

    • Rust:模块、枚举、结构体、trait、impl 块、fn 签名。

    • C / C++ / Java / PHP / Ruby / Kotlin / Swift / Shell:结构体、类、定义。

  • 冻结与 CPU 饥饿保护:

    • 非阻塞异步守护进程初始化。

    • 非忙等 stdio 传输(for raw_line in sys.stdin:)。

    • 对 node_modules/、.git/、.venv/、二进制权重文件和缓存 blob 的严格忽略列表。


Related MCP server: Synapse

🛠️ MCP 工具规范

工具

参数

描述

graph_reindex

force(布尔值)

增量或强制扫描并更新工作区图谱内存。

graph_query_symbol

query(字符串)、type(字符串)、exact(布尔值)

按精确文件路径、行范围、签名和关系查找符号。

graph_find_paths

source(字符串)、target(字符串)、max_depth(整数)

计算两个文件或符号之间的最短依赖/导入/调用路径。

graph_get_neighbors

node_id_or_path(字符串)、direction(入/出/双向)、relation(全部/导入/调用/包含/继承)

检查直接调用者、被调用者、包含和继承边。

graph_structure_overview

depth(整数)、focus_path(字符串)

返回架构指标、枢纽模块和目录树。

graph_find_files

pattern(字符串)、extension(字符串)、contains_symbol(字符串)

按路径模式、扩展名或包含的符号查找工作区文件。


🚀 安装

git clone https://github.com/Luiguard/mcp-sqlite-graph-memory.git ~/.mcp-graph-memory
chmod +x ~/.mcp-graph-memory/server.py

🔌 集成指南

1. Google Antigravity 集成

选项 A:全局配置(推荐)

将 graph-memory 添加到位于 ~/.gemini/config/mcp_config.json 的全局 Antigravity MCP 配置文件中:

{
  "mcpServers": {
    "graph-memory": {
      "command": "python3",
      "args": [
        "/home/YOUR_USER/.mcp-graph-memory/server.py"
      ]
    }
  }
}

(将 /home/YOUR_USER 替换为你的实际 $HOME 目录路径,或使用绝对路径)。

选项 B:工作区级配置

对于按项目激活,请将 mcp_config.json 放置在工作区根目录下的 .agents/mcp_config.json 中:

{
  "mcpServers": {
    "graph-memory": {
      "command": "python3",
      "args": [
        "${workspaceFolder}/.mcp-graph-memory/server.py"
      ]
    }
  }
}

2. Claude Desktop 集成

找到你的 Claude 配置文件:

  • Linux:~/.config/Claude/claude_desktop_config.json

  • macOS:~/Library/Application Support/Claude/claude_desktop_config.json

  • Windows:%APPDATA%\Claude\claude_desktop_config.json

添加服务器定义:

{
  "mcpServers": {
    "graph-memory": {
      "command": "python3",
      "args": [
        "/path/to/mcp-sqlite-graph-memory/server.py"
      ]
    }
  }
}

3. Cursor / VSCode / Windsurf 集成

在 .cursor/mcp.json 或 .vscode/mcp.json 中:

{
  "mcpServers": {
    "graph-memory": {
      "command": "python3",
      "args": [
        "/path/to/mcp-sqlite-graph-memory/server.py"
      ]
    }
  }
}

🔧 环境变量

变量

默认值

描述

MCP_GRAPH_STORAGE_DIR

~/.mcp-graph-memory/storage

SQLite 数据库(graph_<hash>.db)的持久化目录。

MCP_WORKSPACE_ROOT

os.getcwd()

当客户端在 initialize 中省略 rootUri 时的回退工作区路径。


🧪 验证与测试

执行自动化集成测试套件:

python3 test_server.py

📄 许可证

MIT 许可证 — 版权所有(c)2026 Benjamin Leimer。详见 LICENSE。

Maintenance

ActivitySlowing
ResponsivenessNo issues

Related MCP Connectors

Related MCP Servers

  • A
    license
    Not graded
    quality
    D
    maintenance
    Provides AI assistants with a structured, token-efficient map of a codebase's symbols, dependencies, and relationships via MCP tools like overview, query, and impact analysis.
    8
    MIT
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides structural code intelligence via 26 MCP tools, enabling AI assistants to query code symbols, dependencies, and call graphs accurately without file-pasting.
    -
  • F
    license
    Not graded
    quality
    D
    maintenance
    Provides code intelligence by indexing source code into SQLite and offering MCP tools for symbol search, flow tracing, and context retrieval to assist with code navigation and understanding.
    -
  • A
    license
    Not graded
    quality
    A
    maintenance
    A persistent code-intelligence MCP server that builds a queryable knowledge graph of your codebase, enabling AI assistants to perform cross-file structural reasoning, dependency analysis, and blast radius detection.
    9
    MIT