JMESPath Pruning

JMESPath is a declarative query language designed for extracting and transforming data from JSON documents. In the context of the Model Context Protocol (MCP) and HasMCP, JMESPath pruning is a critical optimization technique used to reduce the size of API responses before they are sent to an LLM.

How it works in HasMCP

HasMCP integrates a high-speed JMESPath engine that allows developers to define extraction patterns for their tools. By applying a JMESPath filter, HasMCP can prune a massive JSON response (e.g., 100KB) down to just the essential fields (e.g., 500 bytes) required by the AI agent.

Practical Data Pruning with HasMCP

HasMCP makes JMESPath pruning highly accessible through its declarative configuration. By identifying the most valuable fields in a response—such as status, IDs, or specific nested values—developers can strip away hundreds of irrelevant fields with a single line of JMESPath. This "before/after" optimization is visible in the HasMCP Payload Inspector, allowing teams to quantify exactly how much "noise" is being removed from their AI agent's working memory.

Example

Original API Response:

{
  "id": "ord_12345",
  "status": "shipped",
  "customer": {
    "name": "John Doe",
    "email": "john@example.com",
    "internal_notes": "Very long history of orders..."
  },
  "items": [
    {"sku": "A123", "price": 10.99, "weight": 0.5},
    {"sku": "B456", "price": 25.00, "weight": 1.2}
  ],
  "raw_logs": "..."
}

JMESPath Filter:

{id: id, status: status, total_items: length(items)}

Pruned Result:

{

"id": "ord_12345",

"status": "shipped",

"total_items": 2

}

`

Questions & Answers

What is JMESPath, and how is it used in HasMCP?

JMESPath is a declarative JSON query language. In HasMCP, it is used to prune large API responses, extracting only the essential fields needed by an AI agent before they are sent to the model's context window.

Why is pruning important for AI performance?

Pruning reduces the size of payloads, which significantly lowers token consumption, decreases API latency, and reduces noise in the AI model's working memory, leading to more accurate and faster results.

Where can developers see the effect of their JMESPath pruning in HasMCP?

Developers can use the HasMCP Payload Inspector to compare "before and after" views of their data, allowing them to verify exactly which fields are being extracted and how much data is being removed.

Back to Glossary