Skip to main content
Glama
README.md
# ContextForge MCP — Deterministic Token Compressor & Context-Window Compiler

**Live Remote MCP Endpoint (Streamable HTTP · Zero Auth · Zero LLM Calls):** `https://context-forge-mcp.yashwant938.workers.dev/mcp`  
**Live Interactive Edge Playground:** https://context-forge-mcp.yashwant938.workers.dev  
**Official MCP Registry ID:** `io.github.yashwant938/context-forge-mcp`

**ContextForge MCP** is a zero-dependency **Model Context Protocol (`2025-03-26`) server**, standalone CLI, and installable **Agent Plugin** that cuts **60–90% of context-window bloat deterministically**—with zero external LLM API keys, zero runtime dependencies, and exact line-number traceability.

Most agent failures in production aren't model-intelligence failures—they're **context-harness failures**:
1. **Codebase Overload** — Dumping 25 raw files burns 40,000+ tokens and triggers *Lost-in-the-Middle* recall decay.
2. **Noisy Terminal Logs & Giant JSON Dumps** — Repetitive timestamps, UUIDs, healthcheck lines, and 500-row API arrays drown out the 3 lines that actually explain the crash.
3. **Silent RAG Encoder Truncation** — Chunks exceeding 256 tokens (`all-minilm-l6-v2`) or 512 tokens (`bge-small-en`) are silently chopped off during embedding, while redundant chunks waste generation context.
4. **Blind Token Economics** — Connecting 30+ eager MCP tools quietly burns 6,000–12,000 tokens *every single turn* before the user even writes a sentence.

ContextForge replaces ad-hoc truncation with **deterministic multi-language code skeletonization, Drain-style log clustering, JSON/OpenAPI schema folding, token-bounded RAG re-chunking + U-shaped attention packing, and BM25 multi-fidelity budget compilation**.

---

## Quick Connect (Claude Code, Cursor, Antigravity, Windsurf, Codex)

### Option A — Hosted Remote MCP (5 Seconds · Zero Install · Zero Auth)

```json
{
  "mcpServers": {
    "context-forge": {
      "url": "https://context-forge-mcp.yashwant938.workers.dev/mcp"
    }
  }
}
```

### Option B — Local Stdio MCP (Unlocks Direct Disk `compile_repo_context`)

```json
{
  "mcpServers": {
    "context-forge-local": {
      "command": "node",
      "args": ["/absolute/path/to/context-forge-mcp/bin/context-forge-mcp.mjs"]
    }
  }
}
```

### Option C — Standalone CLI (Zero Dependencies · Node >= 20)

```bash
# BM25-rank & pack a repository into a strict 6,000-token XML bundle
node bin/cli.mjs pack . "authentication jwt refresh" 6000

# Skeletonize any JS/TS/Python/C++/Go/Rust/Java file with Lstart-Lend ranges
node bin/cli.mjs skeleton src/engines/codeSkeletonizer.mjs signatures

# Cluster a noisy CI/Docker/server log into prioritized error templates + unique stack traces
node bin/cli.mjs logs build.log

# Compact a huge JSON payload or OpenAPI 3.x spec into an inferred schema + stats
node bin/cli.mjs json openapi.json

# Simulate multi-turn token growth, compaction cliff & monthly USD savings
node bin/cli.mjs budget claude-sonnet-4 35 25
```

---

## MCP Primitives Implemented (7 Tools · 4 Resources · 3 Prompts)

### 7 Deterministic MCP Tools

| Tool | Transport | What It Computes |
| :--- | :---: | :--- |
| `compile_repo_context` | Local `stdio` | Walks a repo on disk (ignoring `.git`, `node_modules`, lockfiles, `.env`, binaries) → ranks files against `taskQuery` via **BM25** → compiles a strict token-budgeted XML context pack mixing full code + line-indexed skeletons |
| `compile_context_pack` | Remote & Local | Multi-artifact **BM25 + multi-fidelity** context compiler over source files, logs, and JSON passed over HTTP, with a dropped-file manifest for on-demand expansion |
| `skeletonize_code` | Remote & Local | Multi-language skeletonizer (**JS/TS, Python, C/C++, Go, Rust, Java**) with 3 modes: `signatures` (65–88% savings), `outline`, and `symbol-focus` (keeps full bodies only for target symbols) |
| `compress_logs_and_traces` | Remote & Local | **Drain-style** template normalizer (timestamps, UUIDs, IPs, hex, numbers) + severity-prioritized clustering + unique stack-trace extraction (70–95% savings) |
| `compact_json_and_api` | Remote & Local | Collapses giant JSON arrays into inferred typed schemas (`min..max`, `enum`, optionality, 1 trimmed sample) and compacts **OpenAPI 3.x / Swagger** specs into route & component tables (75–92% savings) |
| `audit_and_pack_rag_context` | Remote & Local | Audits encoder truncation (`MiniLM 256`, `BGE/E5 512`, `Nomic 2048`, `OpenAI 8191`, `Voyage 32k`), re-chunks to **0% overflow**, deduplicates via **Jaccard similarity**, and applies **Lost-in-the-Middle U-shaped ordering** |
| `simulate_context_budget` | Remote & Local | Turn-by-turn token trajectory across **8 frontier models** (`Claude Sonnet/Opus 4`, `GPT-5`, `GPT-4.1`, `Gemini 2.5 Pro/Flash`, `DeepSeek V3`, `Qwen3 Coder`), calculating MCP schema tax, compaction cliff turn, prompt caching, and monthly USD savings |

### 4 MCP Resources (`resources/list`, `resources/read`)
- `context-forge://guide/compression-playbooks` — Deterministic strategy matrix by artifact type
- `context-forge://guide/model-pricing-windows` — Frontier context windows, attention sweet spots & cached pricing
- `context-forge://guide/lost-in-the-middle` — Encoder truncation limits & U-shaped attention packing
- `context-forge://guide/mcp-token-hygiene` — Avoiding eager MCP tool-schema bloat

### 3 MCP Prompts (`prompts/list`, `prompts/get`)
- `compress-debug-session` — Cluster raw crash logs + pack suspect source files before diagnosing a bug
- `pack-repo-for-feature` — BM25 repo packing workflow before multi-file implementation
- `optimize-rag-pipeline` — Encoder overflow audit + near-duplicate pruning + U-shaped reordering

---

## Development, Testing & Deployment

```bash
# Run full unit + local stdio MCP + Cloudflare Worker Streamable HTTP tests
npm test

# Dogfood BM25 repo packer on ContextForge's own codebase
npm run pack:self

# Build zero-dependency Cloudflare Worker bundle (dist/worker.mjs)
npm run build:worker

# Deploy to Cloudflare Workers Edge
npx wrangler deploy
```

Related project: [ArchGuard MCP (Architecture Drift, SQL DDL & Distributed Systems Verifier)](https://arch-guard-mcp.yashwant938.workers.dev)

TDQS

A3.7/5.0

Scored across 7 tools

Disambiguation4/5

Each tool targets a distinct artifact type (JSON/OpenAPI, source code, logs/traces, RAG passages) or task (repo walk, budget simulation), so purposes are mostly clear. The three 'pack/compile' tools (compile_context_pack, compile_repo_context, audit_and_pack_rag_context) overlap somewhat since all produce budgeted context, but input-source differences in the descriptions help disambiguate.

Naming Consistency4/5

Names follow a consistent snake_case, verb-led convention (compact_, compile_, skeletonize_, compress_, audit_and_pack_, simulate_). Minor deviations: audit_and_pack_rag_context uses two verbs, and compress vs compact are near-synonyms, but overall pattern is predictable.

Tool Count5/5

Seven tools is well-scoped for a context/token-optimization toolkit, with each tool covering a distinct compression or analysis concern. No redundant or filler tools.

Completeness4/5

The surface broadly covers artifact compaction (JSON, code, logs), context packing (multi-artifact, repo, RAG), and budget simulation, forming a coherent lifecycle. Minor gaps: no standalone token-count/validation tool and no inverse (expand/restore) operations, though simulate_context_budget partially covers estimation.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues