
Agentfit
io.github.MukundaKatta由 GitHub 账号 MukundaKatta 发布v0.1.0更新于 Oct 24, 2026
Token-aware message truncation: fit a chat history into your model's context budget.
概览
本地 MCP 服务器,让助手估算 token 数量并把聊天记录裁剪到模型的上下文预算内。
- 可以做什么
- 估算字符串或聊天消息数组的 token 数,支持按模型划分的估算器系列(openai、anthropic、google、llama、default)
- 按 maxTokens 预算裁剪聊天记录,支持 drop-oldest、drop-middle 和 priority 策略,并遵循 preserveSystem、preserveFirstN、preserveLastN
- 列出内置的估算器系列
- 返回结构化结果,包含保留与丢弃的消息以及裁剪前后的 token 数;预算无法满足时返回 fit: false 而不是报错
- 适用场景
- 适合让助手检查一段提示或对话记录有多大,或在保留系统提示和最近几轮的前提下把长对话压缩到 token 上限。在把上下文发送给模型前做准备时很有用。
- 运行要求
- 以本地 stdio 进程运行,通常通过 npx 启动 npm 包 @mukundakatta/agentfit-mcp,因此需要 Node.js 和 npx。未声明认证、环境变量或请求头。仅支持桌面 MCP 客户端,无网页版。
安装
在 SourceWeft 中
- 打开 控制台中的 Agentfit,将其添加到工作区。
- 为需要使用其工具的对话启用该服务。
Desktop only,通过 STDIO。 STDIO 服务会启动本地进程,因此需要 SourceWeft 桌面宿主。
其他 MCP 客户端
参照 仓库 中的启动说明。
README
agentfit-mcp
MCP server for @mukundakatta/agentfit. Lets Claude Desktop, Cursor, Cline, Windsurf, Zed, or any other MCP client estimate token counts and fit a chat history into a model's context budget on demand.
Three tools:
count_tokens— estimate tokens in a string or chat-message array, with per-model estimator families (openai, anthropic, google, llama, default).fit_messages— drop messages from a chat history until under amaxTokensbudget. Supports drop-oldest, drop-middle, and priority strategies; honorspreserveSystem,preserveFirstN,preserveLastN.list_estimators— list the built-in estimator families.
Add to your client
Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
Cursor
~/.cursor/mcp.json:
Cline / Windsurf / Zed
Same shape as above. The server speaks plain MCP over stdio, so any client that supports stdio MCP servers will work.
Tool examples
count_tokens:
Returns:
fit_messages:
Returns:
fit_messages always returns a structured result and never throws across the wire: if the budget is unreachable even after dropping all non-protected messages, you get fit: false with the partial result so the caller can decide what to do.
Why a separate MCP server
@mukundakatta/agentfit is a zero-dependency JavaScript library. This package wraps it as an MCP server so it's accessible from inside any MCP-aware AI assistant: ask Claude "how many tokens is this transcript?" or "trim this chat to 8k tokens preserving the system prompt and last 2 turns" and the assistant calls these tools directly.
Sibling MCP servers
Part of the agent-stack series, all @mukundakatta/*-mcp:
@mukundakatta/agentfit-mcp— Fit it. (this)@mukundakatta/agentguard-mcp— Sandbox it.@mukundakatta/agentsnap-mcp— Test it.@mukundakatta/agentvet-mcp— Vet it.@mukundakatta/agentcast-mcp— Validate it.
License
MIT
来源:README.md,提交 6657bbb
工具
0版本历史
1- v0.1.0最新Sep 16, 2026
评分
已满足适用检查项的 50%
该评分衡量此收录条目的完整程度,依据注册中心条目、端点与公开来源计算得出。它不是对服务器本身的评价,也不表示服务器安全或当前可用:可连通性是带日期的检查结果,评分也不包含安装量或用户评价。
- 近 30 天内可连通25 分
请保持端点能够响应 MCP 握手;SourceWeft 每 30 天探测一次。
- 已声明认证方式10 分
请在注册中心条目中声明凭据请求头,或保持端点能够响应探测,以便判定其认证方式。
- 已列出工具15 分
请让服务器在无凭据时响应 tools/list,或发布可在沙箱中无凭据启动的软件包。
- 描述必需15 分
- 图标10 分
- 文档15 分
- 许可证10 分