memorylens-mcp
MemoryLens MCP profiles running .NET processes on demand over EventPipe — capturing heap snapshots, comparing them, and analyzing results with built-in rules that return actionable findings.
List .NET processes available for profiling, optionally filtered by process name (excludes IDE/tooling/MCP processes).
Take a memory snapshot of a running .NET process by PID (with optional delay) and get a snapshot ID to pass to
analyze.Compare two snapshots taken with a configurable delay to detect memory growth/leaks between before and after states.
Analyze a snapshot (by ID or path) with built-in rules to detect leaks, LOH fragmentation, excessive allocations, and anti-patterns, returning severity-ranked findings with optional code suggestions; supports before/after path comparison.
List all active analysis rules with ID, title, severity, and category (configurable via
.memorylens.json).
Hosted deployment
A hosted deployment is available on Fronteir AI.
Related MCP server: ASPNET Core Debugging MCP Server
Quick Start
npx (any MCP client)
{
"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 or 11 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):
{
"servers": {
"memorylens": {
"type": "stdio",
"command": "dnx",
"args": ["MemoryLens.Mcp", "--yes"]
}
}
}Claude Code Plugin
/plugin install memorylens --marketplace MarcelRoozekrans/memorylens-mcpThe plugin runs the NuGet tool through dnx, so it needs the .NET 10 or 11 SDK and nothing else.
.NET Global Tool
dotnet tool install -g MemoryLens.McpDocker
docker build -t memorylens-mcp .
docker run -i --rm --pid=host --cap-add=SYS_PTRACE \
-v /tmp:/tmp \
-v "$PWD:/workspace" memorylens-mcpProfiling 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
To run the published tool (dnx, dotnet tool install, the npm launcher):
The .NET 10 or 11 SDK. The package ships both
net10.0andnet11.0builds.
To build and test from a checkout:
The .NET 11 SDK, 11.0.1xx feature band:
global.jsonpins 11.0.100 withlatestPatch, and SDK 10 alone cannot build thenet11.0target.The .NET 10 runtime as well, because the tests run on both
net10.0andnet11.0.
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
Tool | Description |
| Lists running .NET processes available for profiling, discovered from their diagnostic IPC endpoints |
| Captures a single memory snapshot of a target process |
| Captures two snapshots with configurable delay and compares them |
| Runs the rule engine against a captured snapshot and returns findings |
| Lists all available analysis rules with their metadata |
Built-in Rules
ID | Severity | Category | Description |
ML001 | critical | leak | Event handler leak detected |
ML002 | critical | leak | Static collection growing unbounded |
ML003 | high | leak | Disposable object not disposed |
ML004 | high | fragmentation | Large Object Heap fragmentation |
ML005 | medium | retention | Object retained longer than expected |
ML006 | medium | allocation | Excessive allocations in hot path |
ML007 | medium | retention | Closure retaining unexpected references |
ML008 | low | allocation | Array/list resizing without capacity hint |
ML009 | low | pattern | Finalizer without Dispose pattern |
ML010 | low | pattern | String interning opportunity |
Configuration
Create a .memorylens.json file in your project root to customize rule behavior:
{
"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 requestsClaude 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
Available Tools
5 toolsanalyzeB
Analyzes a memory snapshot using built-in rules to detect leaks, fragmentation, excessive allocations, and anti-patterns. Returns findings with severity, description, and optional code suggestions.
Inputs: snapshotId (required), afterPath, beforePath, snapshotPath, +1 more.
compare_snapshotsA
Takes two memory snapshots of a .NET process with a delay between them for comparison. Useful for detecting memory leaks by comparing before/after state. Provide a pid. Returns the ids and paths of both snapshots.
Inputs: pid, command, processName, delaySeconds.
get_rulesA
Lists all active analysis rules with their ID, title, severity, and category. Rules can be configured via .memorylens.json in the project root.
Inputs: no named parameters.
list_processesA
Lists running .NET processes suitable for memory profiling, discovered from their diagnostic IPC endpoints. Excludes IDE, tooling, and MCP server processes to prevent interference.
Inputs: filter.
snapshotA
Takes a memory snapshot of a running .NET process. Provide a pid. Returns a snapshot id to pass to analyze.
Inputs: pid, command, processName, durationSeconds.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 5 tools
Each tool targets a distinct phase of the profiling workflow (discovery, snapshot, comparison, analysis, rule listing), and descriptions are clear enough to avoid serious misselection. However, snapshot and compare_snapshots both involve taking snapshots; while not ambiguous in intent, they are closely related.
Most names follow a verb_snake_case pattern (list_processes, get_rules, compare_snapshots), but 'snapshot' and 'analyze' are single-word verbs rather than the verb_noun form. The naming is readable but not perfectly uniform across the set.
Five tools is well-scoped for a memory profiling MCP server. Each tool serves a necessary part of the primary workflow, and there is no bloat or redundancy.
The tool set covers the core workflow: find process, take snapshot, compare snapshots, analyze against rules, and list rules. Minor gaps like managing rules directly or inspecting snapshot raw details are missing, but the main user journeys are supported.
Maintenance
Related MCP Connectors
Cloud-hosted MCP server for durable AI memory
A MCP server built for developers enabling Git based project management with project and personal…
MCP server for Qwen Image 3 AI image generation
An MCP server that gives your AI access to the source code and docs of all public github repos
Related MCP Servers
- AlicenseBqualityDmaintenanceAn MCP server that enables AI agents to debug .NET applications using netcoredbg. It supports core debugging tasks like setting breakpoints, stepping through code, and inspecting variables or stack traces.1MIT
- AlicenseAqualityBmaintenanceMCP server that lets AI agents (Claude, Cursor) debug your .NET / ASP.NET Core app2715MIT
- AlicenseAqualityCmaintenanceMCP server for profiling Java applications via JDK utilities (jcmd, jfr, jps). Enables AI assistants to diagnose performance, analyze threads, and inspect JFR recordings without manual CLI usage.2664 npm10MIT
- AlicenseAqualityCmaintenanceAn MCP server that captures and analyzes function-level profiling data from NetEase Minecraft Bedrock Edition mods via the native Tracy profiler, enabling AI to identify performance hotspots and verify optimizations.622MIT