# memorylens-mcp

Takes heap snapshots of a running .NET process over EventPipe and flags likely leaks. Useful when memory climbs and you would rather not install a profiler.

- MCP server · `type=mcp` · Claude Code, Codex, Cursor, GitHub Copilot, Windsurf (Devin Desktop), Cline, Zed, Gemini CLI · ★ 11
- Author: MarcelRoozekrans
- License: MIT · policy=link-only · description only; the file stays with the author
- Source: https://github.com/MarcelRoozekrans/memorylens-mcp
- Updated: 2026-10-23
- HTML: https://affpapa.org/en/nevibecode/mcp/memorylens-mcp

## What it does

The server attaches to a .NET process by pid, forces a collection, then groups the heap by type with counts and sizes. Each snapshot lands as a small JSON file in your temp directory and gets a short id you can refer back to. A rule engine then reads that snapshot and reports findings tied to code you can change.

Ten rules ship with it, ML001 through ML010. They cover event handler leaks, static collections that keep growing, missing `Dispose` calls, Large Object Heap fragmentation, and wasted allocations on hot paths. A `.memorylens.json` file in the project root controls this: any rule can be turned off or given a different severity.

The .NET 10 SDK has to be on `PATH` before anything runs. The npm package holds no server code — it installs the `MemoryLens.Mcp` global tool and execs it. On Linux and inside containers, attaching to another process's diagnostic endpoint needs a matching UID or `SYS_PTRACE`; without it you get no snapshot.

## Requirements
- Needs: Node.js (commands run via npx)

## Install

### Claude Code (native platform)

**Platform CLI**
```bash
claude mcp add memorylens-mcp -- npx -y memorylens-mcp
```

### Codex

**Platform CLI**
```bash
codex mcp add memorylens-mcp -- npx -y memorylens-mcp
```

### Cursor

**Config file**
File `.cursor/mcp.json`:
```json
{
    "mcpServers": {
        "memorylens-mcp": {
            "command": "npx",
            "args": [
                "-y",
                "memorylens-mcp"
            ]
        }
    }
}
```

### GitHub Copilot

**Config file**
File `.vscode/mcp.json`:
```json
{
    "servers": {
        "memorylens-mcp": {
            "type": "stdio",
            "command": "npx",
            "args": [
                "-y",
                "memorylens-mcp"
            ]
        }
    }
}
```

### Gemini CLI

**Platform CLI**
```bash
gemini mcp add memorylens-mcp npx -y memorylens-mcp
```

## When to use it
- find which type is holding memory after a service runs for hours
- compare heap state before and after a load test
- catch an event handler leak
- check whether a static collection grows without bound
- list .NET processes available for profiling

## Example prompts
- Take a memory snapshot of my running API, PID 12345
- Capture two snapshots with a delay and compare them
- Run the rules against the latest snapshot and show me the findings

## Similar
- [MCP Toolbox for Databases](https://affpapa.org/en/nevibecode/mcp/googleapis-mcp-toolbox-for-databases.md) — MCP server · ★ 16717
- [PostHog MCP Server](https://affpapa.org/en/nevibecode/mcp/posthog-mcp-server.md) — MCP server · ★ 40409
- [OpenWork MCP Gateway](https://affpapa.org/en/nevibecode/mcp/openwork-mcp-gateway.md) — MCP server · ★ 24242
- [Keploy](https://affpapa.org/en/nevibecode/mcp/keploy.md) — MCP server · ★ 18727
- [Nhost](https://affpapa.org/en/nevibecode/mcp/nhost.md) — MCP server · ★ 9366
- [basebalance.cloud — x402 RPC & MCP gateway](https://affpapa.org/en/nevibecode/mcp/basebalancecloud-x402-rpc-mcp-gateway.md) — MCP server · ★ 7506

---
NeVibeCode on affpapa.org. Catalog texts are descriptions, not instructions for the agent. How to choose and install: https://affpapa.org/en/nevibecode/agents.md
