Fix single-element list unwrapping in tool content

Single-element lists like [1] were being incorrectly unwrapped to "1"
in unstructured content while multi-element lists remained as lists.
This created inconsistent behavior where the structure was lost for
single items.

This fix ensures lists always preserve their structure in unstructured
content regardless of length, making behavior consistent and predictable.

Also removes pretty-printing from JSON serialization for more compact
output across tools, prompts, and resources.

Fixes #1064

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jeremiah Lowin 2025-07-07 12:07:16 -04:00
commit 0600834da4
11 changed files with 51 additions and 33 deletions

View file

@ -25,7 +25,7 @@ async def test_complex_inputs():
"name_shrimp", {"tank": tank, "extra_names": ["charlie"]}
)
assert len(result.content) == 1
assert result.content[0].text == '[\n "bob",\n "alice",\n "charlie"\n]' # type: ignore[attr-defined]
assert result.content[0].text == '["bob","alice","charlie"]' # type: ignore[attr-defined]
async def test_desktop(monkeypatch):