mcpField
M
Memoria

Memoria

本地服务
github.com/byronwade开发工具211 周前更新

关于 Memoria

Memoria 是 MCP 服务和命令行工具,通过分析 Git 历史识别隐式文件依赖与代码变更风险。它面向编码 Agent 和开发者,可在修改代码前提供相关文件的历史依据;分析在本地代码库中运行。

主要功能

  1. 01查找经常共同变更的文件
  2. 02报告风险、变动频率和过时依赖
  3. 03搜索 Git 历史以了解变更背景
  4. 04检测静态导入及其他文件关联
  5. 05提供 MCP 工具和命令行分析

适用场景

  1. 01重构前检查相关文件
  2. 02修改路由前评估历史风险
  3. 03查找可能需要同步更新的依赖
  4. 04搜索提交历史以理解现有代码

MCP 相关

Memoria 向 MCP 客户端提供 `analyze_file` 和 `ask_history`,利用本地 Git 历史和代码库文件,在代码变更前提供取证背景。

配置

本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。

mcp.json · 通用配置
{
"mcpServers": {
"memoria": {
"command": "npx",
"args": [
"-y",
"@byronwade/memoria"
]
}
}
}
启动命令npx -y @byronwade/memoria

本地服务需要在你的电脑上安装运行环境(如 Node.js 18+)。各客户端的配置文件位置不同,请参考客户端文档。

安装包
npm@byronwade/memoria

工具

6

收录的工具列表 · 更新于 3 周前

参数类型必填说明
pathstring是文件的绝对路径(例如,C:/dev/project/src/file.ts)

详细介绍

Memoria 徽标

Memoria

你的 AI 所缺少的记忆。

一个 MCP 服务,通过 Git 取证揭示隐藏的文件依赖关系,防止 AI 破坏代码。

npm version License: MIT TypeScript MCP Twitter


⚡ 快速安装

一键安装(Smithery)

Smithery - 安装 Memoria

点击上方徽标,通过 Smithery 一键安装 Memoria。

快速复制粘贴配置

将以下内容添加到你的 MCP 配置文件中(适用于 Claude、Cursor、Windsurf、Cline):

{
  "mcpServers": {
    "memoria": {
      "command": "npx",
      "args": ["-y", "@byronwade/memoria"]
    }
  }
}
终端单行命令
工具命令
Claude Codeclaude mcp add memoria -- npx -y @byronwade/memoria
Claude Desktopnpx @anthropic/claude-code mcp add memoria -- npx -y @byronwade/memoria
Cursormkdir -p .cursor && echo '{"mcpServers":{"memoria":{"command":"npx","args":["-y","@byronwade/memoria"]}}}' > .cursor/mcp.json
npm globalnpm install -g @byronwade/memoria
🪟 Windows PowerShell 安装
# Claude Desktop
$config = "$env:APPDATA\Claude\claude_desktop_config.json"
$json = if(Test-Path $config){Get-Content $config | ConvertFrom-Json}else{@{}}
$json.mcpServers = @{memoria=@{command="npx";args=@("-y","@byronwade/memoria")}}
$json | ConvertTo-Json -Depth 10 | Set-Content $config
🍎 macOS 手动安装
# Claude Desktop (requires jq: brew install jq)
echo '{"mcpServers":{"memoria":{"command":"npx","args":["-y","@byronwade/memoria"]}}}' | \
  jq -s '.[0] * .[1]' ~/Library/Application\ Support/Claude/claude_desktop_config.json - > tmp.json && \
  mv tmp.json ~/Library/Application\ Support/Claude/claude_desktop_config.json

然后重启你的 AI 工具。就这么简单!


为什么选择 Memoria?

你让 AI 重构一个文件。它做得天衣无缝。你运行应用。应用崩溃了。

为什么?另一个文件依赖旧实现,但两者之间没有导入关系,因此 AI 并不知道。

**Memoria 可以解决这个问题。**它会分析 Git 历史,找出经常一起变更的文件,即使它们之间没有直接导入关系。

Without Memoria:                        With Memoria:
─────────────────                       ─────────────
You: "Update route.ts"                  You: "Update route.ts"
AI: "Done!" ✅                           Memoria: "⚠️ 85% coupled with billing.tsx"
Result: 💥 CRASH                         AI: "I'll update both files"
                                        Result: ✅ Works

隐私与本地运行

Memoria 100% 在你的机器上运行。

  • 不会将代码上传到云端
  • 无需 API 密钥
  • 可离线运行
  • 直接分析本地的 .git 文件夹

你的代码绝不会离开你的电脑。


安装

选择你的 AI 工具:

工具一行命令配置文件
Claudenpx @anthropic/claude-code mcp add memoria -- npx -y @byronwade/memoria见下文
Claude Codeclaude mcp add memoria -- npx -y @byronwade/memoria自动
Cursormkdir -p .cursor && echo '{"mcpServers":{"memoria":{"command":"npx","args":["-y","@byronwade/memoria"]}}}' > .cursor/mcp.json.cursor/mcp.json
Windsurf手动配置~/.codeium/windsurf/mcp_config.json
VS Code手动配置~/.continue/config.json
Cline设置界面Cline MCP 设置

📦 Claude Desktop

配置位置:

  • macOS:~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows:%APPDATA%\Claude\claude_desktop_config.json

选项 1:Claude Code CLI(推荐)

npx @anthropic/claude-code mcp add memoria -- npx -y @byronwade/memoria

选项 2:手动配置

{
  "mcpServers": {
    "memoria": {
      "command": "npx",
      "args": ["-y", "@byronwade/memoria"]
    }
  }
}
📦 Claude Code (CLI)
claude mcp add memoria -- npx -y @byronwade/memoria

完成!Claude Code 会自动处理所有事项。

📦 Cursor

一行命令(项目级):

mkdir -p .cursor && echo '{"mcpServers":{"memoria":{"command":"npx","args":["-y","@byronwade/memoria"]}}}' > .cursor/mcp.json

配置位置:

  • 项目:.cursor/mcp.json(位于项目根目录)
  • 全局:~/.cursor/mcp.json
{
  "mcpServers": {
    "memoria": {
      "command": "npx",
      "args": ["-y", "@byronwade/memoria"]
    }
  }
}
📦 Windsurf

配置: ~/.codeium/windsurf/mcp_config.json

{
  "mcpServers": {
    "memoria": {
      "command": "npx",
      "args": ["-y", "@byronwade/memoria"]
    }
  }
}
📦 Continue (VS Code)

配置: ~/.continue/config.json

{
  "experimental": {
    "modelContextProtocolServers": [
      {
        "transport": {
          "type": "stdio",
          "command": "npx",
          "args": ["-y", "@byronwade/memoria"]
        }
      }
    ]
  }
}
📦 Cline (VS Code)

打开 Cline 设置 → MCP Servers → Add new server:

{
  "mcpServers": {
    "memoria": {
      "command": "npx",
      "args": ["-y", "@byronwade/memoria"]
    }
  }
}
📦 其他 MCP 客户端

任何兼容 MCP 的客户端都可以使用。请使用此通用配置:

{
  "mcpServers": {
    "memoria": {
      "command": "npx",
      "args": ["-y", "@byronwade/memoria"]
    }
  }
}

⚠️ 配置完成后,请重启 AI 工具。

验证安装

重启后,向 AI 提问:

"What MCP tools do you have available?"

你应该会在列表中看到 analyze_file 和 ask_history。

或者直接测试:

"Use the analyze_file tool on any file in this project"

用法

在进行更改前,让 AI 分析文件:

"Analyze src/api/stripe/route.ts before I refactor it"

Memoria 会返回:

  • 关联文件 - 经常一起更改的文件
  • 风险评分 - 此代码在历史上容易出现 Bug 的程度
  • 过时依赖项 - 可能需要更新的关联文件
  • 证据 - 展示文件关联原因的实际代码差异

CLI 命令

Memoria 提供完整的 CLI,供手动分析使用,功能与 AI 使用的相同:

# Full forensic analysis (same as AI's analyze_file)
memoria analyze src/index.ts

# Quick risk assessment
memoria risk src/api/route.ts

# Show coupled files
memoria coupled src/auth.ts

# Find files that import the target
memoria importers src/types.ts

# Search git history (same as AI's ask_history)
memoria history "setTimeout" src/utils.ts
memoria history "fix" --type=message
输出选项
# JSON output for scripting/CI
memoria analyze src/index.ts --json

# Pipe to other tools
memoria risk src/api/route.ts --json | jq '.riskScore'
输出示例
$ memoria analyze src/index.ts

Forensics for `index.ts`

RISK: 45/100 (MEDIUM)
Risk factors: High volatility (38%) • Coupled (5 files) • 3 dependents

VOLATILITY
  Panic score: 38% | Commits: 24
  Top author: Dave (72%)

COUPLED FILES
  85% billing/page.tsx [schema]
      References: billing_records table. Schema changes may break queries.
  90% index.test.ts [test]
      Test file matches naming pattern. Update when changing exports.
  75% config.ts [env]
      Shares env vars: API_KEY, DATABASE_URL
  65% hooks/useData.ts [api]
      Calls endpoint: GET /api/data

STATIC DEPENDENTS
  - [ ] Check `cli.ts`
  - [ ] Check `server.ts`
  - [ ] Check `utils.ts`

Analysis completed in 142ms

配置(可选)

在项目根目录中创建 .memoria.json,以自定义阈值:

{
  "thresholds": {
    "couplingPercent": 20,
    "driftDays": 14,
    "analysisWindow": 100
  },
  "ignore": [
    "**/*.lock",
    "dist/",
    "legacy/**"
  ],
  "panicKeywords": {
    "postmortem": 3,
    "incident": 3,
    "p0": 3
  },
  "riskWeights": {
    "volatility": 0.35,
    "coupling": 0.30,
    "drift": 0.20,
    "importers": 0.15
  }
}
选项默认值说明
thresholds.couplingPercent15报告关联度的最低百分比
thresholds.driftDays7文件被视为“过时”前的天数
thresholds.analysisWindow50要分析的提交数
ignore[]额外的 glob 忽略模式
panicKeywords{}带严重性权重的自定义关键词
riskWeights{}覆盖风险计算权重

工作原理

Volatility 引擎

扫描提交中的恐慌关键词(fix、bug、revert、urgent、hotfix),并采用时间衰减机制——近期 Bug 比旧 Bug 更重要。还会追踪Bus Factor(由谁负责维护代码)。

Entanglement 引擎

找出同时变更的文件(发生频率超过 15%)。揭示导入关系无法展现的隐式依赖。

Sentinel 引擎

检测耦合文件是否超过 7 天未同步。在过时依赖引发 Bug 前发出警告。

静态导入引擎

使用 git grep 查找导入目标文件的文件——即使目标文件是全新文件且没有 Git 历史记录,也能找到。

历史搜索(考古学家)

搜索 Git 历史,了解编写代码的原因。在删除那些看起来奇怪的代码前,解决“切斯特顿栅栏”问题。

文档耦合

查找引用导出函数/类型的 Markdown 文件。当输出格式变更时,及时发现需要更新的 README。

类型耦合

使用 Git pickaxe(git log -S)查找共享类型定义的文件——即使它们之间没有直接导入关系。

内容耦合

查找共享字符串字面量(错误消息、常量)的文件,确保它们保持同步。

测试文件耦合

自动发现符合命名约定(*.test.*、*.spec.*、*_test.* 等)的测试文件,以及模拟和夹具文件——无需硬编码扩展名。

环境变量耦合

查找共享 ALL_CAPS_UNDERSCORE 环境变量(API_KEY、DATABASE_URL 等)的文件——适用于任何语言。

架构/模型耦合

检测数据库架构定义(SQL、Prisma、TypeORM、Mongoose),并查找查询这些表/模型的文件。

API 端点耦合

查找调用路由文件中定义的 API 端点的客户端代码。捕捉可能导致使用方出错的响应结构变更。

重新导出链耦合

检测重新导出你的模块的 barrel 文件(index.ts),并通过这些 barrel 文件查找传递导入者。


输出示例

# Forensics: `route.ts`

**RISK: 65/100** — HIGH
45% volatility · 3 coupled · 8 dependents · 1 stale

> Proceed carefully. Check all coupled files and update stale dependencies.

---

## Coupled Files

**`billing/page.tsx`** — 85% (schema)
> These files share type definitions. If you modify types in one, update the other to match.
  + interface SubscriptionUpdated
  - oldStatus: string

**`route.test.ts`** — 90% [test]
> Test file for this module. Update when changing exports.

**`services/stripe.ts`** — 75% [env]
> Shares env vars: STRIPE_KEY, STRIPE_SECRET

**`README.md`** — 70% [docs]
> Documentation references: generateReport, SubscriptionStatus

**`types/billing.ts`** — 65% [type]
> Shared types: SubscriptionUpdated, PaymentStatus

**`features/billing/index.ts`** — 60% [transitive]
> Re-exports this file. Changes propagate through this barrel.

---

## Static Dependents

These files import `route.ts`. API changes require updating them.

- [ ] `src/components/SubscriptionCard.tsx`
- [ ] `src/hooks/useSubscription.ts`

---

## Pre-flight Checklist

- [ ] Modify `route.ts`
- [ ] Update `billing/page.tsx` (schema)
- [ ] Update `tests/stripe.test.ts` — stale 12d

---

## File History

**Volatile** — 45% panic score
**Expert:** Dave (90% of commits)

自动驾驶模式

希望 AI 在每次编辑前自动检查 Memoria?安装规则文件:

# Install globally first
npm install -g @byronwade/memoria

# Then in your project directory:
memoria init --all

这会安装规则文件,指示 AI 在编辑代码前始终调用 analyze_file。

安装内容
标志文件工具
--cursor.cursor/rules/memoria.mdcCursor
--claude.claude/CLAUDE.mdClaude Code
--windsurf.windsurfrulesWindsurf
--cline.clinerulesCline/Continue
--all以上所有文件所有工具
--force更新现有规则覆盖 Memoria 部分
智能合并行为

memoria init 可安全地多次运行,不会覆盖现有规则:

情况处理方式
文件不存在创建包含 Memoria 规则的新文件
文件存在,但没有 Memoria 规则追加 Memoria 规则(保留你的内容)
文件存在,且已有 Memoria 规则跳过(使用 --force 更新)
# First run - creates or appends
memoria init --cursor
#   ✓ Created .cursor/rules/memoria.mdc

# Second run - skips (already installed)
memoria init --cursor
#   ⊘ Skipped .cursor/rules/memoria.mdc (already has Memoria rules)
#   Use --force to update existing Memoria rules.

# Force update to latest version
memoria init --cursor --force
#   ✓ Updated .cursor/rules/memoria.mdc (--force)
自动检测

不带标志运行 memoria init,会自动检测你正在使用的工具:

memoria init
# Detected: Cursor, Claude Code
# Installing Memoria rules...
#   ✓ Created .cursor/rules/memoria.mdc
#   ✓ Appended to .claude/CLAUDE.md (preserved existing content)
# ✓ Installed/updated 2 rule file(s)

现在,Memoria 会作为每次编辑的强制安全防护。


性能

Memoria 针对速度和最少 Token 用量进行了优化:

指标数值
完整分析耗时<100ms
每次分析的 Token 数~600 tokens
缓存提速重复调用时为 2000x+
引擎细分
引擎耗时用途
耦合~45ms查找同时变更的文件
Volatility~10ms计算易出 Bug 的评分
Drift<1ms检测过时依赖
导入者~8ms查找静态依赖项
历史搜索~7ms搜索 Git 提交

自行运行基准测试:

npm run build
npx tsx benchmarks/run-benchmarks.ts

要求

  • Node.js 18+
  • 包含提交历史记录的 Git 仓库
  • 兼容 MCP 的 AI 工具

Monorepo 布局(Turbo)

  • apps/mcp-server — MCP 服务和 npm 包(发布 @byronwade/memoria)
  • apps/api — API 后端占位项目(Node HTTP 占位符)
  • apps/web — Web 前端占位项目
  • packages — 共享库(未来)

开发

npm install
npm run build                     # turbo build across workspaces
npm test                          # turbo test (runs vitest in mcp-server)

# Focus on a single app/package
npx turbo run build --filter=@byronwade/memoria
npx turbo run dev --filter=@byronwade/memoria

故障排除

❌“未找到工具”或“analyze_file 不可用”
  1. 重启 AI 工具 — MCP 服务仅在启动时加载
  2. 检查配置语法 — JSON 必须有效(不能有尾随逗号)
  3. 确认 Node.js 18+ — 运行 node --version 进行检查
  4. 检查文件路径 — 配置文件必须位于对应工具的准确位置
❌“不是 git 仓库”

Memoria 需要包含历史记录的 git 仓库。请确保:

  1. 当前位于 git 仓库中(git status 应可正常运行)
  2. 仓库至少有几次提交
  3. 传递给 analyze_file 的是绝对路径
❌ npx 运行缓慢或超时

全局安装以加快启动速度:

npm install -g @byronwade/memoria

然后更新配置,直接使用 memoria:

{
  "mcpServers": {
    "memoria": {
      "command": "memoria"
    }
  }
}
❌ Windows 路径问题

路径中使用正斜杠或转义后的反斜杠:

"args": ["-y", "@byronwade/memoria"]

如果问题仍然存在,请全局安装并直接使用该命令。

仍然无法解决? 请携带配置和错误消息提交 issue。


许可证

MIT


如果 Memoria 帮你避免了一次回归,请告诉我们。

评论

支持 Markdown

第一次接触 MCP?

从协议是什么,到在客户端里装上第一个服务,这几条回答覆盖了大多数入门问题。

一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。