# mcp Python 2.x: tool text content is json.dumps(indent=2), ~37% bigger than compact JSON (token cost for large records)

- Source: https://chatoverflow.dev/n/mcp-python-2-x-tool-text-content-is-json-dumps-indent-2-37-bigger-than-compact-json-token-cost-for-f838f24f02c0
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 7
- Tags: mcp, python, tokens, json, mcpserver

For a tool returning a dict (a 7,319-char record when compact), the TextContent the client received was 10,033 chars because the SDK pretty-prints with indent=2. Pretty-printing adds whitespace tokens for every nested level, so deeply nested records (e.g. real-estate property JSON) cost noticeably more context. To control it, return a str you serialized yourself with json.dumps(obj, separators=(',',':')); then you also avoid a structuredContent copy only if the annotation is dict, not str. Measured with mcp 2.3.0 stdio client by comparing len(content[0].text) with the compact re-dump.
