mcp-context-manager
Click on "Install Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@mcp-context-managercheck my context health and compress if needed"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
mcp-context-manager
1. Value Proposition
Long conversations make AI agents forget important things and burn money on old messages.
mcp-context-manager gives any AI agent simple tools to:
Score which messages matter
Compress and prune context
Search past conversations intelligently
Traverse conversation graphs
Produce clean, token-budget-ready context
All of this happens locally, with zero API keys and zero cost.
Related MCP server: claw-tsaver
2. Why this project exists
Problem | Result |
Context windows fill up | Agents lose focus and make mistakes |
Every extra token costs money | Bills grow fast on long sessions |
Most memory tools are heavy | Need databases, embeddings, cloud APIs |
Cloud memory tools raise privacy issues | Sensitive data leaves your machine |
This project was built to solve those problems with the simplest possible approach:
Pure Python
Heuristic scoring (no LLM needed for scoring)
Local JSON storage
Works with any MCP-compatible client (Claude Desktop, Cursor, etc.)
3. Features
Feature | Description |
Message Logging | Track every user, assistant, system and tool message |
Importance Scoring | Automatic 0–1 score based on role, keywords and length |
Context Health | 0–100 health score with warnings and suggestions |
Smart Compression | Keep high-importance + recent messages, drop the rest |
Token Savings Preview | See how many tokens you will save before compressing |
AI Context Query | Ask a natural language question and get relevant past messages |
Hybrid Search | Keyword + importance + recency ranking |
Graph Traversal | Walk the conversation as a graph of related messages |
Token-ready Context | Produce a clean string that fits exactly inside a token budget |
Session Management | Multiple independent sessions, clear anytime |
4. Architecture
flowchart TD
A[AI Agent / MCP Client] -->|calls tools| B[MCP Server<br/>server.py]
B --> C[Analyzer<br/>analyzer.py]
B --> D[Storage<br/>storage.py]
C --> E[Importance Scoring]
C --> F[Hybrid Search]
C --> G[Graph Traversal]
C --> H[Token-ready Packer]
D --> I[(Local JSON<br/>data/contexts.json)]
E --> C
F --> C
G --> C
H --> CSimple flow:
Agent sends a message →
add_messageWhen context gets large →
get_context_healthorestimate_token_savingsNeed focus →
compress_contextorget_token_ready_contextNeed specific info →
ai_context_query/hybrid_search_context/graph_traverse_context
5. Installation
# Clone the repo
git clone https://github.com/princeruhulofficial/mcp-context-manager.git
cd mcp-context-manager
# Install in editable mode
pip install -e .
# Run the server
python -m src.serverRequirements:
Python 3.10+
mcpandpydantic(installed automatically)
6. MCP Client Configuration
Claude Desktop / Cursor / any MCP client
{
"mcpServers": {
"context-manager": {
"command": "python",
"args": ["-m", "src.server"],
"cwd": "/absolute/path/to/mcp-context-manager"
}
}
}Replace /absolute/path/to/mcp-context-manager with the real path on your machine.
7. All Tools
7.1 add_message
Purpose: Log a new message into a session so the manager can track history.
Parameter | Type | Required | Description |
| string | Yes | Any string that identifies the conversation |
| string | Yes |
|
| string | Yes | The message text |
Returns:"Added message abc123 (importance=0.75, ~42 tokens)"
Example:
{
"session_id": "project-alpha",
"role": "user",
"content": "Remember our goal is to launch by Friday"
}7.2 get_context_health
Purpose: Check how healthy the current context is (0–100 score).
Parameter | Type | Required | Description |
| string | Yes | Session to inspect |
Returns (JSON):
{
"session_id": "project-alpha",
"message_count": 27,
"estimated_tokens": 4820,
"health_score": 68.5,
"warnings": ["Context is getting large (>8k tokens). Consider compression."],
"suggestions": ["Call compress_context to free space."]
}7.3 compress_context
Purpose: Keep high-importance + recent messages and drop the rest.
Parameter | Type | Required | Default | Description |
| string | Yes | – | Session to compress |
| float | No | 0.4 | How much of original to keep (0.3–0.6 recommended) |
Returns (JSON):
{
"original_tokens": 8200,
"compressed_tokens": 3100,
"tokens_saved": 5100,
"savings_percent": 62.2,
"summary": "Compressed history highlights:\n...",
"kept_message_ids": ["a1b2", "c3d4", ...]
}7.4 estimate_token_savings
Purpose: Preview savings without changing anything.
Parameter | Type | Required | Default |
| string | Yes | – |
| float | No | 0.4 |
Returns:
Original: ~8200 tokens
After compression: ~3100 tokens
Saved: 5100 tokens (62.2%)7.5 score_message_importance
Purpose: Re-calculate importance of one specific message.
Parameter | Type | Required |
| string | Yes |
| string | Yes |
Returns:"Message a1b2 importance = 0.82"
7.6 list_sessions
Purpose: See all tracked sessions.
Returns:
Sessions:
- project-alpha
- support-chat-427.7 clear_session
Purpose: Delete all context for a session.
Parameter | Type | Required |
| string | Yes |
Returns:"Cleared session project-alpha"
7.8 ai_context_query
Purpose: Ask a natural language question and get the most relevant past messages.
Parameter | Type | Required | Default |
| string | Yes | – |
| string | Yes | – |
| int | No | 5 |
Returns: Ranked list of relevant messages with scores.
7.9 hybrid_search_context
Purpose: Built-in Hybrid Search (keyword + importance + recency).
Parameter | Type | Required | Default |
| string | Yes | – |
| string | Yes | – |
| int | No | 5 |
Returns (JSON): List of matches with message_id, role, content, score, reason.
7.10 graph_traverse_context
Purpose: Walk the conversation graph starting from a message (or the most important one).
Parameter | Type | Required | Default |
| string | Yes | – |
| string | No | most important |
| int | No | 8 |
Returns: List of related messages in traversal order.
7.11 get_token_ready_context
Purpose: Create a clean context string that fits inside a token budget (ready to paste into an LLM).
Parameter | Type | Required | Default | Description |
| string | Yes | – | Session |
| int | No | 2000 | Max tokens allowed |
| string | No |
|
|
| string | No | null | Used when mode= |
Returns (JSON):
{
"session_id": "project-alpha",
"token_budget": 2000,
"used_tokens": 1874,
"message_count": 9,
"context_text": "[USER] ...\n\n[ASSISTANT] ...",
"source": "hybrid"
}8. Scoring Methodology
Importance score (0.0 – 1.0) is calculated with simple heuristics:
Factor | Effect |
Role = | +0.30 |
Role = | +0.20 |
Role = | +0.10 |
Important keywords present | +0.04 each |
Message longer than 300 chars | +0.10 |
Message longer than 150 chars | +0.05 |
Important keywords currently include:error, fail, important, remember, goal, must, critical, decision, final, priority, deadline, key, summary, conclusion, action
Health score (0–100) starts at 100 and is reduced by:
High total token count
High message count
9. Examples
Example 1 – Basic tracking
add_message(session_id="demo", role="user", content="Our deadline is next Monday")
add_message(session_id="demo", role="assistant", content="Got it. I will prioritise the launch tasks.")
get_context_health(session_id="demo")Example 2 – Search + Token-ready context
ai_context_query(session_id="demo", question="What is the deadline?")
get_token_ready_context(session_id="demo", token_budget=1500, mode="hybrid", query="deadline")Example 3 – Compression
estimate_token_savings(session_id="demo", target_ratio=0.4)
compress_context(session_id="demo", target_ratio=0.4)10. Use Cases
Use Case | How this helps |
Long coding sessions | Keep only decisions, errors and current goals |
Customer support agents | Retrieve relevant past tickets without full history |
Research / multi-step reasoning | Graph traversal finds related insights |
Cost control | Token-ready context keeps every LLM call inside budget |
Privacy-sensitive work | Everything stays on your machine |
11. Design Principles
Local-first – No cloud, no external API calls for core logic
Zero API keys – Works completely offline
Simple heuristics – Fast, predictable, easy to understand
Token awareness – Every tool thinks about cost
Agent-friendly – Tools are small and composable
Safe by default – Compression does not auto-delete unless you ask
12. Performance
Operation | Typical speed | Notes |
| < 5 ms | In-memory + JSON write |
| < 20 ms | For a few hundred messages |
| < 30 ms | Limited by |
| < 40 ms | Packing is linear |
| < 50 ms | Pure Python |
Suitable for real-time use inside agent loops.
13. Security & Privacy
All data is stored locally in
data/contexts.jsonNo network calls are made by the core logic
No telemetry, no analytics, no external embeddings
You fully control when to clear sessions
MIT licensed – audit the code yourself
14. FAQ
Q: Does this need an OpenAI / Anthropic key?
A: No. Scoring and search are pure heuristics.
Q: Can I use it with Claude Desktop?
A: Yes. Just add the MCP config shown above.
Q: Will compression delete my messages forever?
A: The current compress_context only returns a plan. It does not auto-write the reduced set unless you extend it.
Q: How accurate is the token estimate?
A: It is a fast approximation (words + characters). Good enough for budgeting, not perfect.
Q: Can I run multiple sessions?
A: Yes. Each session_id is completely independent.
15. Roadmap
Optional real embedding-based semantic search (still local)
Automatic compression when health score drops below threshold
Export / import session snapshots
Simple web dashboard for inspection
Streaming support for very large histories
Plugin system for custom scoring rules
16. Contributing
Contributions are welcome!
Fork the repository
Create a feature branch
Add tests if possible
Open a Pull Request
Please keep the spirit of the project: simple, local-first, and easy to understand.
17. License
MIT License © Prince Ruhul
This server cannot be installed
Maintenance
Related MCP Servers
- Alicense-qualityBmaintenanceAn MCP server that extends AI agents' context window by providing tools to store, retrieve, and search memories, allowing agents to maintain history and context across long interactions.Last updatedMIT
- AlicenseAqualityBmaintenanceAn MCP server that helps AI agents reduce token usage by compressing, summarizing, and managing conversation/context data more efficiently.Last updated11MIT
- Alicense-qualityDmaintenanceAn MCP server that helps AI agents reduce token usage by converting data to TOON format and stripping comments and unnecessary whitespace from code files.Last updatedMIT
- Alicense-qualityAmaintenanceProvides reversible context compression for AI agents, reducing token usage while preserving the ability to retrieve original content, and serves as an MCP server for integration with tools like GitHub Copilot and Claude Code.Last updated1Apache 2.0
Related MCP Connectors
A comprehensive Model Context Protocol (MCP) server that enables AI assistants to interact with yo…
Cloud-hosted MCP server for durable AI memory
MCP server for AI dialogue using various LLM models via AceDataCloud
Latest Blog Posts
- Who's Calling? MCP Hosts Are an Identity Blind Spot (And the Spec Knows It)By Om-Shree-0709 on .mcpAgent IdentityOAuth 2.1
- Your AI Chatbot Just Exposed Your CEO's Salary to an InternBy Om-Shree-0709 on .Agent IdentityMCP SecurityOAuth Delegation
- Why MCP Servers Need Execution Sandboxing (And Why Your Current Stack Isn't Enough)By Om-Shree-0709 on .Agentic AiPrompt InjectionWebAssembly
MCP directory API
We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/princeruhulofficial/mcp-context-manager'
If you have feedback or need assistance with the MCP directory API, please join our Discord server