Skip to content

Token-usage visibility and MCP tool-schema deferral - #438

Merged
mohitranka merged 1 commit into
mainfrom
feat/mcp-tool-token-optimizations
Aug 26, 2026
Merged

mohitranka merged 1 commit into
mainfrom
feat/mcp-tool-token-optimizations

Conversation

@mohitranka

Copy link
Copy Markdown
Contributor

Summary

  • Adds /context (and /ctx) — an on-demand TUI report breaking token usage down by category (system prompt, tool schemas, user/assistant/tool messages, thinking), reusing the existing /status overlay machinery. The footer stays unchanged.
  • Adds enabled_tools/disabled_tools to McpServerConfig — an opt-in per-server allowlist so a bloated MCP server can be trimmed to the tools actually used, filtered before registration so unused schemas never reach the model.
  • Adds automatic MCP tool-schema deferral, no configuration required: once a session's MCP tool schemas exceed 10% of the active model's usable context window (CompactionPolicy::tool_schema_budget), uncalled MCP tools drop off the model's tool list behind a new search_tools meta-tool. Any tool the model has already called stays fully declared (derived from the transcript's own tool_calls, not extra session state).

Test plan

  • cargo fmt --all clean
  • cargo clippy --workspace --all-targets clean
  • cargo test --workspace green (full suite, exit 0)
  • New unit/integration tests: forge-context (tool_schema_budget), forge-core (/context report, deferral trigger/promotion), forge-mcp (ToolFilter, search_tools matching + registration), forge-config (TOML round-trip for enabled_tools/disabled_tools)

https://claude.ai/code/session_01Tb5bxZgFovoKct29q9VEgs

Adds an on-demand /context command breaking down token usage by
category (system prompt, tool schemas, messages by role), an
enabled_tools/disabled_tools allowlist for MCP servers, and automatic
tool-search deferral: once MCP tool schemas exceed 10% of the active
model's usable context window, deferred tools drop off the wire behind
a search_tools meta-tool, restoring full visibility for any tool the
model has already called.

Claude-Session: https://claude.ai/code/session_01Tb5bxZgFovoKct29q9VEgs
@mohitranka
mohitranka merged commit c9e3ac8 into main Aug 26, 2026
7 checks passed
@mohitranka
mohitranka deleted the feat/mcp-tool-token-optimizations branch August 26, 2026 00:03
mohitranka added a commit that referenced this pull request Sep 11, 2026
Adds an on-demand /context command breaking down token usage by
category (system prompt, tool schemas, messages by role), an
enabled_tools/disabled_tools allowlist for MCP servers, and automatic
tool-search deferral: once MCP tool schemas exceed 10% of the active
model's usable context window, deferred tools drop off the wire behind
a search_tools meta-tool, restoring full visibility for any tool the
model has already called.

Claude-Session: https://claude.ai/code/session_01Tb5bxZgFovoKct29q9VEgs
mohitranka added a commit that referenced this pull request Sep 11, 2026
Adds an on-demand /context command breaking down token usage by
category (system prompt, tool schemas, messages by role), an
enabled_tools/disabled_tools allowlist for MCP servers, and automatic
tool-search deferral: once MCP tool schemas exceed 10% of the active
model's usable context window, deferred tools drop off the wire behind
a search_tools meta-tool, restoring full visibility for any tool the
model has already called.

Claude-Session: https://claude.ai/code/session_01Tb5bxZgFovoKct29q9VEgs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant