How to develop smarter AI Agents by using MCP in n8n

N8n is a widely used workflow automation tool that revolutionized the way we automate repetitive processes. Although n8n provides a seamless experience to create workflows and its AI features, specifically LLM nodes are best at making intelligent decisions in these workflows. But these LLM nodes have a major limitation: they make decisions solely based on their intelligence, which is primarily derived from their training data. But in reality, we can’t apply the same intelligence/decision to all the problems. The context of the problem plays an important role in our decision-making process. To enable LLM nodes to make context-aware decisions, we can utilize the MCP (Model Context Protocol) in n8n.

Using MCP in n8n provides these workflows an extra layer of context, enabling LLMs to collect the data from external sources to make better context-aware decisions.

What is n8n?

N8n is a workflow automation tool that helps you create automation workflows using different nodes. We can connect these nodes using a drag-and-drop approach in a visual interface. Its seamless user experience allows it to develop complex AI automations without even touching a single line of code.

What is MCP?

MCP(Model Context Protocol) is a standard protocol for LLMs to communicate with external tools. This communication extends the capabilities of LLMs to get the data from these external sources to make context-aware decisions, and also allows LLMs to perform tasks inside these external tools. This provides an agentic capability to the LLMs.


Why Use MCP in n8n?

Using MCP in n8n provides the powerful capabilities to LLM nodes in n8n. It allows LLM to do more than just respond. It provides them with agentic capabilities to “ACT” as per the user’s query. It is basically a bridge between the LLM and its external tools.

For Example, if you ask an LLM, about I want to send an email to my physician for an appointment. LLM can generate the email for you, but it can’t send it for you. But if you use the MCP server of Gmail with your LLM, now it can send the email to your doctor as well.

Setting Up n8n for MCP Integration

We can use the cloud-hosted version of n8n, but we will be installing it locally and using it on localhost. If you have an n8n subscription, you can use the cloud-hosted version as well, but using it locally is completely free.

To install it locally, you have to first install NodeJS on your system. Once you have Node.js installed on your system. Simply open the command prompt or Windows PowerShell and run the following command.

 npx n8n

After running this command, simply press o to open the editor in a browser, or you can visit this URL (http://localhost:5678/) to open it.

On the editor page, you have to set up your owner account by adding your details.

After adding your details and setting up your owner account, you will be redirected to the following page.

And we have successfully set up n8n locally. Now, we can build our first n8n workflow, but we have to use the MCP. For this, we have to install the n8n-nodes-mcp community node.

First, we have to click on the settings in the bottom left.

Then we have to click on the community nodes.

And then we have to click on the “Install a community node” button.

Now, here we have to type the name of the node in the input field to install, i.e., “n8n-nodes-mcp,” and simply click on the install.

Once it is installed, you will see it listed here.

Now, we can use this MCP node to create MCP-powered workflows in n8n.

Building our First MCP Workflow in n8n

To understand the true power of MCP, we will first create a simple workflow without MCP and check its response to a query. After this, we will introduce the MCP in our workflow and will check the response to the same query. This will give us an idea about the true potential of MCPs.

We will just create a simple AI Agent using the AI Agent node in n8n and attach OpenAI’s chat model. You can use any other chat model as well. The workflow will look like this.

Now just run this workflow and ask the agent, “How is the weather in New York today?”

Ok, I have asked this question to the agent it is saying I can’t provide real-time information. You should check a website or an app. So, we are unable to get the real-time data from our Agent. It is providing the responses from the data it is trained on and is completely unaware of the real-time weather of New York. 

Now, let’s use MCP here to enable the model to be fully aware 

Of the current weather in New York. For this, we will use an MCP server of Tavily. This MCP will provide the search capability to our agent.

To achieve this, we will simply add 2 MCP Client nodes that we have installed earlier in the tools of our AI Agent, as shown in this image.

We are using the Tavily MCP, so we have to configure the credentials of this server in our nodes. We simply have to use these configurations and add them to our nodes.

Tavily MCP Server

{

  "mcpServers": {

    "tavily-mcp": {

      "command": "npx",

      "args": ["-y", "tavily-mcp@latest"],

      "env": {

        "TAVILY_API_KEY": "your-api-key-here"

      },

      "disabled": false,

      "autoApprove": []

    }

  }

}

For TAVILY_API_KEY, we can create a free API key on Tavily by visiting the Tavily docs.

The configuration will be the same for both nodes. The only difference we have between the MCP Tavily Tool node and the MCP Tavily Execute node is the operation parameter. For the MCP Tavily Tool, the operation value will be List Tools, and for the MCP Tavily Execute node operation value will be Execute Tool, and you have to define the other two parameters as shown in the image below.

After this, we have to change the Source of Prompt parameter (User Message) to define below and add the following prompt in the prompt box.

Prompt (User Message)

Suggest to me the best tool to get data from MCP Tools based on user input: {{ $json.chatInput }} and based on the tool, get the details from this tool using the MCP Execute Tool. Please provide a concise answer and make sure you don’t mention tools in response. Just answer the user questions only.

Now, after this MCP incorporation, when we have given the same prompt to our AI Agent, it gives us accurate and real-time data. And also, the order of the MCP calling can be seen. First model got the right tool for the current query, then it used that tool to get the data and provided the accurate data based on the tool execution.

Advanced MCP Use Cases

We have discussed an amazing use case of the MCP and seen its true power to enable a model with real data, providing the ability to execute things as required by the model. Now let’s discuss some advanced use cases.

  1. Browser Automation:

Browser automation is one of the most important, useful, and advanced use cases for MCPs. An LLM with the tools to control and browse your browser is a truly transformative technology. It will allow the Agents to search, navigate, take screenshots, and fill out forms on the web using your browser on your behalf, and you can do some other productive stuff.

  1. E-commerce Use Case:

E-commerce is another interesting use case of MCPs. E-commerce organizations often face issues with their sales performance and inventory optimization. MCPs can solve these problems. LLMs can detect the sales pattern of products and can automatically place orders for the best-selling products in your inventory before the inventory goes out of stock. All this can be done using MCP tools.

  1. Healthcare

In healthcare, AI Agents are generating summaries for doctors of patients by fetching the large histories of patients from databases using MCPs. AI agents are also booking the appointments for patients using the MCPs by checking the schedules of doctors.

In conclusion, using MCP in N8N is an extremely helpful way to empower our agents by providing them with agentic capabilities. It allows the LLMs to connect with external sources. LLMs can retrieve data from external sources, push data to external sources, and make informed and context-aware decisions based on this external data.

At Veritas Analytica, we help you build advanced agentic AI applications. If you have an idea to revolutionize your business, just book a free consultation with us today, and we will transform your idea into reality using the right tools and technologies. 

Happy Learning!  

Related Articles

Get in Touch Today

We will help you overcome your data and AI challenges.

Email us at  [email protected]

Fill the form

Fill the form

Fill the form