Memorylens Mcp

io.github.MarcelRoozekrans由 GitHub 帳號 MarcelRoozekrans 發布v2.1.3更新於 Oct 31, 2026

MCP server for .NET memory profiling — in-process heap snapshots via EventPipe with leak heuristics

已驗證STDIO僅桌面開發者工具安全與監控

概覽

AI 產生的概覽

本機 MCP 伺服器,讓助理對 .NET 行程做記憶體分析:列出行程、擷取堆積快照、比對快照並執行洩漏規則。

可以做什麼
  • 列出可供分析的執行中 .NET 行程
  • 依 PID 擷取目標行程的堆積快照,並比對間隔一段時間取得的兩份快照
  • 對快照執行內建規則引擎,依嚴重程度回傳發現
  • 列出可用的分析規則及其中介資料
適用情境
適合排查執行中 .NET 應用程式的記憶體成長或疑似洩漏,讓助理蒐集堆積資料並指出可能原因,而不必安裝分析工具。
執行需求
以本機 stdio 行程執行;npm 套件只是啟動器,會安裝對應版本的 MemoryLens.Mcp .NET 全域工具,因此 PATH 中必須有 .NET 10 SDK(10.0.4xx 特性帶)。也可安裝為 NuGet 全域工具或透過 dnx 執行。在 Linux 與容器中附加行程可能需要相同 UID 或 SYS_PTRACE。未宣告帳號、金鑰或環境變數。
安裝前請注意
它會附加到執行中的 .NET 行程並觸發垃圾回收,可能短暫影響被分析的應用程式,請只分析自己的行程。快照會以 JSON 檔寫入暫存目錄。文件提到託管部署但未說明細節。Docker 方式需要 ptrace 與主機 PID 命名空間權限。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 Memorylens Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

[GitHub Sponsors]

[MemoryLens MCP]

MemoryLens MCP

[NuGet] [NuGet Downloads] [npm] [Build Status] [codecov] [License]

On-demand .NET memory profiling with concrete, AI-actionable code fix suggestions — no profiler to install.

[memorylens-mcp MCP server]

Hosted deployment

A hosted deployment is available on Fronteir AI.

Quick Start

npx (any MCP client)

json
{  "mcpServers": {    "memorylens": {      "type": "stdio",      "command": "npx",      "args": ["-y", "memorylens-mcp"]    }  }}

The npm package ships no server code — it is a launcher that installs the MemoryLens.Mcp .NET global tool at a matching version and execs it, so the .NET 10 SDK must be on PATH. Subsequent starts skip the install entirely and work offline.

VS Code / Visual Studio (via dnx)

Add to your MCP settings (.vscode/mcp.json or VS settings):

json
{  "servers": {    "memorylens": {      "type": "stdio",      "command": "dnx",      "args": ["MemoryLens.Mcp", "--yes"]    }  }}

Claude Code Plugin

/plugin install memorylens --marketplace MarcelRoozekrans/memorylens-mcp

The plugin runs the NuGet tool through dnx, so it needs the .NET 10 SDK and nothing else.

.NET Global Tool

bash
dotnet tool install -g MemoryLens.Mcp

Docker

bash
docker build -t memorylens-mcp .docker run -i --rm --pid=host --cap-add=SYS_PTRACE \  -v /tmp:/tmp \  -v "$PWD:/workspace" memorylens-mcp

Profiling from a container needs ptrace and the host PID namespace, and on Docker Desktop that namespace is the Linux VM rather than your desktop — see docs/docker.md before choosing this route.

-v /tmp:/tmp is what makes list_processes return anything — the runtime's diagnostic sockets live in the temp directory — and it is also what keeps snapshots alive after --rm, since they are written to /tmp/memorylens-snapshots inside the container. -v "$PWD:/workspace" is only so .memorylens.json is picked up; nothing is written there.

Prerequisites

  • .NET 10 SDK, 10.0.4xx feature band (pinned in global.json)

Running a filtered subset of the tests, e.g. dotnet test --filter <name>, will exit with code 9 and print error: 1, failed: 0. That's the test project's discovery-collapse guard (--minimum-expected-tests) firing because the filter left fewer tests than expected — it is not a test failure, and a full dotnet test run is unaffected.

How Collection Works

MemoryLens collects heap data in-process over EventPipe, the .NET runtime's built-in diagnostics channel. There is no profiler to install, no download on first use, and no external tool on PATH.

snapshot attaches to a running .NET process by pid, induces a collection, and aggregates the heap into per-type counts and sizes. Snapshots are written as small JSON files under your temp directory and referenced by a short id.

On Linux and in containers, attaching to another process's diagnostic endpoint may require matching UID or SYS_PTRACE — see docs/docker.md.

Available MCP Tools

ToolDescription
list_processesLists running .NET processes available for profiling, discovered from their diagnostic IPC endpoints
snapshotCaptures a single memory snapshot of a target process
compare_snapshotsCaptures two snapshots with configurable delay and compares them
analyzeRuns the rule engine against a captured snapshot and returns findings
get_rulesLists all available analysis rules with their metadata

Built-in Rules

IDSeverityCategoryDescription
ML001criticalleakEvent handler leak detected
ML002criticalleakStatic collection growing unbounded
ML003highleakDisposable object not disposed
ML004highfragmentationLarge Object Heap fragmentation
ML005mediumretentionObject retained longer than expected
ML006mediumallocationExcessive allocations in hot path
ML007mediumretentionClosure retaining unexpected references
ML008lowallocationArray/list resizing without capacity hint
ML009lowpatternFinalizer without Dispose pattern
ML010lowpatternString interning opportunity

Configuration

Create a .memorylens.json file in your project root to customize rule behavior:

json
{  "rules": {    "ML001": { "enabled": true, "severity": "critical" },    "ML002": { "enabled": true, "severity": "critical" },    "ML003": { "enabled": true, "severity": "high" },    "ML004": { "enabled": true, "severity": "high" },    "ML005": { "enabled": true, "severity": "medium" },    "ML006": { "enabled": true, "severity": "medium" },    "ML007": { "enabled": true, "severity": "medium" },    "ML008": { "enabled": true, "severity": "low" },    "ML009": { "enabled": true, "severity": "low" },    "ML010": { "enabled": true, "severity": "low" }  }}

Usage Examples

Single Snapshot

Capture a memory snapshot of a running process to inspect current memory state:

> /memorylens> Take a snapshot of my running API (PID 12345)

Claude will call snapshot with the target PID, then analyze the returned snapshot id and present findings ordered by severity.

Before/After Comparison

Detect memory growth by comparing two snapshots taken with a delay:

> /memorylens> Check if my app has a memory leak — compare before and after processing 1000 requests

Claude will call compare_snapshots with a delaySeconds value (default 10 seconds) between the two captures, then analyze the diff to identify objects that grew between snapshots.

Family

MemoryLens MCP is part of a small family of .NET projects for AI work:

  • AI.Sentinel: Security monitoring middleware for IChatClient: prompt injection, hallucination and PII detection with an audit trail.
  • Minos.NET: Typed, source-generated decision questions with calibrated answers.
  • Rag.NET: A modular retrieval-augmented generation pipeline on Microsoft.Extensions.AI.
  • Roslyn CodeLens MCP: Semantic .NET code intelligence for AI agents over MCP.

Built on ZeroAlloc

MemoryLens MCP uses these ZeroAlloc libraries, which are source generators and analyzers with no reflection at runtime:

License

MIT

來源:README.md,提交 59babff

工具

0
SourceWeft 曾在隔離沙箱中以無憑證方式啟動該軟體包一次,以列出其工具,但未能完成:伺服器未能啟動。

版本歷史

2
  1. v2.1.3最新Oct 31, 2026
  2. v2.1.2Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分