This feature makes building AI Agents 10x easier (MCP server setup)

Rory Ridgers shows how MCP servers let you build AI agents with far fewer nodes by dynamically discovering tools instead of hard-coding each one. He walks through setting up MCP in n8n, building a two-node agent that queries an Airbnb server and executes tools based on what the LLM picks.
Chapters
Okay, so there's a new thing going around in the AI agent space called MCP servers. It's literally all I've been seeing for the past week, and it solves a lot of problems that we've had currently with building AI agents. You can see here, this normally is the way that we build AI agents. So you've probably all seen this before. We have an input, they have our agent here, it's able to use different tools to give us an output. So for an example, an input may be something like, hey, can you send the email to Dave saying what's up? Then the AI agent can process that, use the send email tool, and give us an output saying, yep, that's been sent over. So an example of how an AI agent build using this sort of method may look something like this. You can ignore this bit, this is just the trigger through Telegram, so don't worry about that. But you can see here we have basically an input and output, and then we have these different tools here. So we have get emails, send email, uh, get events from Google Calendar, add Airtable record, search Airtable records, and YouTube video ideas. So essentially what we're doing here is we're putting down different nodes which are API endpoints for specific functions. So get emails, there is an endpoint on Gmail to be able to get emails from your inbox. Then you kind of hard code in the different variables. So it might be the amount of emails, the criteria for emails that you're looking for might be only unread emails or only emails in a certain label. For example, you have to kind of hard code these things in. So there'll be input boxes on something like NAN, there'll be input boxes and in there you put variables that you want. So for example, 50 emails, you might put that in the how many emails input, you might put 50, and then there'll be a bunch of other ones. This is basically the JSON schema that we need for that specific API endpoint. So for get emails, like I said, it could be amount of emails, specific criteria, and then specific email label, for example. And then you put in your variables, 50 unread emails only, and in the label business, for example. That's up until this point how we build AI agents. But there is a new sort of way to assign tools to your AI agents, which solves some of these problems. So a new way to do it is by using something called an MCP server. And what this stands for is Model Context Protocol. And the way you've got to kind of think about it is, is basically rather than connecting to one specific endpoint— so for example, if we have a look at this again, like the Gmail endpoint to get emails— rather than connecting to that specific endpoint, what we do, for example, is just connect to Gmail. And then when we're connecting to the Gmail MCP server, we can get these different data points. So we can get things like tools, documents, schemas, and a bunch of other things. But basically, we can interact with the server to get these different things back. So like I said, tools, docs, schemas, that kind of thing. And you're just interacting with kind of the entire server rather than just that one specific endpoint. So, so the way it might work is We get an input to send an email, for example. The AI agent— you can do this with absolutely no prompt, which is really, really cool— the AI agent can go over to the Gmail MCP server. It can look at all the different tools it has. So for example, things like send emails, get emails, change email category. There's a bunch of them for Gmail. It can check all the different tools, and then it can look at the schema for these tools. So it can look at the endpoints, the JSON schema that we need to send over to this endpoint. And then it can use the appropriate tool. So if we say something like send an email to duh duh duh, it can look at the tools, find all the different functions that it can use, and then it can get the schemas for each of those tools. And then it can say, okay, we need to use the send email function, look at the schema for that. So the schema may be the to email, the email subject line, and then the email body. And then it can just use that tool via the MCP server. So it can just adding the endpoint for that tool. On Gmail, you need to go into your Google Cloud Console and set up some credentials and stuff, but you do that on the MCP server level, so you don't have to do it every single time you want to use it. Or you just set it up once for the MCP server and then it just works from there. So we'll look at the schema for the send email function. It will get the endpoint that it needs to use, and then it will look at the schema, so the to email, the subject line, and the email body, and then it can just use that tool via the MCP server. So the main benefit for this is you don't have to have agents that have loads of different tools connected to them that are using the same software. So for example, just gonna use Gmail again. If you wanted to have an email assistant, you wouldn't have to connect up 5 tools that get emails, send emails, change email categories, mark emails as read or unread. For example, you wouldn't have to have all these different tools and prompt the agent how to use each of these specific tools. You could just connect up the Gmail MCP server and just say to the agent, I want to get my last 50 emails from my inbox. It can trigger the MCP server, see all the different endpoints and different tools that it can use, and then say, okay, we need to use the get emails function, can look at the schema for that, and then it can input all the right data into that endpoint and then send off the request via the MCP server. So it's basically just a way more efficient way of using tools. And when you have an agent that is using multiple endpoints for the same software or the same server, so like I said, for Gmail, for example, but it could be anything, could be Airtable, Google Sheets, uh, HubSpot, whatever it might be. You don't have to connect up all these different tools and endpoints like I have in this example. So maybe this isn't best example because these are all tools for kind of different softwares, but you can see I have 2 Gmail tools and I have 2 Airtable tools. That could just be one MCP server for each of them. So it could just be Airtable MCP server and then Gmail MCP server, and the agent would just— when I say to it I want to send an email to this person. It could just go over to the Gmail MCP server, see what it needs to do, see the JSON schema that it needs, and then just send off that request for me and then output to me, okay, done, like an AI agent usually would. So for this video, I've made a really, really simple, um, MCP agent. I can use the Airbnb MCP, and the reason I chose Airbnb, by the way, is because you don't really need to set up any credentials or get an API key or anything like that. You'll basically just scraping Airbnb. So if we just have a look at the anatomy of this, first of all, we just have a chat message node here. So it just means that we can talk to the agent via NAN like this, and then we have obviously our brain hooked up to it. So we have GPT-4o Mini. If you haven't done this before, all you have to do is put down an OpenAI chat model node, hit create new credential, and then go over to your Assistants API account, grab an API key, put it in there, and you'll be connected. It's really, really easy. Then we have two different tools here. So we have the Airbnb List Tools MCP server, and then we have the Airbnb Execute Tool MCP server. And basically what these two tools do is this one here can look at the Airbnb MCP server and see all the different tools that we're able to use, and then this one here can execute those tools. So this might seem a little confusing at the moment, but don't worry, I'll walk you through exactly how it works and all makes sense by the end of the video. So to begin with, to set this up, by default you won't have, um, MCP server nodes set up on NAN. So if I go add node, you can see when I type in MCP, we get MCP client here, which is what you want. By default you won't have that. So what you need to do is you need to come over to the GitHub repo here, and you can look inside all these different files if you like, but you don't need to at all. And basically what this is, is this allows you to get access to these community MCP servers. And by the way, something important I need to mention with this is this only works if you're self-hosting NAN. So personally, I'm self-hosting NAN on Render. If you want a full video on how to do that, then please do just let me know. But if you don't know, with NAN, you can either pay NAN to host it on their servers, or you can just download the source code because OpenAI is open source, so the source code is just out there on GitHub for absolutely free. You just download that and then you can host it yourself, which is what I do. And it means you have the community version of NAN, so you can do things like this, which is really, really cool. So yeah, like I said, if you want a full video on how to set that up, then please do just let me know. But I'm using Render. You can use things like DigitalOcean, Railway, but yeah, I'm using Render to do it. And the reason I say this is obviously because you need the community version, like I just said, but there are also some environment variables that you'll need to add on your NAN instance on whatever you're hosting it on. To set this up properly. So anyway, make sure that you're self-hosting this, and all you do is you copy this name here. So you can just highlight it, Command+C, copy it, come back over to NAN. And then what you're going to do is you want to go to your settings down here, hit save. And then we want to go to community nodes, and I already have something in here, but this would just be blank for you. So you just hit install, and then you literally just paste the name of that GitHub repo into here, hit understand obviously, and then hit install. And then that's literally all you need to do, you'll be set up. Once you do that, if we come back to our workflow here, you should see when you right-click and do add node, type in MCP, and then you can see we have, um, this MCP client node here. And this little box, by the way, just means that it's a community node, so it's not something that's natively on NAN. So yeah, that's a really, really easy setup. By the way, that GitHub repo will be linked in the description of this video, so Don't worry about scrambling around trying to find it, it'll be linked in the video. So let's add one of these nodes down. So MCP client, um, which you can say execute tool, doesn't really matter. So you can see we have these different functions here. So we have execute tool, get prompt, list prompts, list resources, list tools, and read resources. And these are basically the things I was saying here, the different things that you can retrieve from your MCP server. So you can execute a tool, get a prompt, list prompts, list resources, list tools, and then read resources. This node here that I already have set up, the first one is list tools, and then the second one is, uh, execute tools. So this is pretty much what you're going to be doing a lot of the time with these MCP servers is you're going to be looking at the MCP, listing the tools, and then you can have another node that can actually execute those tools. So now I already have Airbnb hooked up to this MCP client node. Let's just say that you didn't have anything at all, it's your first time using it. What you do is go to add new credential. Then you see we get this command arguments and then environments. Don't have to worry about environments, but command and arguments we need. So what we do is we come over to this GitHub repo, which by the way will also be linked in the description of this video, so don't worry. And if we scroll down, you can see these are all the different things that we're able to link our MCP server to, or should I say get the MCP servers for. So you can see there's like thousands here. And you can look for all of these and see sort of what looks good for you. But for this example, we're going to be using Airbnb because, as I said, it doesn't require really any credentials at all. It doesn't require an API key or anything like that. So we're just going to use that for this example. So we find the one we want, Airbnb. Let's hit that. It should open new GitHub repo. And then if we scroll down, you can see these are different tools. So for this, we only have two different tools, and this is what is going to be returned to us when we list the tools on this node here. So what we need to do to get the command and the arguments is we come down to here. You see the command is npx. So all we do is we can copy that, come back over to NAN, paste that into here. And then the arguments, if we come back over, are just going to be these ones here. You have to do this one with the ignore robots.txt. What the ignore robots.txt does, because this one doesn't have it but this one does have it. It basically just means that the AI agent is able to actually execute these tools. If you do this one, the AI agent will be able to list the tools and stuff but won't be able to execute them. So make sure you've got this one. You can see we have 3 different arguments here. We have -y, and then we have this, and then we have the ignore-roblox.txt. And all you do is you just highlight these, copy them, come back over to NAN, paste them in, add a space, and then come back over, copy the next one, add it back in, add a space, and then get the last one, copy that, come back over to N8N. We've already got the space, so just paste it in there. And I've already got this set up obviously for Airbnb, but all you do is you hit save and then that should all connect for you. So now you should see that your Airbnb tool is set up. Make sure to name it Airbnb. And then we have the different operations I just showed you. And a really, really important thing that you need to do at this point is— this looks like it's completely working, and if you just run it through a workflow, it will work. But if you want an AI agent to be able to execute it like we have in this scenario here, I can delete this. Now what you're going to need to do is you're going to need to come over to this original GitHub repo where you install the MCP servers, scroll all the way down to the bottom. So we get to this point, so execute tool operation, and you'll just need to add this environment variable to wherever you're hosting NAN. So for me it's render, and we're going to use this one. So it says if you're using Docker, but it's if you're hosting it yourself. We go with this one, and all we do is we copy this. And then I'm now in Render in my NAN instance, and what I do is I come over to environments. Whatever you're hosting this on, this will have an environments tab with all your different environment variables. Here you can see I've already added this environment that we're talking about, but if you're going to add it, just hit edit, hit add new variable, and then you just paste this in. You can see this automatically does it, so it does the name and then sets the value to true. Even though the actual thing that we are copying, if you look, it's just all one sentence. So if it is like that, it's just all one sentence, and whatever you're hosting on doesn't automatically split it up, what you'll need to do is you'll need to copy this first bit here. So before the equal sign, hit copy, put that in there, and then you'll need to just break it up manually. So the— so then for the value, you'll click true. And if you're hosting it on something that doesn't have these sort of nice input boxes for environments, if it's just sort of like a terminal looking type thing, what you do is you'd copy this and you just replace this equal sign with a colon and a space. So it just means it's the name and then the value separated by a colon. I hope that makes sense to you guys. Like I said, if you do want a full video on how to self-host NAN, please do let me know because I'm not sure how many of you guys are self-hosting NAN or if you're using it through the NAN servers. So please do let me know if you want a video on how to set up self-hosting N8N. So now we have it all set up. This is working. You only need to do these things I've showed you once. So the environment variables, installing that GitHub repo, the only thing that you'll need to do every time is when you set up a new credential. So for example, we've done Airbnb. If you want to do, like I said, something like Gmail or Google Sheets, for example, is you just have to go through that process again of we come back, go into this GitHub repo. Let's say we want to do Airtable. Click on this, takes us to a new GitHub repo, and then we get the schema here that we need to put in. So yeah, that's the only thing you need to do is when you want to add new credentials, you can just go through here, click on the one you want, and then it will show you exactly what you need to do. So now we have two nodes. We have our Airbnb list tools and our Airbnb execute tool. And the way we obviously set this is we set the operation to list tools. And really, really simple, all this tool here is going to do is just going to list the different functions that we can do with Airbnb. So we're going to test this out quickly. Let's open the chat, zoom out so we can see this. And we're going to say something like, what Airbnb tools can I use? So I'm gonna say, what Airbnb tools can I use to the agent? And we should see it use the Airbnb list tools. Yeah, because we've labeled it really clearly that it's listing tools. The agent, by the way, this agent has literally no prompts at all. This is just the default prompt. So I haven't told it how to do any of the stuff it's doing because we've clearly labeled it as list tools. It knows if it wants to list some tools, it's going to have to use that MCP server. So this does take a couple seconds to load, so we'll come— it looks like it's finished just now actually. So as you can see, we got Airbnb search description, and then these are the different parameters. So if we're using a native Airbnb node here, we'd have to use an Airbnb search node on NaN, and then the parameters that we'd have to input would look like this. So location, uh, place ID, check-in, check-out, adults, children, infants, you can read all of them. And then we have a second function, Airbnb listing details, and then the same thing. The parameters are ID, check-in, check-out, adults, children, infants, pets, uh, ignore robots text. So yeah, that tool works absolutely fine. We have got in touch with the Airbnb MCP server to get the different functions that we can use. So now what we're going to do is we're going to have a look at this other tool. So the Airbnb Execute Tool, if we have a look on this, we've obviously added our credentials, the Airbnb tool description set automatically, doesn't really matter. The operation is of course going to be Execute Tool. Then for the tool name, I've already put something in here, but I'm going to show you what I've done. So by default, this will be set to fix and this will be, uh, blank. And usually in here you will drag in your input from other tools and stuff because obviously this is a variable because we're getting the different tools from that step before. We're getting the different tools, we're getting the different names for these tools. We want to input one of those names into this tool because we only want one node here. This is the whole point of it. We only want one node and we can use different tools in this same node. So this tool name is going to have to be a variable depending on what we want to do. So for example, if I wanted to search for some Airbnb listings, and then if I wanted to get some information on a specific Airbnb listing they're going to be two different tool names, and we don't want to use two different nodes because that just defeats the whole point of what we're doing. So this tool name has to be a variable for the different tools that we got from the step before. So what we do in here is we add in this little function. So if we do curly bracket, curly bracket, and then hit a dollar sign, and then from AI, basically what this does is it lets the AI— so the LLM, our agent step before— It lets the agent decide what to put in this input, which is really, really nice. So we'll just give it a description. Let's say, let's call it tool in speech marks. Make sure to do it in speech marks. Hit comma, another set of speech marks, and let's just give it a description. So the tool to be selected for this function. So keeping it nice and simple, the tool to be selected for this function. And then the tool parameters by default, this will look like this, so empty, and it'll probably be fixed like this. Yes, it'll be fixed. What you're going to want to do is you want to change it to expression and then let the model define this parameter. So it's basically the exact same thing as what we're doing before, we're just letting the LLM decide what to put in this input. And this is going to be tool parameters because again, same thing with the title, the tool parameters are going to be different every time because the different functions that we got from the step before are going to have different parameters that we need to send over. So That is the setup for this. It's really, really simple. Obviously, that is the entire point of this, is that it's really, really simple. We only have two nodes. One just lists all the functions that we can use, and the second one just executes the right function for what we're trying to do. So we're going to test this out again, again, just to show you this has literally no prompt at all. We're just doing this just with the default system prompt, which is your helpful assistant. So what we're going to do is we're going to say to it, I I want to find an Airbnb in LA for 3 adults and my dog. So I've said to it, I want to find an Airbnb in LA for 3 adults and my dog. So hopefully it should use— yeah, it's using this tool again to see what functions it actually has and also to get the parameters for that function that we're trying to use. And then it should use this tool after and give us an output. So we'll come back when it's done. Okay, so it's just finished. You can see it used the two different tools. It got the list of functions that it can use, and it knew to use the— let's have a look— so the Airbnb search function, and then it used the Airbnb execute tool node, which is perfect. And it's given us this output here. So we got— how many did we get? We got 5 different ones. So we've got a type, so apartment, the price, the rating, and then free cancellation, cool. Let's click on this. And then yeah, we got linked to this Airbnb. Pretty cool. Come back, you can see we can just click on another one of these, links to Airbnb. So absolutely perfect. I made this in literally 5 minutes. Obviously it was taking me a little bit longer because I'll explain to you guys how to use it, but this literally took me maybe not even 5 minutes to set up. It was so simple, no prompt required at all, literally 2 nodes. And we can do— for this one we can only do 2 different functions, so maybe it's not the best example. But let's say if we use the list tool functions and then it output it to us, 15 different functions that we could use, all we'd have to use still is these two different nodes. So the list tool node and then the execute tool node to use all of those 15 different functions, which is really, really cool. And we have no system prompt as well, because from this we get it, the agent gets a description on what the tool is and then the parameters, which is basically all it needs to be able to execute a tool. So that is it for this video, guys. I hope you did learn something about setting up these MCP servers and using them in your AI agents. Personally, I don't think these are going to be a complete replacement for the traditional tools that we already use, but definitely for certain agents and in certain use cases, they're going to be really, really valuable. I'm probably going to be using at least a couple of them in pretty much all my AI agent builds. They're going to be some cases where I might want specific endpoints and I might want specific functions for my agent that I want to list on there. I don't want it to be able to get all the different functions and then execute a certain tool from that function. If I'm only using one function, for example sending emails, it'll probably be quicker to just put down a send email node and put in the variables that I want to send. But don't get me wrong, this is still really, really cool and something that's really, really useful, especially if you're a beginner and you're just starting out and you want to get these up and running straight away. By the way, if you want to work with me so we can implement some AI agent systems into your business, then I've left a link to my website in the description. You can go ahead and book up a call with me, or you can just fill out the contact form and I'll get back to you. If any of you guys have any video suggestions you'd like to see with NAN, then please do just drop them in the comments or shoot me over an email, and I'll try my best to get around to doing them. But that's it for this one. I'll see you in the next video.
More from Rory

Dynamic Workflows are crazy. This is how to actually use them (beginner's guide)










