mcp-working-context-optimizer
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-working-context-optimizercompress the history and clear recent logs"
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-working-context-optimizer
An MCP (Model Context Protocol) server designed to optimize the working context of AI agents. It prevents context bloat and the "Lost in the Middle" phenomenon by distilling action histories into concise summaries while maintaining a clear core objective.
🌟 The Problem it Solves
Current autonomous AI agents (like AutoGPT, Cline, or custom smolagents) tend to append all tool execution logs and error messages directly into their context window. This naive approach quickly leads to:
Context Bloat & OOM: Exceeding the token limit or causing Out-Of-Memory errors on local LLM servers due to massive KV cache expansion.
Lost in the Middle: The agent gets distracted by recent, verbose error logs and forgets the original, overarching objective.
Related MCP server: Memory MCP Server
💡 The Solution: Dual-Track Memory
This MCP server acts as an external "Working Memory" for the agent. It enforces a structured context containing:
Current Task: The immediate next step or user instruction.
Core Objective: The ultimate goal (never truncated, always focused).
Summarized History: A compressed version of past events.
Recent Actions: Raw logs of the last few steps (auto-truncated to prevent bloat).
When the recent actions limit is reached, the server proactively prompts the agent to summarize the history and clear the logs, keeping the context perfectly optimized.
🚀 Installation
Ensure you have Python 3.10 or higher. Using uv is recommended.
# Clone the repository
git clone [https://github.com/your-username/mcp-working-context-optimizer.git](https://github.com/your-username/mcp-working-context-optimizer.git)
cd mcp-working-context-optimizer
# Install via uv (or pip)
uv pip install -e .⚙️ Usage / Configuration
To use this with an MCP client (like Claude Desktop, Cursor, or Cline), add the following to your MCP settings file (e.g., mcp_config.json or claude_desktop_config.json):
{
"mcpServers": {
"working-context-optimizer": {
"command": "mcp-working-context-optimizer"
}
}
}(Note: If using uv, you might need to specify the absolute path to the executable or run via uvx depending on your environment).
🛠️ Provided Tools & Resources
Resources
working-context://state: Returns the optimized Markdown representation of the current working context. The agent should read this when losing track of the context or starting a new task.
Tools
set_core_objective(objective: str): Sets the primary goal and constraints.update_current_task(task: str): Sets the immediate, short-term focus.log_action(action: str, result: str): Logs a tool action and its result. Extremely long results are automatically truncated to 2000 characters.compress_history(new_summary: str): Used by the agent to update the summarized history and clear the recent action logs, freeing up context space.
🤖 Agent Workflow Example
The agent reads the user prompt and calls
set_core_objectiveandupdate_current_task.The agent executes a tool (e.g., reading a file, running a shell command) and calls
log_actionto store the result.The agent reads
working-context://stateto decide the next step.If
working-context://statereturns a warning that the recent actions limit is reached, the agent callscompress_historyto summarize the past actions, thereby keeping its own context window clean.
📄 License
This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Available Tools
4 toolscompress_historyA
履歴を要約し、Recent Actions をクリアします。
| Name | Required | Description | Default |
|---|---|---|---|
| new_summary | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
The description explicitly discloses two behavioral effects: summarizing history and clearing Recent Actions. With no annotations, it adequately conveys the destructive nature (clearing actions).
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single sentence that is direct and front-loaded. No extraneous words; every word contributes to understanding the tool's function.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
For a tool with one parameter and no nested objects, the description covers the core action but omits explanation of the parameter's role. Output schema exists but is not shown; however, the description could be more complete.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The only parameter, 'new_summary', is not explained in the description or the schema. The name hints at its purpose, but the description does not add any meaning, such as format or behavior (e.g., replacement vs. append).
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool's action: summarizing history and clearing Recent Actions. It is distinct from sibling tools (log_action, set_core_objective, update_current_task) which have different purposes.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance on when to use this tool versus alternatives, nor any prerequisites or conditions. The description does not mention any exclusions or when not to use it.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
log_actionC
直近の行動とその結果をログに記録します。
| Name | Required | Description | Default |
|---|---|---|---|
| action | Yes | ||
| result | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, so the description carries full burden. It only mentions 'logs' without disclosing side effects, whether the log is persistent, or if it overwrites. The behavior beyond logging is opaque.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single concise sentence that immediately conveys the purpose. It is front-loaded and efficient, though it sacrifices detail for brevity.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Despite the presence of an output schema, the description lacks context about log behavior, such as what qualifies as 'recent', whether the log is append-only, or how results are formatted. The tool's simplicity does not excuse the omission.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, but the description does not elaborate on the parameters 'action' and 'result'. It adds no meaning beyond the property names, failing to compensate for the lack of schema descriptions.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool logs recent actions and results. The verb 'log' and resource 'recent actions and results' are specific. However, it does not differentiate from sibling tools like compress_history or set_core_objective, but those have distinct names.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance is provided on when to use this tool or when to avoid it. No alternatives are mentioned, leaving the agent without context for decision-making.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
set_core_objectiveC
大目標(Core Objective)を設定します。
| Name | Required | Description | Default |
|---|---|---|---|
| objective | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are provided, and the description adds no behavioral traits beyond the basic action. There is no mention of side effects, authentication requirements, or any other relevant behavior.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is extremely concise (one sentence) but lacks essential information. It is undersized for a tool with no annotations and a single parameter.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Given the presence of an output schema and one parameter, the description is incomplete. It does not explain output, prerequisites, or any contextual information needed to use the tool effectively.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
Schema description coverage is 0%, and the description does not explain the 'objective' parameter's meaning, format, or constraints. The parameter remains ambiguous.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the action 'set' and the resource 'Core Objective', which matches the tool name. However, it does not distinguish from siblings, though the sibling names are distinct enough that the purpose is understandable.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No guidance on when to use this tool versus alternatives like 'compress_history' or 'log_action'. The description simply states the action without context or exclusions.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
update_current_taskC
現在の最優先タスク(Current Task)を更新します。
| Name | Required | Description | Default |
|---|---|---|---|
| task | Yes |
Output Schema
| Name | Required | Description |
|---|---|---|
| result | Yes |
TDQS
Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?
No annotations are present, so the description carries the full burden. It only says 'updates' without explaining side effects, whether changes are reversible, or what happens to the previous task.
Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.
Is the description appropriately sized, front-loaded, and free of redundancy?
The description is a single, succinct sentence with no extraneous information. It is efficiently front-loaded.
Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.
Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?
Despite an output schema existing, the description is too minimal to provide sufficient context for an agent. The concept of 'current task' is undefined, and the tool's relationship to sibling tools is not explained.
Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.
Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?
The single parameter 'task' has no schema description (0% coverage) and the tool description adds no meaning beyond the schema. The agent cannot infer whether this is a task ID, title, or other data.
Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.
Does the description clearly state what the tool does and how it differs from similar tools?
The description clearly states the tool updates the current top-priority task, with a specific verb and resource. It distinguishes from sibling tools like compress_history, log_action, set_core_objective.
Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.
Does the description explain when to use this tool, when not to, or what alternatives exist?
No usage guidance is provided. The description does not specify when to use this tool versus alternatives, nor does it mention prerequisites or when not to use.
Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections. Dates show when Glama detected each change.
4 tool updates
v0.1.0- First observed
compress_history - First observed
log_action - First observed
set_core_objective - First observed
update_current_task
TDQS
Each tool has a clearly distinct purpose: compress_history summarizes and clears recent actions, log_action records actions/results, set_core_objective sets a core goal, and update_current_task updates the priority task. No tool overlaps with another.
All tool names follow a consistent verb_noun pattern with underscores (compress_history, log_action, set_core_objective, update_current_task). No mixing of conventions or inconsistent verb styles.
With 4 tools, the server is well-scoped for managing working context. Each tool covers a distinct aspect (logging, compressing, setting objectives, updating tasks) without unnecessary clutter.
The tool set covers core lifecycle operations: setting objectives, updating tasks, logging actions, and compressing history. A minor gap exists for reading current context or viewing history, but the surface is largely complete for the stated purpose.
Maintenance
Resources
Unclaimed servers have limited discoverability.
Looking for Admin?
If you are the server author, to access and configure the admin panel.
Related MCP Connectors
Same functionality, consuming only 1/20 of the context window tokens.
Stop re-explaining yourself to Agents. Give it the right context, right when needed.
Knowledge accumulation for AI coding agents. Records decisions, problems, and insights as context.
Memory that reasons: continual learning for stateful agents. Better context, fewer tokens.
Related MCP Servers
- AlicenseAqualityFmaintenanceProvides AI chat history compression tools through token-based trimming and AI-powered summarization strategies to manage conversation context within token limits.2915MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI agents to maintain context across conversation sessions by saving and retrieving summaries of key points from past interactions.225MIT
- AlicenseAqualityCmaintenanceAuto-captures decision context from multi-agent workflows to preserve the 'why' behind every choice. Enables task traceability, reasoning retrieval, and continuous improvement across planning and implementation sessions.17236MIT
- AlicenseBqualityBmaintenanceEnables LLM agents to compress handoffs into structured, auditable context capsules, preserving goals, constraints, decisions, and risks without external API calls.320MIT
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/globalpocket/mcp-working-context-optimizer'
If you have feedback or need assistance with the MCP directory API, please join our Discord server