Optimize Response (JSON) with HTTP Request Tool

Describe the problem/error/question

Searched for a solution in community forum, tried multiple values / expressions but not getting the desired output response with “HTTP Request Tool”.

I developed an MCP Server Trigger for Azure data retrieval. The implementation uses a Graph API endpoint to fetch all VM instances (https://management.azure.com/subscriptions/[subscription-id]/providers/Microsoft.Compute/virtualMachines?api-version=2023-03-01)

The response is too large for my Azure AI agent, so I want to use the “Optimize Response” option.

Below example response:

{
“response”: [
{
“value”: [
{
“name”: “APP001”,
“id”: “/subscriptions/ZZZZ”,
“type”: “Microsoft.Compute/virtualMachines”,
“location”: “westeurope”,
“tags”: {
“displayName”: “VM”
}
},
{
“name”: “APP002”,
“id”: “/subscriptions/ZZZZZ”,
“type”: “Microsoft.Compute/virtualMachines”,
“location”: “westeurope”,
“tags”: {
“displayName”: “VM”
}
}
],
“nextLink”: “https://management.azure.com/subscriptions/…”
}
]
}

I need two things from the response: the Name of each VM and the nextLink to retrieve additional VMs.

Things I tried:

Test 1

Output: Response shows the VM names but missing the nextLink

Test 2

Output: Response shows nextLink but missing VM names
Troubleshooting: value[0].name retrieves single VM only; map() expression unsuccessful

Test 3


Output: The MCP Server Trigger - GetAllAzureVMs is timing out. I’m uncertain if my implementation is correct.

What is the error message (if any)?

See explantion above in output.

Please share your workflow

Information on your n8n setup

  • n8n version: 1.100.1
  • Database (default: SQLite): default
  • n8n EXECUTIONS_PROCESS setting (default: own, main): main
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker Desktop
  • Operating system: Windows

I’ve exhausted all my troubleshooting options. If anyone knows a solution, I’d greatly appreciate the help.

Cheers,
Hans

Not sure if this helps, but a workaround for me was to generate an arbitrary number of fields automatically. Downside is you’ll get alot of nulls, but assuming you set your upper bound to a higher enough number you can catch everything, and let the LLM exclude the nulls…

  • Include Fields: Selected
  • Fields [Expression]:

{{ […Array(5).keys()].map( m => ‘value[' +m+ '].name').join() }}

1 Like

This was really helpful, thanks!

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.