Skip to main content
Glama

AgentContext

Reversible context optimization for AI agents. AgentContext is a local-first MCP server that turns oversized tool output — long test logs, large JSON responses, whole files, diffs, repeated content — into smaller, structured results, while keeping the original on your machine so the agent can recover any omitted part exactly.

  • Deterministic — no LLM calls, no API key; same input, same output.

  • Reversible — every omission is recorded and recoverable byte-for-byte.

  • Conservative — nothing is judged irrelevant unless you ask; when in doubt the original is returned.

  • Local — no telemetry, no network; data stays in your user profile.

  • Measured — token counts are labelled as estimates; benchmarks include the cost of recovery.

Status: v0.1.0 release candidate. See limitations.

Quick start

Requires Node.js ≥ 22.13.

# Claude Code (after the npm release)
claude mcp add agentcontext -- npx -y @agentcontext/mcp-server

# from a source checkout
pnpm install && pnpm build
claude mcp add agentcontext -- node /absolute/path/to/AgentContext/apps/mcp-server/dist/cli.js

Then ask your agent to pass long outputs through optimize_context, or to read large files with read_file. Full guide: Getting started.

Related MCP server: cap-shield-mcp

What it looks like

Real output for the terminal-large benchmark input (a 1,000-line test run), abridged:

2026-11-23T10:00:00Z INFO [db] pool size=10 idle=8
[... s1: repeated 719 more times (lines 7-11, 14-19, 22-27, ... (+117 more))]
2026-11-23T10:00:06Z INFO [http] GET /health 200 2ms
[... s2: repeated 119 more times (lines 20, 28, 37, ... (+116 more))]
 ✓ src/module001.test.ts (11 tests) 10ms
...
 FAIL  src/billing/invoice.test.ts > computes totals with tax
AssertionError: expected 118.5 to be 118.05 // Object.is equality
    at src/billing/invoice.test.ts:42:19
...
---
[agentcontext] log-compressor: 2734/22049 tokens (estimated), 87.6% saved.
Recover omitted parts (s1, s2, s3, s4) with retrieve_context {"contextId":"ctx_01M8...","selector":{"type":"segment_id","value":"<sN>"}}, or omit the selector for the full original.

Tools

Tool

Purpose

optimize_context

Compress text; optional selections (JSON paths, Markdown sections, line ranges, log levels) and token budgets

retrieve_context

Recover the full original, a line range, a JSONPath, keyword matches, or a segment

read_file

Read and optimize a file inside the allowed project roots

execute_command

Run an allowlisted command (no shell) and optimize its output — disabled by default

get_optimization_stats

Tokens saved, including what was recovered

Plus the resources agentcontext://stats and agentcontext://context/{id}/metadata, and the agentcontext_guidelines prompt. Reference: docs/tools.md.

Benchmarks

On seven reproducible scenarios (test logs, API responses, duplicate-heavy text, documentation, source code, diffs), counting recovered content:

Median reduction

Extraction accuracy

Recovery integrity

Unrecoverable omissions

86.6%

100%

100%

0

Synthetic datasets, estimated tokens and a deterministic oracle — see the full report and methodology. Run them yourself with pnpm bench.

Documentation

Development

pnpm install
pnpm check      # lint + typecheck + test + build
pnpm bench      # benchmarks and reports

Monorepo: apps/mcp-server (the only package that imports the MCP SDK), packages/{shared,core,strategies,tokenization,storage,retrieval,observability}, benchmarks/. See CONTRIBUTING.md.

Security

Report vulnerabilities privately — see SECURITY.md.

License

Apache License 2.0.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables AI agents to compress and selectively retrieve context, with measured recall rather than claimed performance. It provides tools to assess potential traffic and token savings, list compression dictionaries, and assemble relevant memory entries within a token budget.
      MIT
    • F
      license
      Not graded
      quality
      B
      maintenance
      Shrinks logs, JSON, docs and web pages before your AI reads them: offline, deterministic, no API key. Folds repetitive log lines (12,037 to 127 tokens on a 400-line log) while code, URLs and quoted strings come back byte-for-byte. Also fetches URLs as clean text, counts tokens exactly, and has optional local Ollama tools for image and text compression.
      59 PyPI
      25
      -