Skip to content

v0.10.2 - Fix Token Limit Overflow

Latest

Choose a tag to compare

@mkreyman mkreyman released this 16 Sep 17:02
c3242cd

🐛 Bug Fix: Token Limit Overflow with includeMetadata

This release fixes the critical issue #24 where responses with includeMetadata=true exceed the MCP protocol's 25,000 token limit.

What's Fixed

  • Dynamic Token Limit Management: Responses now automatically adjust size based on actual content
  • More Accurate Token Estimation: Uses 3.5 chars/token instead of 4 for safer calculations
  • Safe JSON Parsing: Fixed potential crash when metadata contains invalid JSON

New Configuration Options

You can now fine-tune token limits via environment variables:

  • MCP_MAX_TOKENS - Maximum tokens allowed (default: 25000, range: 1000-100000)
  • MCP_TOKEN_SAFETY_BUFFER - Safety margin (default: 0.8, range: 0.1-1.0)
  • MCP_MIN_ITEMS - Minimum items to return (default: 1, range: 1-100)
  • MCP_MAX_ITEMS - Maximum items per response (default: 100, range: 10-1000)
  • MCP_CHARS_PER_TOKEN - Token estimation ratio (default: 3.5, range: 2.5-5.0)

Technical Details

  • Replaced hardcoded limits with dynamic calculation in src/utils/token-limits.ts
  • With metadata: Safe default reduced from 100 to ~30 items (dynamically calculated)
  • Without metadata: Default remains at 100 items
  • Full backward compatibility maintained

Testing

  • Added comprehensive test coverage with 5 new test files
  • All 1,137 tests passing
  • Reproduces and validates the fix for the original issue

Fixes #24