mcpField
A
agentfit

agentfit

Local
github.comAI & Agents1Updated 20w ago

About agentfit

agentfit is an MCP server for estimating token counts and trimming chat histories to a model’s context budget. It is intended for MCP clients that need token-aware conversation fitting while preserving selected messages.

Key features

  1. 01Estimate tokens for text or messages
  2. 02Support several model estimator families
  3. 03Trim history to a token budget
  4. 04Choose drop and message-preservation strategies
  5. 05List built-in estimators

Use cases

  1. 01Check a transcript’s estimated token count
  2. 02Fit a conversation within a model limit
  3. 03Retain system prompts and selected turns

MCP support

Exposes token estimation, message fitting, and estimator-listing tools to MCP clients over stdio.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

mcp.json · Universal config
{
"mcpServers": {
"mukundakatta-agentfit": {
"command": "npx",
"args": [
"-y",
"@mukundakatta/agentfit-mcp"
]
}
}
}
Run commandnpx -y @mukundakatta/agentfit-mcp

Local servers need a runtime on your machine (e.g. Node.js 18+). Config file locations differ by client; see your client’s docs.

Packages
npm@mukundakatta/agentfit-mcp0.1.0

Tools

3

Saved tool list · updated 3w ago

ParameterTypeRequiredDescription
inputanyYesString or array of chat messages.
modelstringNoOptional model name (e.g. "gpt-5", "claude-sonnet-4-6"). Picks the closest estimator family.
overheadnumberNoPer-message overhead in tokens (default depends on model family, usually 4-6).

Details

From the project 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.

npx -y @mukundakatta/agentfit-mcp

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 a maxTokens budget. Supports drop-oldest, drop-middle, and priority strategies; honors preserveSystem, 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):

{
  "mcpServers": {
    "agentfit": {
      "command": "npx",
      "args": ["-y", "@mukundakatta/agentfit-mcp"]
    }
  }
}
Cursor

~/.cursor/mcp.json:

{
  "mcpServers": {
    "agentfit": {
      "command": "npx",
      "args": ["-y", "@mukundakatta/agentfit-mcp"]
    }
  }
}
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:

{ "input": "hello world", "model": "claude-sonnet-4-6" }

Returns:

{ "tokens": 4, "model": "claude-sonnet-4-6" }

fit_messages:

{
  "messages": [
    { "role": "system", "content": "You are precise." },
    { "role": "user", "content": "long context..." },
    { "role": "assistant", "content": "..." },
    { "role": "user", "content": "final question" }
  ],
  "maxTokens": 8000,
  "model": "claude-sonnet-4-6",
  "preserveSystem": true,
  "preserveLastN": 2,
  "strategy": "drop-oldest"
}

Returns:

{
  "messages": [...],
  "dropped": [...],
  "tokens": { "before": 12000, "after": 7800, "budget": 8000 },
  "fit": true
}

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:

License

MIT

Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.