# Transformers Transformers are a way to sanitize, transform and alter the data: * going INTO a function (MCP, or Collection). Trigger: `onFunctionInput`. * coming OUT a function (MCP, or Collection). Trigger: `onFunctionOutput`. * being loaded from a resource. Trigger: `onResource`. Transformers are defined outside the realm of sessions, and are triggered by hooks. ## Operators * `parser`: (csv/json) if the input data is **plain text** parse the input data into a **structured output**. * `jsonata`: apply a [JSONata](https://jsonata.org/) expression to the structured input (currently deprecated) * `jmesPath`: apply a [JMESPath](https://jmespath.org/) expression to the structured input * `expr`: apply an [Go Expr](https://github.com/expr-lang/expr) expression to the structured input * `code`: run a script against the input data, assuming the integrating application provides a scripting engine. The CLI supports a vanilla JavaScript runtime. A single transformer can implement all the above operators and will be applied as a transformation chain top-down. ## YAML This example sanitizes GitHub pull request data (MCP function): ```yaml transformers: - name: cleanup_atlassian onFunctionOutput: search_pull_requests jsonata: |- items.{ "title": title, "state": state, "url": html_url, "author": user.login } ``` This example loads a csv [resource](Resources.md) into memory, but first makes into a data structure so that the prompt can reference it: ```yaml transformers: - name: csv1 onResource: data/data2.csv parser: csv jmesPath: '[1:].{first_name: [0], last_name: [1]}' sessions: parsed_content_into_memory: prompt: |- who was {{ (index .vars.data2 2).first_name }} {{ (index .vars.data2 2).last_name }}. resources: - identifier: data/data2.csv in: vars var: data2 ``` ## Go Same as the YAML version, nothing special here.