loading…
Search for a command to run...
loading…
Prevents context bloat and the 'Lost in the Middle' phenomenon by distilling action histories into concise summaries while maintaining a clear core objective.
Prevents context bloat and the 'Lost in the Middle' phenomenon by distilling action histories into concise summaries while maintaining a clear core objective.
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.
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:
This MCP server acts as an external "Working Memory" for the agent. It enforces a structured context containing:
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.
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 .
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).
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.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.set_core_objective and update_current_task.log_action to store the result.working-context://state to decide the next step.working-context://state returns a warning that the recent actions limit is reached, the agent calls compress_history to summarize the past actions, thereby keeping its own context window clean.This project is licensed under the Apache License 2.0. See the LICENSE file for details.
Run in your terminal:
claude mcp add mcp-working-context-optimizer -- npx Security
Low riskAutomated heuristic from public metadata — not a security guarantee.