Skip to main content
Glama
globalpocket

mcp-working-context-optimizer

by globalpocket

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:

  1. Context Bloat & OOM: Exceeding the token limit or causing Out-Of-Memory errors on local LLM servers due to massive KV cache expansion.

  2. 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

  1. The agent reads the user prompt and calls set_core_objective and update_current_task.

  2. The agent executes a tool (e.g., reading a file, running a shell command) and calls log_action to store the result.

  3. The agent reads working-context://state to decide the next step.

  4. If 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.

📄 License

This project is licensed under the Apache License 2.0. See the LICENSE file for details.

Available Tools

4 tools
compress_historyA

履歴を要約し、Recent Actions をクリアします。

ParametersJSON Schema
NameRequiredDescriptionDefault
new_summaryYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.6/5.0
Behavior4/5

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.

Conciseness5/5

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.

Completeness3/5

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.

Parameters2/5

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.

Purpose5/5

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.

Usage Guidelines2/5

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

直近の行動とその結果をログに記録します。

ParametersJSON Schema
NameRequiredDescriptionDefault
actionYes
resultYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.7/5.0
Behavior2/5

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.

Conciseness4/5

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.

Completeness2/5

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.

Parameters2/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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)を設定します。

ParametersJSON Schema
NameRequiredDescriptionDefault
objectiveYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.2/5.0
Behavior1/5

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.

Conciseness2/5

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.

Completeness2/5

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.

Parameters1/5

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.

Purpose4/5

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.

Usage Guidelines2/5

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)を更新します。

ParametersJSON Schema
NameRequiredDescriptionDefault
taskYes

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

C2.8/5.0
Behavior2/5

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.

Conciseness4/5

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.

Completeness2/5

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.

Parameters1/5

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.

Purpose5/5

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.

Usage Guidelines2/5

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.

  1. 4 tool updatesv0.1.0
    • First observedcompress_history
    • First observedlog_action
    • First observedset_core_objective
    • First observedupdate_current_task

TDQS

B3.3/5.0
Disambiguation5/5

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.

Naming Consistency5/5

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.

Tool Count5/5

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.

Completeness4/5

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

ActivityInactive
ResponsivenessSyncing

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

Related MCP Servers

Latest Blog Posts

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