HTML to Markdown
MCP Payload Optimization Policy
Policy Name |
MCP Payload Optimization Policy |
Summary |
Reduces tool response token consumption using one or more configurable methods: remove structural noise, trim oversized responses to match agent intent, or compress repeated structures into TOON |
Category |
MCP |
First Omni Gateway version available |
v1.12.0 |
Release Notes |
|
Returned Status Codes |
No return codes exist for this policy. |
| This policy supports Model Context Protocol (MCP) version 2025-06-18 and earlier. To learn more about MCP, see MCP Specification. |
Summary
The MCP Payload Optimization policy reduces LLM token consumption by transforming MCP tools/call responses before they’re returned to the client. The policy operates in three configurable stages:
-
Clean Payloads - Removes structural noise and unnecessary data:
-
Convert HTML to Markdown
-
Remove base64-encoded data
-
Remove JSON fields with null values
-
Remove excessive whitespace
-
-
Smart Response Trimming - Uses an LLM proxy to reduce large responses to match the agent’s intent, extracting only the information the agent requires.
-
Compress Repeated Structures - Encodes uniform JSON structures into Token-Oriented Object Notation (TOON), a lossless format that reduces tokens.
The policy processes responses when:
-
The upstream response has a
Content-Typeofapplication/jsonortext/event-stream(SSE). -
The body is a JSON-RPC MCP
tools/callresult (including streamed SSE events that carry those results).
Configure the minimum response size to skip transformation for small payloads. Each stage has independent size thresholds.
The policy uses the pre_transform_tokens and response_tokens for tool metrics to estimate token reduction.
Configuring Policy Parameters
Managed Omni Gateway and Omni Gateway Connected Mode
When you apply the policy from the UI, the following parameters are displayed:
| Element | Description | Default |
|---|---|---|
Converts HTML content in tool results to Markdown. |
Enabled |
|
Strip Base64 |
Detects and removes base64-encoded data from tool results. |
Enabled |
Remove Nulls |
Removes JSON fields whose value is null. |
Disabled |
Collapse Whitespace |
Removes excess whitespace in text content. |
Enabled |
Min Response Size (bytes) |
Minimum response size in bytes to transform. Smaller responses pass through unchanged for the four Token Sanitization transforms ( |
|
Enable Compress Repeated Structures |
Translates JSON-shaped |
Disabled |
TOON Min Response Size (bytes) |
Minimum response size in bytes for TOON encoding. Responses smaller than this skip TOON encoding. Minimum value is |
|
Enable Smart Response Trimming |
When enabled, an LLM proxy distills large tool responses down to match the caller’s declared intent (the |
Disabled |
LLM Proxy URL |
The endpoint of the LLM proxy service used for Smart Response Trimming (for example, |
N/A |
LLM Proxy ID |
Identifier of the selected LLM Proxy asset, stored for reference. This value is parsed and retained but not used at runtime by the policy. |
N/A |
Model-Based Routing |
Determines how the LLM proxy selects the target model. When disabled (default), the proxy owns model selection (Semantic Routing). When enabled, the caller selects the model via the |
Disabled |
LLM Model |
Model name sent in the |
N/A |
Client ID |
Client ID for LLM proxy authentication. Sent as a |
N/A |
Client Secret |
Client secret for LLM proxy authentication. Sent as a |
N/A |
Threshold Bytes |
Smart Response Trimming runs only when the post-sanitize content length exceeds this threshold (in bytes). Payloads below this threshold pass through with sanitize-only results. |
|
LLM Timeout (ms) |
Timeout in milliseconds for each LLM proxy request. If the proxy exceeds this timeout, the call fails and only completes the Clean Payloads step. |
|
Per-Tool Overrides |
Overrides the policy configuration values for specific tool names. Tools without an override use the global policy configuration. To learn more, see Per-tool overrides. |
N/A |
Per-tool overrides
Use Per-Tool Overrides to override the response optimization of specific tools. For example, if whitespace is necessary for a specific tool response but not for others, override Collapse Whitespace for that tool.
You can override the global policy configuration for the HTML to Markdown, Strip Base64, Remove Nulls, and Collapse Whitespace parameters. You cannot override Min Response Size, TOON Min Response Size, Enable Compress Repeated Structures, or Smart Response Trimming on a per-tool basis. Both TOON encoding and Smart Response Trimming are global settings that apply to all eligible tool responses.
If you omit a parameter in an override configuration, the tool uses the corresponding value from the global policy configuration.
Transformation Order
The policy applies optimizations in three stages:
Stage 1: Clean Payloads
String transforms are applied to each eligible string value in this order:
-
HTML to Markdown — Converts HTML documents or fragments to Markdown.
-
Strip Base64 — Replaces detected base64 blobs with a short
<stripped: N bytes>placeholder. -
Collapse Whitespace — Normalizes runs of whitespace.
Then the structural transform is applied:
-
Remove Nulls — Removes JSON fields with null values (applied once after string transforms).
Smart Response Trimming
Smart Response Trimming uses an LLM proxy to distill large tool responses to match the agent’s declared intent. When enabled, the policy:
-
Applies the Token Sanitization transforms (HTML to Markdown, Strip Base64, Collapse Whitespace, Remove Nulls).
-
Checks if the sanitized content exceeds the Threshold Bytes parameter (default: 8000 bytes) and includes
expected_info -
Sends the sanitized content to the configured LLM proxy.
-
Replaces the original content with the LLM extracted response if it’s smaller than the sanitized version.
Smart Response Trimming:
-
Requires an LLM proxy endpoint configured via LLM Proxy URL.
-
Requires
expected_infoto be present and non-empty in the request. The extractor only runs when the caller declares their intent. -
Is fail-open. If there is any LLM failure (timeout, transport error, non-2xx status), the policy falls back to the result from Clean payloads.
-
Processes
content[0]only when it istype: "text". Other content entries are left untouched. -
Uses client credentials (Client ID and Client Secret) for LLM proxy authentication, sent as separate
client_idandclient_secretrequest headers (not HTTP Basic Auth). -
Includes an output guard that rejects extractions larger than the sanitized input.
-
Makes exactly one LLM call per response.
-
Works with both JSON (
application/json) and Server-Sent Event (text/event-stream) responses. When enabled, SSE responses are buffered to allow complete content extraction.
Compress Repeated Structures
TOON is a compact, lossless, JSON-equivalent text format that reduces LLM token consumption for structured data. When Enable Compress Repeated Structures is enabled, the policy translates eligible JSON-shaped content items into TOON format.
TOON encoding:
-
Runs after all other transforms.
-
Applies to only the shapes that TOON can shrink, for example, uniform-scalar arrays of objects.
-
Preserves or reduces payload size (never inflates).
-
Is a global setting with no per-tool overrides.
-
Uses the TOON Min Response Size (bytes) threshold, independent of the Min Response Size (bytes) threshold used for other transforms.
A payload can be large enough for TOON encoding but too small for Token Sanitization transforms, or vice versa, because they use independent thresholds.



