Skip to main content

Overview

When a tool calls an external API, the raw response is often large — paginated lists with dozens of fields, nested objects, metadata the AI never needs. GetMCP’s response pruning lets you extract only the relevant data before the response is sent to the AI client. Two query engines are available: JMESPath is the recommended engine for any response that involves filtering or reshaping data — it can reduce a 50 KB API response to a few hundred bytes before the AI ever sees it.

Why This Matters: Token Costs

AI models bill by token. A token is roughly 4 characters of text. Every byte in an API response that reaches the AI is a byte you’re paying for — and a byte consuming limited context-window space. Example: a WooCommerce orders list At 500 tool calls per day, that’s ~$300/day saved from one JMESPath expression. Beyond cost, smaller payloads:
  • Fit more tool results in a single AI context window
  • Reduce hallucination risk (the AI focuses on fewer fields)
  • Make session replay and logs far more readable

Where to Configure It

Open GetMCP → Servers → {Your Server} → Tools → {Tool} → Edit. In the Response Mapping section:
  1. Set Selector Type to jmespath.
  2. Enter your JMESPath expression in the Selector field.
  3. Click Test to see the pruned output live.
Tool Editor — Response Mapping section with JMESPath engine selected and expression field

JMESPath Syntax Quick Reference

JMESPath expressions operate on the decoded JSON body of the API response.

Extract a field

Extracts the items array from { "data": { "items": [...] } }.

Project specific fields from an array

Turns an array of full product objects into an array of {id, name, price} objects — everything else is dropped.

Filter an array

Returns only orders where status equals "pending".

Filter and project

Combines filtering and projection — only pending orders, only three fields each.

Nested access

Walks any depth of nesting.

Sort and slice

Returns the 10 cheapest products sorted by price ascending.

Flatten a nested list

Flattens [{tags: [...]}, {tags: [...]}] into a single flat tag list.

Practical Examples

WooCommerce: orders list

Raw response from /wp-json/wc/v3/orders is ~8 KB per order. Pruning extracts only what the AI needs:
Result: ~150 bytes per order instead of 8 KB — a 50× reduction.

Mailchimp: campaign stats

OpenWeather API: current conditions only

GitHub: PR list — only open ones


Live Testing

Use the Test button in the Tool Editor to call the real API. The result panel has three tabs:
  • MCP Output — the pruned payload, exactly what the AI client receives
  • Raw Response — the full upstream body, for checking your expression against real data
  • Outbound Request — the URL, headers and body GetMCP sent upstream
Switch between MCP Output and Raw Response to see what the expression removed. Tool Editor test result panel on the MCP Output tab, showing the pruned payload

Token Savings Dashboard

Every live tool call records the upstream byte count (raw) and the delivered byte count (after pruning). The Interceptor Savings widget on the Analytics page shows the aggregate savings across all calls, so you can see the real-world impact of your JMESPath expressions. Analytics page — Interceptor Savings widget showing upstream bytes, saved bytes, and delivered bytes

How Pruning Fits in the Processing Pipeline

Every tool call passes through this sequence before the AI sees the result:
JMESPath runs first — which is important for two reasons:
  1. PII redaction is faster. The redactor only regex-scans the fields that survived pruning. If you’ve already stripped 49 of 50 fields with JMESPath, the PII engine has 98% less text to process.
  2. PII placeholders land correctly. Template substitution sees [REDACTED:EMAIL] as a label rather than a raw email address, so the AI still understands something was present.

Using Pruning and PII Redaction Together

This is the recommended combination for any tool that touches customer or personal data:
  • JMESPath removes fields the AI doesn’t need (cost savings + focus)
  • PII Redaction scrubs sensitive values from the fields the AI does see (compliance + safety)
Example — CRM contact lookup:
This prunes the contact object from 40+ fields to 4. Then PII redaction replaces the actual email addresses with [REDACTED:EMAIL] before the AI sees them. The AI knows a contact has an email field, but never sees the address. Configure PII redaction under Server Settings → PII Redaction. See the PII Redaction guide for details.

Fallback Behaviour


JSONPath vs JMESPath

Use JSONPath when migrating existing selectors written for it. Use JMESPath for any new tool that needs filtering or projection.