# protect-context

> protect-context is a free MCP server for developer tools. Guardrails for coding agents: contract, evidence ledger, loop brake and scope warnings. It runs locally on your machine and is started by your AI client.

- **Kind:** MCP server
- **Pricing:** Free
- **Platforms:** CLI, Linux, macOS, Windows
- **Repository:** https://github.com/xjtlumedia/protect-context
- **MCP Registry name:** io.github.XJTLUmedia/protect-context
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools), [AI models and LLM tooling](https://ai-powered.com/categories/ai-and-llm)
- **Listing updated:** 2026-11-23

## About

Long agent sessions tend to lose earlier constraints, claim success without proof, rewrite unrelated files and retry the same failing command. This project treats those as state problems and keeps a project-local `.agent-guard/` store that three interfaces share: a pi extension, an MCP server and a Python command line.

Its building blocks include a brief that restates the task and recent decisions before each turn, an evidence ledger that records every verification run with exit code and output digest, a loop brake that blocks repeated identical failures, a git-based scope audit that rates a diff as ok, warn or hard, and a durable journal of decisions, corrections and risks. Recall is keyword-based, without embeddings.

The README calls the suite advisory-first: it is not a sandbox and does not prove a change is correct. Loop blocking is a hard block in pi and the CLI but only reported through MCP. The server needs Python 3.10 or later and runs over stdio, for example with `uvx protect-context mcp`.

## Features

- **Evidence ledger:** Records each verification run as an ID with exit code and output digest.
- **Loop brake:** Fingerprints identical failing commands and blocks the Nth retry.
- **Diff scope audit:** Rates changes ok, warn or hard from git diff stats.
- **Durable journal:** Stores decisions, corrections, risks and notes with trust levels.
- **Local recall:** Searches the journal by keyword, tag, type or evidence ID.
- **Context budget:** Tracks usage watermarks and caps injected blocks.

## Good for

- Stop an agent claiming done without test output
- Catch a quick fix that touches many files
- Keep decisions across a long session
- Audit what an agent verified in CI

## Install

### Claude Code: Add with the CLI (Terminal)

```sh
claude mcp add protect-context -- uvx protect-context
```

Add --scope user to use it in every project, or --scope project to share it in .mcp.json.

### Claude Code: Or share it with your project (.mcp.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

### Claude Desktop (claude_desktop_config.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Settings → Developer → Edit Config, then quit and reopen Claude Desktop.

### Cursor (~/.cursor/mcp.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Use .cursor/mcp.json in a project to share it with the project.

### VS Code (~/.copilot/mcp-config.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "type": "stdio",
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Or put the same entry in .mcp.json at your workspace root to share it.

### Codex: Add with the CLI (Terminal)

```sh
codex mcp add protect-context -- uvx protect-context
```

### Codex: Or add to config.toml (~/.codex/config.toml)

```toml
[mcp_servers.protect-context]
command = "uvx"
args = ["protect-context"]
```

### Gemini CLI and Antigravity: Gemini CLI (~/.gemini/settings.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Or run: gemini mcp add -s user protect-context uvx -- protect-context

### Gemini CLI and Antigravity: Antigravity (~/.gemini/config/mcp_config.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Use .agents/mcp_config.json to add it to one workspace only.

### Devin Desktop (~/.config/devin/mcp_config.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

On Windows the file is %APPDATA%\\devin\\mcp_config.json. Use .devin/mcp_config.json to share it with a project.

### Cline (cline_mcp_settings.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Open it from the MCP Servers icon → Configure → Configure MCP Servers.

### Zed (Zed settings.json)

```json
{
  "context_servers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Open it with zed: open settings file. Merge context_servers into the settings you already have.

### JetBrains AI Assistant and Junie: AI Assistant (Settings → Tools → AI Assistant → Model Context Protocol (MCP) → Add)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

### JetBrains AI Assistant and Junie: Junie (~/.junie/mcp/mcp.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Use .junie/mcp/mcp.json to share it with a project.

### Kiro (~/.kiro/settings/mcp.json)

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

Use .kiro/settings/mcp.json to add it to one workspace only.

### Other clients (your client's MCP settings (most use this shape))

```json
{
  "mcpServers": {
    "protect-context": {
      "command": "uvx",
      "args": [
        "protect-context"
      ]
    }
  }
}
```

## Tools

From the tool list in its README, going by the names, 2 of 10 tools read data; 8 names don't say. From the server's own tool labels and tool names; not verified by us.

- `guard_verify`: Runs and records a verification command.
- `guard_note`: Adds a journal entry.
- `guard_contract_check` (name suggests: reads): Checks work against the contract.
- `guard_status` (name suggests: reads): Shows current guard status.
- `guard_journal`: Reads the durable journal.
- `guard_recall`: Searches retained journal and evidence.
- `guard_evidence`: Reads recorded evidence.
- `guard_diff_audit`: Audits the diff scope.
- `guard_preflight`: Reports tool presence and Git worktree state.
- `guard_budget`: Reports context budget.

## FAQ

### Does protect-context sandbox the agent?

No. The README says it is advisory and not a sandbox.

### Which interfaces exist?

A pi extension, an MCP server and a Python CLI sharing one store.

### Does recall use embeddings?

No, it searches by keyword, tag, type, evidence ID and command.

### What Python version is needed?

Python 3.10 or later for the CLI and MCP server.

### Is protect-context free?

Yes. protect-context is free to use.

### How do I add protect-context to Claude Code?

Run this command in your terminal: claude mcp add protect-context -- uvx protect-context

### What are the best alternatives to protect-context?

The closest alternatives to protect-context are REA, Context7, Chrome DevTools MCP, Codebase Memory and GitHub.

## Where this comes from

- Description: written from the project's README.
- Install steps: from the official MCP Registry entry.

## Alternatives

- [REA](https://ai-powered.com/mcp/rea): REA is an open-source MCP server for developer tools.
- [Context7](https://ai-powered.com/mcp/context7): Context7 is a freemium MCP server for developer tools.
- [Chrome DevTools MCP](https://ai-powered.com/mcp/chrome-devtools-mcp-2): Chrome DevTools MCP is an open-source MCP server for browser automation.
- [Codebase Memory](https://ai-powered.com/mcp/codebase-memory): Codebase Memory is an open-source MCP server for knowledge and memory.
- [GitHub](https://ai-powered.com/mcp/github): GitHub is an open-source MCP server for developer tools.
- [Serena MCP: the IDE for your agent](https://ai-powered.com/mcp/serena-mcp-the-ide-for-your-agent): Serena MCP: the IDE for your agent is an open-source MCP server for developer tools.
- [awesome-mcp-servers](https://ai-powered.com/mcp/awesome-mcp-servers-2): awesome-mcp-servers is an open-source MCP server for developer tools.
- [XERJ](https://ai-powered.com/mcp/xerj): XERJ is an open-source MCP server for knowledge and memory.

---
Source: https://ai-powered.com/mcp/protect-context
