Context Mode
MCP server that reduces AI agent context usage by sandboxing tool outputs, indexing session data, and preserving workflow continuity.
Context Mode is an open-source MCP (Model Context Protocol) server designed to reduce context window bloat in AI coding agents by intercepting and restructuring how tool outputs are handled. Instead of allowing raw tool responses (such as logs, file contents, or web snapshots) to flow directly into the model’s context, Context Mode executes these operations in a sandboxed environment and stores the results locally for retrieval when needed.
The core mechanism is a “context offloading” system. Large outputs from tools like file readers, browsers, or API calls are captured outside the context window and indexed into a local SQLite database using full-text search (FTS5) with BM25 ranking. The AI model then retrieves only the relevant fragments instead of processing entire raw datasets, significantly reducing token usage while preserving functionality.
In addition to compression of tool outputs, Context Mode tracks session-level events such as file edits, git operations, task execution, and errors. These events are persisted locally and reloaded across sessions, enabling continuity even after context compaction. This allows AI agents to resume work without losing state or requiring full rehydration of previous context.
The system also promotes a “think in code” approach, encouraging AI agents to generate scripts for data processing tasks instead of loading large datasets into context for manual reasoning. This further reduces token consumption and improves scalability in complex workflows.
Context Mode operates as a protocol-level layer between AI agents and tools, meaning it integrates with multiple coding environments and CLI-based AI systems. It is fully local-first, with no cloud dependency or telemetry, and is designed for privacy-sensitive development environments.
Key features include:
- Sandboxed execution of tool calls to prevent context overflow
- Local indexing of outputs using SQLite FTS5 + BM25 search
- Session persistence across compaction cycles
- Context reduction of up to ~98% for large tool outputs
- “Think in code” execution model for data-heavy tasks
- Support for multiple AI coding environments via MCP integration
- Fully local-first architecture with no telemetry or cloud sync
- Cross-session continuity for long-running AI workflows
Common use cases include:
- AI-assisted software development with large codebases
- Log analysis and debugging workflows
- Long-running agent sessions requiring state persistence
- Reducing token cost in tool-heavy AI pipelines
- Building persistent AI coding environments
Context Mode is developed as an open-source project by mksglu and is positioned as a foundational infrastructure layer for managing AI context efficiently in developer tooling ecosystems.
Comments
0Markdown is supported.