Introducing The Sweep: OX’s New Live Security Research Series
Register Now
Breaking: The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Read the Report
Are you exposed? Connect your apps in minutes.
Scan your apps free

toolcap

Latest version: v0.3.0

Overview

Last scanned
25 Nov 2026
Published
25 Nov 2026
PyPI package Publisher: sri.lingamaneni
0 Stars
0 Forks
3 Versions
270 Downloads
Python Repo language

Scan summary

toolcap was last scanned on 25 Nov 2026 at version 0.3.0. Risk score 0 of 100. No malicious behavior was detected.

  • Releases: 3 versions; the latest was published on 25 Nov 2026.
  • Findings: No rules fired in version 0.3.0.
  • Downloads: 270 downloads.

Versions

3 versions published
Versions and the rules that fired in each
VersionPublishedStatus
0.3.0 LATEST 25 Nov 2026 No rules fired
0.2.0 13 Nov 2026 No rules fired
0.1.0 11 Nov 2026 No rules fired

No rules fired in 0.3.0

Findings

Findings for v0.3.0. The score is a capped sum of the weights of the rules that fired — not CVSS, not exploitability, and not a probability. It is not comparable across packages with different scan coverage.

The score describes 0.3.0; other versions have their own rules, not their own score.

README

The publisher’s own README, as collected from the registry.

toolcap

Keep MCP tool results under the client's token limit, with pages the model can follow. Use it in your own server (one decorator), or as a proxy in front of any MCP server you didn't write.

A tool that returns 200 flow runs, a long log or a big page snapshot can blow past the client's limit (Claude Code rejects results over 25,000 tokens) or fill the context in one call. toolcap cuts any result into pages of whole items that fit a token budget, each with a next_cursor and a note telling the model how to get the next page, in one call or one decorator.

pip install toolcap

Python 3.9+, no dependencies. Works with any MCP framework (the official MCP Python SDK 1.x FastMCP and 2.x MCPServer, the standalone fastmcp) or none, because it only turns a value into text.

Fix a server you didn't write

MCP tool "..." response (61,234 tokens) exceeds maximum allowed tokens (25000) in Claude Code, or a client that silently fills its context with one giant snapshot? Wrap the server in toolcap proxy in your MCP config. It works with servers in any language:

{
  "mcpServers": {
    "filesystem": {
      "command": "uvx",
      "args": ["toolcap", "proxy", "--",
               "npx", "-y", "@modelcontextprotocol/server-filesystem", "/home/me/code"]
    }
  }
}

Or from the command line: claude mcp add filesystem -- uvx toolcap proxy -- npx -y @modelcontextprotocol/server-filesystem ~/code.

Everything after -- is the command you had before. The proxy adds an optional cursor parameter to every tool. A result that fits is passed through unchanged; one that doesn't is cut into pages exactly as described below. The proxy keeps the last 16 full results in memory, so the model's next pages are served from there without running the tool again. Tested on the reference filesystem server's directory_tree of /usr/share: a 1.1 million-token result became pages under 20,000 tokens.

Option
--max-tokens N budget for one result (default TOOLCAP_MAX_TOKENS, else 20,000)
--trim cut long results with a note instead of paging them; adds no parameter
--tool NAME=N budget for one tool, overriding --max-tokens; repeat for more tools
--tool NAME=off leave one tool exactly as the server sends it (no cursor, nothing cut)
--cursor-param NAME name of the added parameter (default cursor)
--quiet don't log cut results to stderr

Per-tool settings help when one tool needs different treatment: --tool browser_snapshot=8000 keeps page snapshots small so they don't crowd out the rest of the context, and --tool read_media_file=off passes a tool through when its client has its own handling, or when its result must arrive whole. Later pages of a tool use that tool's budget.

Tools that already have a cursor parameter are left alone and their results are trimmed instead. outputSchema is removed from the tool list, because a page can't match it. Images and other non-text content stay on the first page. No uv? pip install toolcap and use "command": "toolcap".

In your own server

from mcp.server.fastmcp import FastMCP     # SDK 2.x: from mcp.server.mcpserver import MCPServer
from toolcap import Cap

mcp = FastMCP("prefect")
cap = Cap(max_tokens=20_000)

@mcp.tool()
@cap.paginate                      # adds a `cursor: str = ""` parameter for the model
def get_flow_runs(state: str = "COMPLETED", limit: int = 200) -> list:
    """List flow runs."""
    return api.flow_runs(state=state, limit=limit)    # any JSON-able value

If the 200 runs fit in 20,000 tokens the model gets them unchanged. If not, it gets as many whole runs as fit, plus a page object:

{"items": [{"id": "...", "name": "..."}, ...],
 "page": {"items": "1-37 of 200", "total": 200, "next_cursor": "MTozNzo1YzBmYTE5Mw",
          "note": "Showing items 1-37 of 200. Call this tool again with the same arguments and cursor=\"MTozNzo1YzBmYTE5Mw\" for the next page."}}

The model calls get_flow_runs(state="COMPLETED", limit=200, cursor="MTozNzo1YzBmYTE5Mw") and gets items 38 onward. The decorator also adds one sentence about next_cursor to the tool's description. It works on sync and async tools, keeps Context parameters hidden from the model as before, and resolves string annotations (from __future__ import annotations).

Without the decorator, call it yourself. This is the way to go when you want the cursor in your own signature, or to page only some of the result:

@mcp.tool(structured_output=False)
def read_log(run_id: str, cursor: str = "") -> str:
    """Read a flow run's log."""
    return cap.page(api.log_text(run_id), cursor)

What it does with each kind of result

Result What the model gets when it is too big
A list A page of whole items, wrapped as {"items": [...], "page": {...}}
A dict with a list inside ({"count": 500, "results": [...]}) The same dict with the largest list paged, the other fields kept, and a page key next to it (_page if the dict already has a page). Pick the list with key="data.items"
Text A chunk cut at a line break (or a space), then [Output cut: showing characters 1-5850 of 65000. Call this tool again ... cursor="..."]
One item bigger than the whole budget That item with its long strings (then long lists) cut, marked ... [N more characters cut], and paging moves on to the next item
Anything else (a dict without lists, a huge string field) Every key kept, long strings and lists cut until it fits

cap.trim(data) does the same without cursors, for tools where paging makes no sense: the model gets the first part and a note saying how many items were left out and to narrow the request. Pydantic models, dataclasses, tuples and sets are converted to JSON first.

Settings

Cap(
    max_tokens=None,        # default: the TOOLCAP_MAX_TOKENS env var, else 20,000
    count=None,             # text -> token count; default is a high estimate (UTF-8 bytes / 3)
    indent=None,            # JSON indent; None (compact) uses the fewest tokens
    cursor_param="cursor",  # name of the parameter the decorator adds
)

For an exact fit, pass a real tokenizer: Cap(count=lambda s: len(enc.encode(s))). The default estimate counts one token per 3 bytes of UTF-8, which is above what real tokenizers give for English, JSON, code and CJK text, so pages come out a little smaller than they could be but never over the limit. Users of your server can change the budget with TOOLCAP_MAX_TOKENS without code changes (match it to MAX_MCP_OUTPUT_TOKENS if they raised that in Claude Code).

Module-level shortcuts with default settings: toolcap.page(data, cursor), toolcap.trim(data) and @toolcap.paginate.

How paging works, and its limits

  • Cursors are stateless: an offset plus a short fingerprint of the full result. The server runs the tool again on every page and slices it, so nothing is stored between calls and it works across processes and restarts. The cost is that each page re-runs the query; for an expensive backend, cache the result yourself or pass the cursor's offset on to the backend.
  • If the result changed between pages (new rows came in), the page's note says so and that items may be repeated or missed. Give results a stable sort order.
  • A cursor that toolcap did not issue is rejected with an error the model can act on ("call the tool without a cursor to start from the beginning"). It is the SDK's own ToolError, so the text reaches the model on SDK 2.x too.
  • The decorated tool returns text and declares no output schema, so the SDKs don't also copy the page into structuredContent (which would double its size, and some clients skip their truncation for structured content). Use structured_output=False on hand-written -> str tools for the same reason.
  • The budget covers one result. It does not know how full the model's context already is.
  • Lists are paged at one level (the largest list reached through dict keys). Lists inside list items are cut, not paged.

Why this exists

MCP servers keep running into the client's result-size limit, and each one fixes it by hand with ad-hoc limit parameters or a second "minimal" tool:

License

MIT

OX Radar and Response Center

Find threats in your stack.

OX Radar can check high-priority threats, like critical package CVEs, against your context.

Each incident is marked Detected or Not Detected with a remediation plan and proof all tracked in the Response Center.

Where it’s listed

The probe returned only these fields for this server — auth requirement, protocol and tool list weren’t observed, so they’re not shown (never guessed).

  • pypi-releases toolcap

References

The publisher’s own links, as the registry reports them. These are not sources for the assessment on this page.

Scan your whole stack

Group 1261154050 1
Group 1261154050
 

From OX Research Newsroom

Copy of Template Design OX Blog (2)
Research

NGINX2Root: Five Critical NGINX Flaws Expose Web Servers to Remote Code Execution

Vulnerability Insights

OpenSSH Password Authentication Bypass on Alpine Linux (*sshole) – CVE-2026-123158

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?
Vulnerability Insights

The 2026 Vulnpocalypse Hits PHP: Four Critical RCEs, but How Dangerous Are They?

Frame 2085668439 (1)
Group 1261154229