---
schema_version: "1"
id: 024eeb9cee28ef75b16774b7b950cb05658f9593c9a3b96aa2d25dd4aa17ae46
title: MCP Payload Optimization Policy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/1.12/policies-included-mcp-payload-optimization.md
canonical_url: https://docs.mulesoft.com/gateway/1.12/policies-included-mcp-payload-optimization
source_site: docs.mulesoft.com
content_type: documentation
content_hash: e54d8adc7f09fa86baca53a17d7e85538ba7606b218dddb35ae1e2302b918bee
description: MuleSoft Documentation Site
release: "1.12"
latest: false
---
---
product: Omni Gateway
version: 1.12
keywords: api gateway, flex gateway, gateway, policy
---

# MCP Payload Optimization Policy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

<table><colgroup><col> <col></colgroup><tbody><tr><td><p><strong>Policy Name</strong></p></td><td><p>MCP Payload Optimization Policy</p></td></tr><tr><td><p><strong>Summary</strong></p></td><td><p>Optimizes MCP tool responses for token consumption by transforming HTML to Markdown and removing unnecessary data</p></td></tr><tr><td><p><strong>Category</strong></p></td><td><p>MCP</p></td></tr><tr><td><p><strong>First Flex Gateway version available</strong></p></td><td><p>v1.12.0</p></td></tr><tr><td><p><strong>Returned Status Codes</strong></p></td><td><p>No return codes exist for this policy. The policy modifies response bodies and doesn’t block traffic based on content.</p></td></tr></tbody></table>

## Summary

The MCP Payload Optimization policy reduces LLM token consumption by transforming MCP `tools/call`
responses before they’re returned to the client.

Configure the transformations to:

- Convert HTML to Markdown.

- Remove base64-encoded data.

- Remove JSON fields with null values.

- Remove excessive whitespace.

The policy processes responses when:

- The upstream response has `Content-Type` `application/json` or `text/event-stream` (SSE).

- The body is a JSON-RPC MCP `tools/call` result (including streamed SSE events that carry those
  results).

Configure the minimum response size to skip transformation for small payloads.

The policy uses the `pre_transform_tokens` and `response_tokens` for tool metrics to estimate token
reduction.

## Configuring Policy Parameters

### Flex Gateway Local Mode

The MCP Payload Optimization policy isn’t supported in Local Mode.

### Managed Flex Gateway and Flex Gateway Connected Mode

When you apply the policy from the UI, the following parameters are displayed:

<table><colgroup><col> <col> <col></colgroup><thead><tr><th>Element</th><th>Description</th><th>Default</th></tr></thead><tbody><tr><td><div><div><p>HTML to Markdown</p></div></div></td><td><div><div><p>Converts HTML content in tool results to Markdown.</p></div></div></td><td><div><div><p>Enabled</p></div></div></td></tr><tr><td><div><div><p>Strip Base64</p></div></div></td><td><div><div><p>Detects and removes base64-encoded data from tool results.</p></div></div></td><td><div><div><p>Enabled</p></div></div></td></tr><tr><td><div><div><p>Remove Nulls</p></div></div></td><td><div><div><p>Removes JSON fields whose value is null.</p></div></div></td><td><div><div><p>Disabled</p></div></div></td></tr><tr><td><div><div><p>Collapse Whitespace</p></div></div></td><td><div><div><p>Removes excess whitespace in text content.</p></div></div></td><td><div><div><p>Enabled</p></div></div></td></tr><tr><td><div><div><p>Min Response Size (bytes)</p></div></div></td><td><div><div><p>Minimum response size in bytes to transform. Smaller responses pass through unchanged. Minimum value is <code>0</code>.</p></div></div></td><td><div><div><p><code>500</code></p></div></div></td></tr><tr><td><div><div><p>Per-Tool Overrides</p></div></div></td><td><div><div><p>Overrides the policy configuration values for specific tool names. Tools without an override use the global policy configuration. To learn more, see <a href="#tool-overrides">Per-tool overrides</a>.</p></div></div></td><td><div><div><p>N/A</p></div></div></td></tr></tbody></table>

### Per-tool overrides

Use **Per-Tool Overrides** to overide the 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 but for not **Min Response Size**.

If you omit a parameter in an override configration, the tool uses the corresponding value from the
global policy configuration.

## See Also

- [MCP Support Policy](https://docs.mulesoft.com/gateway/1.12/policies-included-mcp-support)
