N8N Ai Agent Loop failing Calling MCP Client tools connect to grafana-mcp

Hi everyone,

I am running into a tool calling issue with the AI Agent node connected to Grafana (specifically targeting a Prometheus datasource).

The Setup: I have an AI Agent connected to Grafana tools. The goal is to query Prometheus metrics.

The Issue: On the first iteration, the agent works perfectly. It calls the correct tool (query_prometheus) with the correct schema. However, on the second iteration (when the agent tries to refine or query more data), it fails. Instead of calling query_prometheus again, it looks like hallucinate the process calling tools, but the N8N UI tells that the Grafana MCP only calls 1-2 times.

Tools : GitHub - grafana/mcp-grafana: MCP server for Grafana · GitHub

Please share your workflow

Share the output returned by the last node

[ERROR: Max iterations (20) reached. The agent could not complete the task within the allowed number of iterations.]

Information on your n8n setup

  • n8n version: 2.1.4
  • Database (default: SQLite): Postgres
  • n8n EXECUTIONS_PROCESS setting (default: own, main): own
  • Running n8n via (Docker, npm, n8n cloud, desktop app): Docker K8S
  • Operating system: Linux CentOS 8

@Farhan_Naufal_Ghani There’s 3 things that might be contributing to your tool calling issue:

  1. The Google Gemini Chat Model is not supported for use with tool agents according to the docs. Try switching to OpenAI, Anthropic, or any of the other supported models listed on the docs page for tool agents.

  2. The Grafana MCP Client Tool node is currently set to include all tools:

    Could specifying which tools you want to call help with limiting the iterations it takes? At the very least, it might be more token-efficient to limit the tools available

  3. In addition to specifying which tools to include in the MCP Client Tool node, defining this in the AI Agent’s system prompt could help as well (e.g. “you can use tools from the Grafana MCP: query_prometheus: Query prometheus metrics”)

  4. I also wonder if this could simply be an issue with the question you’ve asked. While there should be a “list tools” MCP endpoint, I’ve had issues with asking questions in the chat trigger that lead to loop failures when calling the MCP tool.

Hopefully some of this helps

Thanks for the suggestion @Nifemi_Emmanuel
Currently, I’m trying to separate the tools that don’t require AI to function. However, in some scenarios, we need AI to explore further—for things we haven’t explicitly defined, like assistants that can search and handle various tasks.

@tdot33 After reading your suggestion, I started exploring other Gemini models. I found that Gemini Flash 2.5 can handle this, but I’m not sure why gemini-3-flash-preview isn’t able to perform tool calling correctly :sweat_smile: , for limitting tools i’ll do this thanks :+1:

Hi @Farhan_Naufal_Ghani

I am using the gpt-5-mini model which supports the tool calling but even with this model the agent sometimes call the wrong tools like list_datasources.

Can you please let me know how were you able to fix it ?