Skip to main content

Context window management: compress, deduplicate, filter tool outputs

Project description

MCP Context Guard — Context Window Management for AI Agents

Compress tool outputs, manage token budgets, deduplicate content, and filter by relevance. Zero dependencies, pure Python stdlib.

The Problem

AI agents waste context window tokens on:

  • Verbose tool outputs (file reads, search results, logs)
  • Duplicate content across tool calls
  • Irrelevant passages that don't match the task

The Solution

MCP Context Guard sits between your tools and the LLM, compressing and filtering everything that enters the context window.

Tools (14)

Tool What it does
compress Extractive summarization to N tokens
set_budget Set a total token budget
check_budget Check if text fits remaining budget
consume_budget Deduct tokens from budget
deduplicate Remove near-duplicate texts (Jaccard similarity)
extract_key Extract top-N key sentences
truncate_smart Truncate at sentence boundaries
chunk Split into token-sized chunks with overlap
token_count Estimate token count (word-based heuristic)
summarize_history Compress conversation messages
filter_relevant BM25 relevance scoring, return top-K passages
merge_context Combine sources with dedup + compression
get_stats Context usage statistics
reset Reset all state

Install

git clone https://github.com/aaameobius-crypto/mcp-context-guard.git
cd mcp-context-guard
python -m src.server --stdio

Tests

python -m pytest tests/ -v  # 36 tests, all passing

Inspiration

License

MIT — aaameobius-crypto

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_context_guard-1.0.0.tar.gz (10.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_context_guard-1.0.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file mcp_context_guard-1.0.0.tar.gz.

File metadata

  • Download URL: mcp_context_guard-1.0.0.tar.gz
  • Upload date:
  • Size: 10.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for mcp_context_guard-1.0.0.tar.gz
Algorithm Hash digest
SHA256 9e4362139985fa5b3057453a510ad7e8686a8d254d38c7ce0f0342cf1897a27c
MD5 ce913c5da73620881ac790032731f679
BLAKE2b-256 2e43cbe69c7927522d20d12ff71d00d87c8ede4dc82b257755b7371a2245afe5

See more details on using hashes here.

File details

Details for the file mcp_context_guard-1.0.0-py3-none-any.whl.

File metadata

File hashes

Hashes for mcp_context_guard-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 09ad079401157c81b5ccb7d1c926d9952610e829765945c9eff3b93363f03e94
MD5 4454dc3bcb1fdc56d5f8e1c92c17e82d
BLAKE2b-256 a122bf6ab606b43dd03de9a912a731ef63309d9673f28e089a436593c463f433

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page