This document covers client-side data routing (MCP Bridge behavior). For protocol-level binary data specification (how apps should format binary responses across all transports), see Binary Data Protocol.
The Problem
If all capability outputs flow through the agent’s context window:- Large PDFs, images, and HTML consume excessive tokens
- Agent performance degrades
- Context limits are hit quickly
- Non-deterministic orchestration
The Solution: Always Save to File
All capability results are saved to a file. The agent receives a file path and metadata summary, and decides whether to read the file. This removes the routing decision from the agent entirely — nooutputMode to choose, no risk of accidentally inlining large data.
Routing Rules (MCP Bridge)
| Data Type | Routing |
|---|---|
| Binary (PDF, images) | Save to file (Base64 to binary) |
| Text / JSON | Save to file as JSON |
| Error responses | Return inline (small diagnostic info) |
How Output Routing Works
After everyabp_call, the bridge’s DataFlowManager inspects the ABP response:
Nested Binary Data Detection
ABP responses commonly nestBinaryData objects under property names rather than returning them at the top level. For example, an export.pdf capability might return:
DataFlowManager scans one level deep into response.data to find BinaryData and BinaryDataReference objects. When binary data is found nested (e.g., under document), sibling properties (e.g., pageCount) are collected and returned as metadata alongside the file path:
Binary Data Handling
App Returns Binary Data
Client Detects Binary Data
A response is detected asBinaryData when it has content (string) and mimeType (string), and either:
- The MIME type is binary (not
text/*orapplication/json), or - The
encodingfield is set to"base64"
The second condition is critical: a
text/html document with encoding: "base64" is file data that the agent cannot reason about, so it is always saved to a file regardless of MIME type.Client Saves to File
Binary Processing Sequence
When binary data is detected, the bridge:Supported MIME-to-Extension Mappings
| MIME Type | Extension |
|---|---|
application/pdf | .pdf |
image/png | .png |
image/jpeg | .jpg |
image/gif | .gif |
image/webp | .webp |
image/svg+xml | .svg |
audio/mpeg | .mp3 |
audio/wav | .wav |
audio/ogg | .ogg |
video/mp4 | .mp4 |
video/webm | .webm |
application/zip | .zip |
application/json | .json |
text/html | .html |
text/plain | .txt |
text/csv | .csv |
text/markdown | .md |
| Other | .bin |
Download URLs
If the ABP response contains aBinaryDataReference object (has downloadUrl and mimeType), the bridge downloads the file, saves it to disk, and returns the path. If the download fails, it returns the URL and the error.
Text/JSON Output Handling
All non-binary successful results are serialized as JSON and saved to a file. The agent receives the file path and size:Configuration
The MCP Bridge supports these environment variables:| Variable | Default | Description |
|---|---|---|
ABP_OUTPUT_DIR | <os.tmpdir()>/abp-mcp-bridge | Directory where output files (PDFs, images, JSON results) are saved. Created automatically if it doesn’t exist. |
Best Practices
For App Developers
- Return data, not file paths: Let the client handle file I/O
- Use Base64 for binary: Encode PDFs, images as Base64
- Include metadata: Add
mimeType,sizefields - Don’t save files yourself: Let the client manage storage
For Client Developers
- Save all results to files: Don’t give the agent a choice about inline vs file
- Save to predictable locations: Use a dedicated output directory
- Return file paths, not file contents: Let the agent read files on demand
- Clean up old files: Remove temporary files after use
See Also
Binary Data Protocol
Protocol-level binary data specification for app developers
MCP Bridge Quick Start
Using
abp_call in practiceMCP Bridge Architecture
DataFlowManager component details
Building ABP Apps
How to return data from capabilities