You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: blog/toon-format-support.md
+3-62Lines changed: 3 additions & 62 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -51,37 +51,11 @@ Adding TOON support seemed simple: set an `Accept: text/toon` header when callin
51
51
52
52
**The MCP SDK overwrites the Accept header.**
53
53
54
-
The `mcp` Python library's `_prepare_headers()` method sets:
55
-
```python
56
-
"Accept": "application/json, text/event-stream"
57
-
```
58
-
59
-
This happens after user headers are merged, meaning our `Accept: text/toon` gets overwritten before the request is sent. No amount of header configuration could fix this.
54
+
The `mcp` Python library's `_prepare_headers()` method forces `Accept: application/json, text/event-stream`, and this happens after user headers are merged. No amount of header configuration could fix this.
60
55
61
56
## The Solution: Custom Header
62
57
63
-
Instead of fighting the SDK, we introduced a custom header that the SDK doesn't touch:
64
-
65
-
```
66
-
X-Prefer-Format: toon
67
-
```
68
-
69
-
Armory checks this header first, falling back to the standard `Accept` header for non-MCP clients:
# Fallback to Accept header (for direct HTTP clients)
79
-
accept = request.headers.get("accept", "")
80
-
if"text/toon"in accept:
81
-
return OutputFormat.TOON
82
-
83
-
return OutputFormat.JSON
84
-
```
58
+
Instead of fighting the SDK, we introduced a custom header that the SDK doesn't touch: `X-Prefer-Format: toon`. Armory checks this header first, falling back to the standard `Accept` header for non-MCP clients.
85
59
86
60
## The Full Flow
87
61
@@ -100,47 +74,14 @@ The key insight: **conversion happens in Armory, not in backends**. MCP servers
100
74
101
75
## Smart Conversion
102
76
103
-
TOON isn't always smaller than JSON. For deeply nested objects or non-uniform arrays, JSON might actually be more compact. Armory's conversion logic handles this:
return data # Return as object for JSON serialization
116
-
```
117
-
118
-
This ensures TOON is only used when it provides actual benefit.
77
+
TOON isn't always smaller than JSON. For deeply nested objects or non-uniform arrays, JSON might actually be more compact. Armory compares both formats and only uses TOON when it provides actual benefit.
119
78
120
79
## UI Display
121
80
122
81
Tool results now display differently based on format. JSON results get pretty-printed with indentation. TOON results display as plain text with proper line breaks.
With TOON enabled, we see 30-60% token reduction on tool results with tabular data (weather forecasts, search results, database queries). The format is especially effective for:
0 commit comments