@yavdaanalytics/context-optimiser
A context window optimizer and session rotator MCP server for agentic workflows that prevents LLMs from running out of context by compacting chat history and rotating sessions.
README
@yavdaanalytics/context-optimiser
A context window optimizer and session rotator MCP server for agentic workflows. It prevents LLMs/coding agents from running out of context window space by estimating token usage, compacting chat history using semantic failure clustering (Topic Attempt Graph - TAG), and rotating chat sessions dynamically while preserving session continuity links.
Features
- Token Estimation: Heuristically counts and budgets tokens for a conversation.
- Context Compaction: Uses semantic failure clustering (TAG) and heuristic offloading to shrink conversational history, offloading large code dumps/logs to disk or local ChromaDB.
- Session Auto-Rotation: Dynamically rotates chat sessions when context limit thresholds are reached, updating next/previous session pointers for linked context history.
- Local Vector Search: Stores offloaded messages in ChromaDB and retrieves them via semantic similarity search.
Quick Start
1. Installation
Install globally via npm:
npm install -g @yavdaanalytics/context-optimiser
2. Setup
Run the setup utility to configure the MCP server globally for Gemini, Cursor, and Claude Desktop, and copy the agent loading skills:
context-optimiser-setup
This will automatically configure:
- Gemini:
~/.gemini/settings.json - Cursor:
~/.cursor/mcp.json - Claude Desktop:
~/.claude/settings.jsonand%APPDATA%/Claude/claude_desktop_config.json - Loader Skills: Copies
SKILL.mdto~/.cursor/skills/context-optimiser/SKILL.md,~/.claude/skills/context-optimiser/SKILL.md, and~/.gemini/config/skills/context-optimiser/SKILL.md.
MCP Tools API
The server registers the following MCP tools for client use:
estimate_tokens(conversation): Returns estimated token usage, capacity limits, and percentage used.compact_context(conversation, strategy, keep_last_n_turns): Returns compacted message history.rotate_session(conversation, origin_prompt, token_limit, threshold_pct): Returns rotated session metadata and compacted history.get_current_session(): Returns active session JSON metadata.query_vector_store(query_text, n_results): Performs semantic vector similarity queries on offloaded history.
Development & Local Testing
If you are developing locally, run setup in local mode to link the configuration to your checkout directory:
node bin/setup.js --local
Run Tests
To verify all tool integrations and ChromaDB vector queries:
python scratch/test_tools.py
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.