fix: shared MCP truncate() crashes on None/non-string tool output (#1605)
This commit is contained in:
@@ -13,6 +13,10 @@ SEARCH_TIMEOUT = 30
|
||||
|
||||
def truncate(text: str, limit: int = MAX_OUTPUT_CHARS) -> str:
|
||||
"""Truncate text to *limit* characters with a suffix note."""
|
||||
if not isinstance(text, str):
|
||||
# Tool output is occasionally None or a non-string; len(None) would
|
||||
# raise. Coerce so this shared helper never crashes a tool response.
|
||||
text = "" if text is None else str(text)
|
||||
if len(text) > limit:
|
||||
return text[:limit] + f"\n... (truncated, {len(text)} chars total)"
|
||||
return text
|
||||
|
||||
Reference in New Issue
Block a user