Skip to main content
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 — no outputMode to choose, no risk of accidentally inlining large data.

Routing Rules (MCP Bridge)

How Output Routing Works

After every abp_call, the bridge’s DataFlowManager inspects the ABP response:

Nested Binary Data Detection

ABP responses commonly nest BinaryData objects under property names rather than returning them at the top level. For example, an export.pdf capability might return:
The 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 as BinaryData when it has content (string) and mimeType (string), and either:
  1. The MIME type is binary (not text/* or application/json), or
  2. The encoding field 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:
1

Detect encoding

Identifies the encoding (base64 or utf-8)
2

Decode content

Decodes the content to a Buffer
3

Determine extension

Maps the MIME type to the correct file extension
4

Save to disk

Saves to the output directory with a timestamped filename
5

Return reference

Returns the file path, MIME type, and size

Supported MIME-to-Extension Mappings

Example response for binary output:

Download URLs

If the ABP response contains a BinaryDataReference 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:
The agent can then read the file if it needs to inspect the content.

Configuration

The MCP Bridge supports these environment variables:

Best Practices

For App Developers

  1. Return data, not file paths: Let the client handle file I/O
  2. Use Base64 for binary: Encode PDFs, images as Base64
  3. Include metadata: Add mimeType, size fields
  4. Don’t save files yourself: Let the client manage storage
Do not return file paths from your app. Return the actual data and let the client handle storage.

For Client Developers

  1. Save all results to files: Don’t give the agent a choice about inline vs file
  2. Save to predictable locations: Use a dedicated output directory
  3. Return file paths, not file contents: Let the agent read files on demand
  4. 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 practice

MCP Bridge Architecture

DataFlowManager component details

Building ABP Apps

How to return data from capabilities