Portainer MCP tools return large JSON payloads (e.g., full K8s status blocks or complete stack manifests) that can quickly exceed the ~50,000 character response cap and consume significant context tokens (up to 20K tokens for a single call).
To prevent truncation and save context, use the optional select parameter to apply a JMESPath projection server-side. This allows you to request only the specific fields required for a task.
Key JMESPath patterns for Portainer:
- List of objects: Start with
[] to map over elements (e.g., [].{id:Id, name:Name}). - Wrapped lists (Kubernetes): Start with
items[] (e.g., items[].{name:metadata.name}). - Single object: Use direct paths without leading brackets (e.g.,
{field:path.to.value}). - Nested paths: Use dots (e.g.,
Snapshots[0].RunningContainerCount). - Keys with dots/hyphens: Use double quotes to avoid syntax collisions (e.g.,
Labels."com.docker.compose.project"). Note: Do not use backslashes to escape quotes inside the string; use plain double quotes "..." or use a function filter like [?contains(metadata.name, 'value')] to avoid transport issues.
# Example: Projecting only necessary fields for a list of endpoints
EndpointList(select="[].{id:Id,name:Name,type:Type,status:Status}")
# Example: Projecting Kubernetes pod details
kubernetes_proxy(environment_id=N, path="/api/v1/pods", select="items[].{name:metadata.name,ns:metadata.namespace,phase:status.phase}")