Agent Context Token Optimizer MCP Server

Agent Context Token Optimizer MCP Server

Provides owner-bound secure storage and retrieval of tool outputs via MCP tools, enabling trusted persistence for agents like Claude Code, Codex CLI, and OpenCode.

Category
访问服务器

README

Agent Context Token Optimizer v2

English | 中文

English

A local-first, dependency-free core for replacement-history compaction and an owner-bound secure tool-output vault, with honest adapters for multiple agent ecosystems.

Capability matrix

Target History Vault Mode / boundary
Hermes Agent policy helper / explicit host patch point automatic allowlisted transform hook + retrieval tool History: integration helper; Vault: Native plugin
OpenAI-compatible/custom Python message helper explicit middleware helper Native helper when the application controls messages/tool results
LangChain / LangGraph duck-typed conversion + state helper compose the core helper in a tool wrapper Native helper; this package does not patch framework internals
AutoGen message-list helper compose a tool wrapper Native helper only at application-owned hooks
CrewAI task-context handoff compose a tool wrapper Wrapper; no claim of private transcript mutation
Claude Code new/resumed-session JSON handoff explicit MCP tools Wrapper + MCP-only; cannot rewrite existing history or automatically intercept output
Codex CLI new/resumed-session JSON handoff explicit MCP tools Wrapper + MCP-only; cannot rewrite existing history or automatically intercept output
OpenCode new/resumed-session JSON handoff explicit MCP tools Wrapper + MCP-only; cannot rewrite existing history or automatically intercept output

MCP caveat: text passed explicitly to store_tool_result normally already entered the host/model context. MCP provides owner-bound retention and retrieval, not retroactive token savings or automatic interception.

Install and run

python3 -m pip install .
context-token-optimizer install-hermes-plugin
python3 -m token_optimizer.cli compact --agent claude-code < handoff.json
TOKEN_OPTIMIZER_OWNER='<host-generated-opaque-id>' \
  python3 -m token_optimizer.mcp_server --store ~/.context-token-optimizer/vault
python3 -m pytest -q

Never let the model choose the MCP process owner. Generate/bind it in host configuration. See Integration, Architecture, Verification, and Changelog.

Safety contract

Latest real user intent remains last; summaries are reference-only. Vault artifacts use hashed owner binding, strict IDs/types, sensitive-content rejection, SHA-256 integrity, 0700 directories, 0600 files, atomic writes, TTL checks on read and cleanup, and a total quota. These controls reduce risk but do not make retained untrusted content safe to execute.

中文

v2 提供本地优先、无第三方运行时依赖的替换历史压缩核心和绑定 owner 的安全工具输出仓库,并为多种 Agent 生态提供不夸大能力的适配器。

能力矩阵

目标 历史压缩 输出仓库 模式 / 边界
Hermes Agent 策略 helper / 显式宿主补丁点 白名单自动 transform hook + 取回工具 历史:集成 helperVault:Native 插件
OpenAI-compatible/custom Python 消息 helper 显式 middleware helper 应用控制消息和工具结果时为 Native helper
LangChain / LangGraph 鸭子类型转换 + state helper 在工具 wrapper 中组合 core Native helper;不修改框架内部
AutoGen 消息列表 helper 组合工具 wrapper 仅限应用可控 hook 的 Native helper
CrewAI task-context handoff 组合工具 wrapper Wrapper;不声称修改私有历史
Claude Code 新建/恢复会话 JSON 交接 显式 MCP 工具 Wrapper + MCP-only;不能原地改历史或自动截获输出
Codex CLI 新建/恢复会话 JSON 交接 显式 MCP 工具 Wrapper + MCP-only;不能原地改历史或自动截获输出
OpenCode 新建/恢复会话 JSON 交接 显式 MCP 工具 Wrapper + MCP-only;不能原地改历史或自动截获输出

**MCP 限制:**显式传给 store_tool_result 的正文通常已经进入宿主/模型上下文。MCP 只提供绑定 owner 的保存和取回,不代表自动拦截或追溯性节省 Token。

安装与命令同上。MCP owner 必须由宿主生成并通过进程参数/环境绑定,不能让模型传入。安全措施包括 owner 哈希绑定、严格类型与 ID、敏感内容拒绝、SHA-256、原子写、0700/0600 权限、读取时 TTL 和总配额;仓库内容仍应视为不可信数据。

License / 许可证

MIT; third-party projects retain their licenses and copyrights. / MIT;第三方项目保留其许可证与版权。

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选