Response transforms with an agent
Create a response transform from the Core MCP.
Create a response transform when a target response needs code after filters run. You need the organisation clientId, the parent proxyId, and source that default-exports a function.
Call get_guide with guide_key: "transform-creation" before the first create. The transform tools are shared with request transforms. Set transformType to response; it cannot be changed later.
Call order
- Call
list_proxy_transformswithclientIdandproxyId. Keep rows whosetransformTypeisresponse. - Call
create_proxy_transformwithclientId,proxyId,transformType,transformMode,transformActive, andcode. - Save the returned transform
sKeyastransformId. - Call
get_proxy_transformwith all three ids to read its source. - Call
update_proxy_transformwith the ids and only the fields to change.
For conditional transforms, pass effect and any request or response predicates. Optional fields include priority, notes, variables, and alerts.
Example
{
"clientId": "organisation-id",
"proxyId": "proxy-id",
"transformType": "response",
"transformMode": "all",
"transformActive": true,
"code": "export default function transform(proxyContext, proxyRequest, targetResponse) { return { ...targetResponse, headers: { ...targetResponse.headers, \"x-request-path\": proxyContext.path } }; }"
}A successful tool result has success: true. Its data.transforms[0].sKey is the new transformId.
The function receives (proxyContext, proxyRequest, targetResponse). It must return an object with a numeric status; headers and data carry the transformed response. Imports, require, fetch, and process are rejected.
Use a filter for retain or destroy operations on successful JSON. Use a response transform when the output requires code.