{
  "markdown": "# agentfit-mcp\n\n**MCP server for [`@mukundakatta/agentfit`](https://www.npmjs.com/package/@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.\n\n```bash\nnpx -y @mukundakatta/agentfit-mcp\n```\n\nThree tools:\n\n- **`count_tokens`** — estimate tokens in a string or chat-message array, with per-model estimator families (openai, anthropic, google, llama, default).\n- **`fit_messages`** — drop messages from a chat history until under a `maxTokens` budget. Supports drop-oldest, drop-middle, and priority strategies; honors `preserveSystem`, `preserveFirstN`, `preserveLastN`.\n- **`list_estimators`** — list the built-in estimator families.\n\n## Add to your client\n\n### Claude Desktop\n\nEdit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\\Claude\\claude_desktop_config.json` (Windows):\n\n```json\n{\n  \"mcpServers\": {\n    \"agentfit\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@mukundakatta/agentfit-mcp\"]\n    }\n  }\n}\n```\n\n### Cursor\n\n`~/.cursor/mcp.json`:\n\n```json\n{\n  \"mcpServers\": {\n    \"agentfit\": {\n      \"command\": \"npx\",\n      \"args\": [\"-y\", \"@mukundakatta/agentfit-mcp\"]\n    }\n  }\n}\n```\n\n### Cline / Windsurf / Zed\n\nSame shape as above. The server speaks plain MCP over stdio, so any client that supports stdio MCP servers will work.\n\n## Tool examples\n\n**`count_tokens`:**\n\n```json\n{ \"input\": \"hello world\", \"model\": \"claude-sonnet-4-6\" }\n```\n\nReturns:\n\n```json\n{ \"tokens\": 4, \"model\": \"claude-sonnet-4-6\" }\n```\n\n**`fit_messages`:**\n\n```json\n{\n  \"messages\": [\n    { \"role\": \"system\", \"content\": \"You are precise.\" },\n    { \"role\": \"user\", \"content\": \"long context...\" },\n    { \"role\": \"assistant\", \"content\": \"...\" },\n    { \"role\": \"user\", \"content\": \"final question\" }\n  ],\n  \"maxTokens\": 8000,\n  \"model\": \"claude-sonnet-4-6\",\n  \"preserveSystem\": true,\n  \"preserveLastN\": 2,\n  \"strategy\": \"drop-oldest\"\n}\n```\n\nReturns:\n\n```json\n{\n  \"messages\": [...],\n  \"dropped\": [...],\n  \"tokens\": { \"before\": 12000, \"after\": 7800, \"budget\": 8000 },\n  \"fit\": true\n}\n```\n\n`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.\n\n## Why a separate MCP server\n\n`@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.\n\n## Sibling MCP servers\n\nPart of the agent-stack series, all `@mukundakatta/*-mcp`:\n\n- [`@mukundakatta/agentfit-mcp`](https://www.npmjs.com/package/@mukundakatta/agentfit-mcp) — *Fit it.* (this)\n- [`@mukundakatta/agentguard-mcp`](https://www.npmjs.com/package/@mukundakatta/agentguard-mcp) — *Sandbox it.*\n- [`@mukundakatta/agentsnap-mcp`](https://www.npmjs.com/package/@mukundakatta/agentsnap-mcp) — *Test it.*\n- [`@mukundakatta/agentvet-mcp`](https://www.npmjs.com/package/@mukundakatta/agentvet-mcp) — *Vet it.*\n- [`@mukundakatta/agentcast-mcp`](https://www.npmjs.com/package/@mukundakatta/agentcast-mcp) — *Validate it.*\n\n## License\n\nMIT\n",
  "bytes": 3386,
  "sha": "ff661b5231be452febb880659f1817ddd77fb415d2bb7e39cbb552d17c75f1b0",
  "repo_slug": "mukundakatta/agentfit-mcp",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/mcp_io_github_mukundakatta_agentfit_f81ec3d9/readme"
}