tokenfold

Fit LLM context to token budgets with structural compression and relevance ranking.

Local

Install

See the repository for setup

What it does

Tokenfold is a Python-first SDK, with TypeScript and Rust bindings, that fits text, JSON, and grouped context into an explicit token ceiling. The base workflow is offline and model-free: it applies lossless structural compression to inputs such as tool schemas or API responses, returns a receipt, and exposes a checked accessor that raises when the exact budget is not met. An optional Select scorer, a separately provisioned model, can rank and drop whole context groups for relevance when structural compression alone is insufficient; selection requires per-fit consent and is described by the project as experimental.

The tool is aimed at developers and AI teams assembling LLM requests, including coding agents that fill context with shell output, diffs, build logs, and test results. Connections include:

  • pip install tokenfold for Python and npm install tokenfold for Node, with CLI installation through Cargo
  • A stdio MCP server started with tokenfold mcp serve, offering compress, inspect, retrieve, and stats tools; tokenfold init configures Claude Code, while Codex requires manual registration
  • A loopback proxy for OpenAI-compatible clients that forwards to a fixed upstream and compresses chat-shaped request bodies

Token counts use local tokenizer encoding and may differ from provider framing or billing. Folded representations require validated consumers, and saved benchmarks are fixtures rather than guarantees of savings or answer quality.

Compatibility and authentication

Connection
Local
Transports
Unspecified
Authentication
Unknown

Security and permissions

  • When you run the server locally, it runs with your user permissions.
  • Authentication type: Unknown.

Repository data

Stars
425
Last push
Nov 12, 2026
License
Apache-2.0
Archived
No

FAQ

What license does tokenfold use?
Apache-2.0
Does tokenfold run locally or remotely?
It runs locally.
Is tokenfold an official server?
It is listed as a community server.

Comments

No comments yet.

Embed a listing badge

Featured on AI Agents Marketplace
<a href="https://aiagentsmarketplace.dev/mcp/tokenfold"><img src="https://aiagentsmarketplace.dev/badges/featured.svg" alt="Featured on AI Agents Marketplace" width="262" height="36"></a>
See badge options