Recipe: Using custom code to process response data from MCP tools in action flows

<body>
<p id="docs-hc-snippet" style="display: none;">In this article, you’ll use custom code to process output from an MCP action so you can extract the data you need and use it in later steps of an action flow. Because MCP servers don't always define the data each tool returns, you might need to do a little extra work to use an MCP tool’s output. This recipe describes how to do that. The examples in this article useAsana, but the same approach works for objects returned by any MCP server.</p>
<div class="article-banners">
<div id="docs-wmp-link">
<a href="https://support.zendesk.com/hc/en-us/articles/5411234991258-plan" rel="noopener" target="_blank">What's my plan?</a>
</div>

<div class="article-banner" id="suite_gpee">
<table>
<tbody>
<tr>
<td>
<strong>All Suites</strong>
</td>
<td>Growth, Professional, Enterprise, or Enterprise Plus</td>
</tr>
</tbody>
</table>
</div>

<div class="article-banner" id="support_all">
<table>
<tbody>
<tr>
<td>
<strong>Support</strong>
</td>
<td>Team, Professional, or Enterprise</td>
</tr>
</tbody>
</table>
</div>

</div>

<div class="body">

<div class="p">
<div class="note attention" id="topic_wxc_ccr_ljc__note_nlf_fx2_d3c">
<span class="attentiontitle"></span> Support for MCP servers and MCP tools is
currently in an early access program (EAP). To participate, click <strong class="ph b">Activate early
access</strong> and accept the EAP terms.</div>
</div>
<p class="p">In this article, you’ll use custom code to process output from an MCP action so you can
extract the data you need and use it in later steps of an action flow. Because MCP
servers don't always define the data each tool returns, you might need to do a little
extra work to use an MCP tool’s output. This recipe describes how to do that. The
examples in this article use <a class="xref" href="https://support.zendesk.com/hc/en-us/articles/10623225702298-Using-Asana-actions-in-action-flows" target="_blank">Asana</a>, but the same approach works for objects
returned by any MCP server.</p>
<p class="p">This article contains the following topics:</p>
<ul class="ul" id="topic_wxc_ccr_ljc__ul_qr3_chr_ljc">
<li class="li"><a class="xref" href="#topic_svx_whr_ljc">Considerations</a></li>
<li class="li"><a class="xref" href="#topic_bmj_dcl_njc">Recipe: Processing objects from MCP tools in action flows</a></li>
<li class="li"><a class="xref" href="#topic_f4v_x2r_ljc">Using AI to help write the custom code</a></li>
</ul>
</div>
<div aria-labelledby="ariaid-title2" class="topic nested1" id="topic_svx_whr_ljc">
<h2 class="title topictitle2" id="ariaid-title2">Considerations</h2>
<div class="body">
<p class="p"> This tutorial assumes some familiarity with action flows and MCP. If you are new to
action flows and action builder, see:</p>
<ul class="ul" id="topic_svx_whr_ljc__ul_xw3_2dr_ljc">
<li class="li"><a class="xref" href="https://support.zendesk.com/hc/en-us/articles/8855513857306-Understanding-the-action-builder-and-action-flows" target="_blank">Understanding the action builder and action
flows</a></li>
<li class="li"><a class="xref" href="https://support.zendesk.com/hc/en-us/articles/8855601898266-Creating-action-flows-to-automate-processes-across-Zendesk-and-external-systems" target="_blank">Creating action flows to automate processes
across Zendesk and external systems</a></li>
<li class="li"><a class="xref" href="https://support.zendesk.com/hc/en-us/articles/9853782610970-Using-custom-code-steps-in-action-flows" target="_blank">Using custom code steps in action
flows</a></li>
</ul>
</div>
</div>
<div aria-labelledby="ariaid-title3" class="topic nested1" id="topic_bmj_dcl_njc">
<h2 class="title topictitle2" id="ariaid-title3">Recipe: Processing objects from MCP tools in action flows</h2>
<div class="body">
<p class="p">The following steps describe how to test an MCP action to see what data it returns
and use a custom code step to turn a JSON object into individual fields that you can
use in later steps of an action flow.</p>
<div class="p">
<strong class="ph b">To create an action flow that processes object data from MCP tools</strong><ol class="ol" id="topic_bmj_dcl_njc__ol_epr_ncl_njc">
<li class="li">
<a class="xref" href="https://support.zendesk.com/hc/en-us/articles/10497779528730-Connecting-to-MCP-servers-and-using-MCP-tools-in-action-flows" target="_blank">Connect an MCP server</a>.<p class="p">In this
example, we use Asana's MCP server.</p>
</li>
<li class="li">
<a class="xref" href="https://support.zendesk.com/hc/en-us/articles/8855601898266" target="_blank">Create</a> or <a class="xref" href="https://support.zendesk.com/hc/en-us/articles/9052312956570" target="_blank">edit</a> an action flow.</li>
<li class="li">After you add an action flow trigger, <a class="xref" href="https://support.zendesk.com/hc/en-us/articles/10497779528730#topic_hlj_nbh_53c" target="_blank">add an MCP tool as a step in an action
flow</a>.</li>
<li class="li">Click <strong class="ph b">Save</strong>.</li>
<li class="li">
<a class="xref" href="https://support.zendesk.com/hc/en-us/articles/9052312956570#topic_uyj_qsw_3fc" target="_blank">Test the action flow.</a><p class="p">When the
test completes successfully, click the arrow to expand the MCP step
output.</p>
<p class="p"><img class="image img-screenshot" id="topic_bmj_dcl_njc__image_mqx_hr3_x2b" src="https://zen-marketing-documentation.s3.amazonaws.com/docs/en/mcp_tutorial_getproject.png" width="500"></p>
</li>
<li class="li">Review the MCP step's output to identify the data you want to use. <div class="p">In this example, the <em class="ph i">Get
project</em> action returns a JSON object similar to the
following:<pre class="pre codeblock"><code>{
"archived": false,
"color": "purple",
"completed": false,
"completed_at": null,
"created_at": "2026-04-28T02:58:53.099Z",
"current_status": {
"gid": "1234535757412345",
"modified_at": "2026-04-28T04:39:04.032Z",
"resource_type": "project_status",
"text": "Summary\n\nFollowing on from the successful robot uprising, a T800 infiltration unit has been built and dispatched to 1984 in search of Sarah Connor.\n\n----------------------------------------\n\n\n",
"title": "Operation Cyberdyne - Apr 28"
},
"custom_fields": [],
"name": "Operation Cyberdyne",
"notes": ""
}</code></pre>
</div>
<div class="p">For
the purposes of the example, we only need three of those properties:<ul class="ul" id="topic_bmj_dcl_njc__ul_tkc_f2l_njc">
<li class="li"><code class="ph codeph">name</code></li>
<li class="li"><code class="ph codeph">current_status.text</code></li>
<li class="li"><code class="ph codeph">current_status.modified_at</code></li>
</ul>
</div>
</li>
<li class="li">
<a class="xref" href="https://support.zendesk.com/hc/en-us/articles/9853782610970" target="_blank">Add a custom code step</a> to the
action flow to process the MCP response and the specific values you
need.<div class="p">The following example takes the output of the <em class="ph i">Get project</em>
step from Asana and extracts the three fields needed for the rest of the
action flow. You can use this example as a starting point for your own
custom code, or you can <a class="xref" href="#topic_f4v_x2r_ljc">use AI</a> to help you write your custom code
step.<pre class="pre codeblock" id="topic_bmj_dcl_njc__codeblock_tsw_52r_ljc"><code>module.exports = (inputs) =&gt; {
// This code takes an object input named 'output'
// and returns 'name', 'current_status_modified_at', and 'current_status_text'.
// If any property is missing or invalid, the code returns an empty string.

// Make sure to create the following inputs:
// output (object) - stringified object or actual object

// Accept 'output' either as a stringified JSON object or as an object.
let outputObj;
if (typeof inputs.output === 'string') {
try {
outputObj = JSON.parse(inputs.output);
} catch {
outputObj = {};
}
} else if (typeof inputs.output === 'object' &amp;&amp; inputs.output !== null) {
outputObj = inputs.output;
} else {
outputObj = {};
}

const name = typeof outputObj.name === 'string' ? outputObj.name : "";

const current_status_modified_at =
outputObj.current_status &amp;&amp; typeof outputObj.current_status.modified_at === 'string'
? outputObj.current_status.modified_at
: "";

const current_status_text =
outputObj.current_status &amp;&amp; typeof outputObj.current_status.text === 'string'
? outputObj.current_status.text
: "";

// Make sure to create the following outputs:
// name (Text)
// current_status_modified_at (Date and time)
// current_status_text (Text)

return {
name,
current_status_modified_at,
current_status_text
};
};</code></pre>
</div>
</li>
<li class="li">Add any additional steps required to complete your action flow. For example,
you might want to:<ul class="ul" id="topic_bmj_dcl_njc__ul_e3g_y2l_njc">
<li class="li">Use the <em class="ph i">Zendesk: Update ticket</em> action to add the values to a
ticket comment or the <em class="ph i">External actions: Slack: Post message</em>
action to send a message to a channel in Slack with the extracted
values.</li>
<li class="li">Use the values as inputs for a custom action.</li>
<li class="li">(Only if your flow uses the <em class="ph i">Run on demand</em> action flow
trigger) Use the <em class="ph i">Send outputs</em> step to send the extracted
values to auto assist.</li>
</ul>
</li>
<li class="li">Save and test your action flow.</li>
<li class="li">When you're ready to use the action flow, click <strong class="ph b">Activate</strong>.</li>
</ol>
</div>
</div>
</div>
<div aria-labelledby="ariaid-title4" class="topic nested1" id="topic_f4v_x2r_ljc">
<h2 class="title topictitle2" id="ariaid-title4">Using AI to help write the custom code</h2>
<div class="body">
<p class="p">You can paste the full test output into your preferred AI tool and ask it to help you
write the custom code. Here’s a prompt to get you started:</p>
<pre class="pre codeblock" id="topic_f4v_x2r_ljc__codeblock_d2d_z2r_ljc"><code>Write JavaScript code that exports a function taking an inputs object and returning an outputs object. For example:

module.exports = (inputs) =&gt; {
let msg = "Your text was " + inputs.inputText + "."
return {
outputMessage: msg
}
}

Supported data types:
Strings, numbers, booleans, dates (YY-MM-DD), datetimes (YY-MM-DDTHH:mm:SSZ), objects, and arrays are supported.
Arrays must contain only one data type.

Arrays of arrays, arrays of objects, and mixed-type arrays are not supported.
If these are used as inputs or outputs, they must be stringified and passed as strings.

Handle missing data:
Check for missing or invalid data and handle it gracefully by returning valid default values:

- strings: ""
- numbers: -1
- booleans: false
- arrays: []
- objects: {}

Comment the code:
Include a brief comment at the top describing what the code does.

Add comments telling the reader to create the inputs and outputs, for example:
// Make sure to create the following inputs: field_tag (Text)

In comments, use these friendly names for data types:
- string: use "Date" for dates, "Date and time" for datetimes, otherwise "Text"
- number: use "Number" or "Decimal"
- boolean: use "True/False"
- array: use "Number array", "Text array", and so on

Code functionality:
The code should take an input like the example below and ...

&lt;DESCRIBE WHAT YOU WANT YOUR CODE TO DO HERE&gt;
&lt;PASTE YOUR TEST OUTPUT HERE - BE MINDFUL OF PASSING SENSITIVE DATA TO AN AI&gt;</code></pre>
</div>
</div>
<script id="docs-schema-markup" type="application/ld+json">{
"@context": "https://schema.org",
"@type": "TechArticle",
"@id": "https://support.zendesk.com/hc/en-us/articles/10856375514906-Recipe-Using-custom-code-to-process-response-data-from-MCP-tools-in-action-flows",
"url": "https://support.zendesk.com/hc/en-us/articles/10856375514906-Recipe-Using-custom-code-to-process-response-data-from-MCP-tools-in-action-flows",
"headline": "Recipe: Using custom code to process response data from MCP tools in action flows",
"description": "You can use custom code in action flows to process and extract specific data from MCP tool responses, enabling you to utilize that data in subsequent steps of the flow.",
"articleSection": "Product help",
"datePublished": "2026-06-02T21:15:56+00:00",
"dateModified": "2026-06-10T15:40:08.478384+00:00",
"inLanguage": "en-US",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "https://support.zendesk.com/hc/en-us/articles/10856375514906-Recipe-Using-custom-code-to-process-response-data-from-MCP-tools-in-action-flows"
},
"author": {
"@type": "Organization",
"name": "Zendesk",
"url": "https://www.zendesk.com"
},
"publisher": {
"@type": "Organization",
"name": "Zendesk"
},
"isPartOf": {
"@type": "WebSite",
"name": "Zendesk Help",
"url": "https://support.zendesk.com/hc/en-us"
},
"about": {
"@type": "SoftwareApplication",
"name": "Zendesk"
}
}</script>
</body>