context-guard
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@context-guardcheck memory and scan my workspace for bloat"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
devin-resource-guard-mcp
A Model Context Protocol (MCP) server for autonomous coding agents such as Devin, Cursor, and Claude Code. It runs over stdio and targets two common failure modes in long agent sessions: context bloat and out-of-memory (OOM) crashes.
Features
Resource headroom checks: On each call, it reports memory, CPU, and disk headroom. Inside a container, it reads the cgroup memory limit from
/sys/fs/cgroup(v1 and v2), so the numbers reflect the container rather than the host. When effective free memory falls below a threshold (500 MB by default), it returns a structuredNEAR_OOM_THRESHOLDwarning with recommended actions. The agent can then back off before the OOM killer or a cgroup limit ends its process.Workspace context optimization: It scans a workspace for token-heavy, low-value paths such as dependency trees, build output, large logs, binary artifacts, minified bundles, and lockfiles. It ranks them by estimated token cost and returns
exclude_globsthat keep them out of the agent's context.
Works with any MCP client, including Devin, Claude Desktop, Claude Code, Cursor, and VS Code. This is an independent project, not affiliated with Cognition.
Tools
inspect_resource_limits
Argument | Type | Default | Description |
| string | server's cwd | Path whose filesystem is checked for free space |
It returns memory (total, available, and cgroup-aware effective available), CPU utilisation and load average, and disk usage.
status takes one of three values:
| Meaning |
| Nothing is wrong. |
| Disk space is low or the CPU is saturated. |
| Effective available memory is below 500 MB. A top-level |
Example of the low-memory warning:
{
"status": "warning",
"alert": {
"code": "NEAR_OOM_THRESHOLD",
"severity": "critical",
"message": "Only 412.3 MB of memory is available (threshold 500.0 MB). The process is at risk of being killed by the OOM killer or a cgroup memory limit.",
"available_bytes": 432324608,
"threshold_bytes": 524288000,
"cgroup_limited": true,
"recommended_actions": [
"Pause spawning new subprocesses, builds, or test runners.",
"Run memory-heavy commands serially with reduced parallelism (e.g. -j1, --runInBand, --maxWorkers=1).",
"..."
]
},
"memory": { "...": "..." },
"cpu": { "...": "..." },
"disk": { "...": "..." },
"alerts": [ "..." ]
}Inside a container, the server reads /sys/fs/cgroup (v1 and v2), so the warning reflects the container's limit rather than the host's total RAM.
optimize_workspace_context
Argument | Type | Default | Description |
| string | — | Absolute path to the workspace root (required) |
| number |
| Flag any file at or above this size |
| number |
| Flag |
| int |
| Maximum recursion depth (capped at 64) |
| bool |
| Also report paths already covered by ignore files |
The scan detects:
Kind | Examples |
|
|
|
|
|
|
|
|
| large |
| any other file over |
The response ranks findings by size and estimated token cost (about 4 bytes per token). It also includes exclude_globs that you can paste into .cursorignore, .aiignore, or an agent's deny list:
{
"status": "ok",
"summary": {
"findings": 7,
"excludable_size": "1.8 GB",
"estimated_tokens_saved": 483183820
},
"exclude_globs": ["**/node_modules/", "**/dist/", "logs/server.log", "**/*.log"],
"findings": [
{ "path": "node_modules/", "kind": "bloat_directory", "size": "1.2 GB", "estimated_tokens": 322122547, "already_ignored": false }
]
}The scanner reads .gitignore, .cursorignore, .codeiumignore, .aiignore, and .dockerignore at the root, so by default it reports only paths that are not yet ignored.
Related MCP server: DevTwin MCP
Quick start
Requires Python 3.10+.
git clone https://github.com/crona16/devin-resource-guard-mcp.git
cd devin-resource-guard-mcp
python -m venv .venvActivate the virtualenv:
# macOS / Linux
source .venv/bin/activate# Windows (PowerShell)
.venv\Scripts\Activate.ps1Install the dependencies:
pip install -r requirements.txtConfirm that the server starts. It will wait silently on stdin, and you can stop it with Ctrl+C:
python server.pyTo exercise the tools interactively, use the official MCP Inspector. It needs Node.js:
npx @modelcontextprotocol/inspector .venv/bin/python server.pyConnecting to an agent
Every client below takes the same two things:
command: the absolute path to the virtualenv's Python interpreter.
macOS / Linux:
/abs/path/devin-resource-guard-mcp/.venv/bin/pythonWindows:
C:\\abs\\path\\devin-resource-guard-mcp\\.venv\\Scripts\\python.exe
args: the absolute path to
server.py.
Use absolute paths. GUI apps don't inherit your shell's
PATHor working directory, so a barepythonoften resolves to the wrong interpreter, one withoutmcpinstalled.
Cursor
Edit ~/.cursor/mcp.json to make the server available globally, or .cursor/mcp.json in a project to scope it to that project:
{
"mcpServers": {
"context-guard": {
"command": "/abs/path/devin-resource-guard-mcp/.venv/bin/python",
"args": ["/abs/path/devin-resource-guard-mcp/server.py"],
"env": {
"CONTEXT_GUARD_LOW_MEMORY_MB": "500"
}
}
}
}Then open Settings → MCP and confirm that context-guard shows a green dot with 2 tools.
Devin (Desktop / local MCP)
Add the server through Devin's MCP settings (Settings → MCP servers → Add custom server) as a stdio server:
Field | Value |
Name |
|
Transport |
|
Command |
|
Arguments |
|
Env |
|
If your Devin build accepts a JSON config instead, use the same mcpServers block as in the Cursor example. The exact menu path varies between Devin releases, so check Devin's MCP documentation if the menu items above don't match.
Claude Desktop
Edit the config file for your platform:
macOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonWindows:
%APPDATA%\Claude\claude_desktop_config.json
Add the same mcpServers block as in the Cursor example, then restart the app.
Claude Code
claude mcp add context-guard -- /abs/path/devin-resource-guard-mcp/.venv/bin/python /abs/path/devin-resource-guard-mcp/server.pyVS Code (Copilot agent mode)
Create .vscode/mcp.json:
{
"servers": {
"context-guard": {
"type": "stdio",
"command": "${workspaceFolder}/../devin-resource-guard-mcp/.venv/bin/python",
"args": ["${workspaceFolder}/../devin-resource-guard-mcp/server.py"]
}
}
}Suggested agent rule
Add a rule like this to your agent's rules or system prompt so it actually uses the tools:
Before starting a build, test suite, or large refactor, call
inspect_resource_limits. Ifstatusiswarning, followalert.recommended_actionsbefore continuing. When you open a new workspace, calloptimize_workspace_contextonce, and never read paths that match itsexclude_globs.
Configuration
All settings are optional environment variables:
Variable | Default | Purpose |
|
| Memory threshold for the |
|
| Free-disk threshold for |
|
| CPU threshold for |
| (unset) |
|
|
| Maximum number of filesystem entries visited per scan |
|
| Maximum time per scan (results are marked |
|
| stderr log verbosity |
Design notes
stdout is used only for the protocol. All logging goes to stderr, and the code never calls
print(). Errors are returned as structured{"status": "error", "error": {...}}payloads instead of being raised, so one bad path doesn't kill the session.The event loop stays free. psutil sampling and filesystem walks run in
asyncio.to_thread.The scanner is safe by default. It never follows symlinks, it never descends into bloat directories (it only measures their size), it is bounded by time and file-count budgets, and it can be confined with
CONTEXT_GUARD_ALLOWED_ROOTS.The scanner is read-only. It deletes or modifies nothing. It only returns recommendations.
Limitations
Ignore-file matching is a lightweight
fnmatchapproximation, not a full gitignore engine. Negation (!pattern) is skipped. The matching only affects thealready_ignoredflag, never what gets scanned.Token estimates use a fixed rate of about 4 bytes per token. Treat them as an order of magnitude.
Generic directory names such as
bin/,out/,env/, andvendor/are flagged by name alone. Review findings before you exclude them.
License
MIT
This server cannot be deployed
Maintenance
Related MCP Connectors
Codebase graphs, caller impact analysis, and recorded project context for AI coding agents.
Codebase intelligence for AI agents — dead code, blast radius, ownership.
Cross-agent artifact workspace with provenance across Claude Code, Codex, Cursor, LangGraph.
Lets coding agents check their own code for leaked secrets, risky dependencies and AI-code mistakes
Related MCP Servers
- AlicenseCqualityCmaintenanceProfessional local context management and system diagnostic tools for AI IDEs (Cursor, Trae, Antigravity, Windsurf).3684 npm1MIT
- AlicenseAqualityBmaintenanceProvides AI coding agents with structured, evidence-based diagnostics about the local development environment, detecting tech stack, runtime mismatches, dependency state, services, ports, and Git status without exposing secrets or using network calls.10Apache 2.0
- AlicenseAqualityAmaintenanceEnables AI assistants to audit and clean development workspaces safely by detecting reclaimable artifacts, exposed .env files, and potential secret leaks.6MIT
- AlicenseNot gradedqualityCmaintenanceProvides coding agents with pre-flight cost estimation by analyzing local logs to forecast token usage and quota impact before expensive work, exposing tools for remaining quota, per-task cost estimates, and attempt affordability.36 npmMIT