Skip to content

Commit dc4859c

Browse files
committed
Make read tool token limit configurable via env var
- Added HANZO_MCP_READ_MAX_TOKENS env var (default: 22000) - Added HANZO_MCP_READ_LINE_LIMIT env var (default: 2000) - Added HANZO_MCP_MAX_LINE_LENGTH env var (default: 2000) Users can now configure: export HANZO_MCP_READ_MAX_TOKENS=30000 # Increase limit export HANZO_MCP_READ_LINE_LIMIT=5000 # Read more lines export HANZO_MCP_MAX_LINE_LENGTH=4000 # Longer lines Default 22000 tokens leaves buffer for MCP overhead.
1 parent 67c0e38 commit dc4859c

File tree

1 file changed

+7
-5
lines changed
  • pkg/hanzo-mcp/hanzo_mcp/tools/filesystem

1 file changed

+7
-5
lines changed

pkg/hanzo-mcp/hanzo_mcp/tools/filesystem/read.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
from typing import Unpack, Annotated, TypedDict, final, override
77
from pathlib import Path
8+
import os
89

910
from pydantic import Field
1011
from mcp.server import FastMCP
@@ -58,9 +59,10 @@ class ReadToolParams(TypedDict):
5859
class ReadTool(FilesystemBaseTool):
5960
"""Tool for reading file contents."""
6061

61-
# Default values for truncation
62-
DEFAULT_LINE_LIMIT = 2000
63-
MAX_LINE_LENGTH = 2000
62+
# Default values for truncation (configurable via env vars)
63+
DEFAULT_LINE_LIMIT = int(os.getenv("HANZO_MCP_READ_LINE_LIMIT", "2000"))
64+
MAX_LINE_LENGTH = int(os.getenv("HANZO_MCP_MAX_LINE_LENGTH", "2000"))
65+
MAX_TOKENS = int(os.getenv("HANZO_MCP_READ_MAX_TOKENS", "22000"))
6466
LINE_TRUNCATION_INDICATOR = "... [line truncated]"
6567

6668
@property
@@ -212,10 +214,10 @@ async def call(
212214
await tool_ctx.info(f"Successfully read file: {file_path}")
213215

214216
# Apply token limit to prevent excessive output
215-
# Reduce to 20000 to leave buffer for MCP overhead
217+
# Default 22000 tokens (configurable via HANZO_MCP_READ_MAX_TOKENS)
216218
return truncate_response(
217219
result,
218-
max_tokens=20000,
220+
max_tokens=self.MAX_TOKENS,
219221
truncation_message="\n\n[File content truncated due to token limit. Use offset/limit parameters to read specific sections.]",
220222
)
221223

0 commit comments

Comments
 (0)