Build a Weather AI Agent with N8N and MCP Server — A Step-by-Step Guide for Beginners
This guide walks you through building a real, working weather assistant using N8N (a workflow automation tool) and an MCP server (a way to give AI agents special tools/skills). By the end, you'll have a working chatbot you can talk to via a simple API call, and it will tell you the weather for any US city.
No prior experience required. Let's go.
What Are We Building?
A weather AI agent that:
- Accepts a question like "What is the weather like in Austin, TX?" via an API call (webhook)
- Uses an AI model (Google Gemini) to understand the question
- Calls a weather tool to fetch real weather data
- Returns a human-readable weather summary
Here's what the final workflow looks like in N8N:
What You Need Before Starting
- N8N Community Edition installed locally (https://n8n.io)
- Node.js installed on your machine (https://nodejs.org)
- uv package manager installed (https://github.com/astral-sh/uv)
- A Google Gemini API key (free at https://aistudio.google.com/app/apikey)
- A local Weather MCP server running (we'll cover this below)
- Basic comfort with running commands in a terminal
Part 1 — Setting Up the Weather MCP Server
An MCP (Model Context Protocol) server is essentially a plugin that gives your AI agent special abilities — in this case, the ability to fetch real weather data.
Step 1 — Install the Weather MCP Server
Make sure you have uv installed. Then create a folder for your weather server and install it:
C:\>mkdir C:\Users\Admin\weather
C:\>cd C:\Users\Admin\weather
C:\Users\Admin\weather\>uv init
C:\Users\Admin\weather\>uv add mcp-server-weather
Step 2 — Run the Server
Start the MCP server using Python script and is opensource to download from google:
C:\Users\Admin\weather\>uv run weather.py
You should see it running. Keep this terminal open — the server must stay running while you use N8N.
In the MCP server manager, your weather server config should look like this (screenshot given below):
| Setting | Value |
|---|---|
| Command | C:\Users\Admin\.local\bin\uv.exe |
| Arguments | --directory C:\Users\Admin\weather run weather.py |
| Status | Running ✅ |
Step 3 — Verify the Tool Name
Your weather MCP server exposes a tool called get_weather_by_city — this is what the AI agent will call when someone asks about the weather. It accepts a single parameter: city (the city name as a string).
Note: Step 2 is completely optional since we can use the Weather MCP server configuration details in n8n community edition settings (See Part 2).
Part 2 — Setting Up N8N
Step 1 — Enable and add the Community Nodes
N8N needs a special community package to talk to MCP servers.
- Open N8N in your browser (usually
http://localhost:5678) - Go to Settings → Community Nodes
- Search for and install:
n8n-nodes-mcp - Set this environment variables using command line before starting N8N:
D:\>set N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=trueD:\>n8n start
- Restart N8N after installing the package
- Follow the below screenshots to setup the MCP node from n8n community edition's Settings section -> Community nodes before adding the MCP node in the workflow
Part 3 — Building the Workflow
Create a new workflow in N8N. You'll add 5 nodes total.
Node 1 — Webhook (The Entry Point)
This is how your agent receives questions from the outside world.
- Add a Webhook node
- Configure it:
- HTTP Method:
POST - Path:
weather - Respond:
Using Respond to Webhook Node
- HTTP Method:
- Your webhook URL will be: http://localhost:5678/webhook-test/2dfe9033-459f-421d-9fde-5e626466afe3
Node 2 — AI Agent (The Brain)
This is the heart of the workflow — the AI that decides what to do.
- Add an AI Agent node
- Connect Webhook → AI Agent (main connection)
- Configure it:
- Source for Prompt: Define below
- Prompt:
{{ $json.body.message }} - System Message (under Options):
You are a weather assistant. Use the get_weather_by_city tool
to answer weather questions. Pass the city name as the parameter.
Always provide a friendly, readable weather summary.
Node 3 — Google Gemini Chat Model (The AI Engine)
This is the actual AI brain powering the agent.
- Add a Google Gemini Chat Model node
- Add your Google Gemini API key as a credential
- Select model:
gemini-2.5-flash - Connect it to the AI Agent's "Chat Model" input (bottom connector)
Node 4 — Memory (For Conversation Context)
This lets your agent remember previous messages in a conversation.
- Add a Simple Memory node
- Configure it:
- Session ID: Define below
- Session Key:
{{ $json.body.sessionId }} - Context Window Length:
5
- Connect it to the AI Agent's "Memory" input (bottom connector)
Node 5 — Local Weather MCP Client (The Weather Tool)
This is the MCP tool that fetches real weather data.
- Add an MCP Client Tool node
- Create a new credential:
- Type: MCP Client (STDIO)
- Command:
C:\Users\Admin\.local\bin\uv.exe - Arguments:
--directory C:\Users\Admin\weather run weather.py
- Configure the node:
- Operation: Execute Tool
- Tool Name:
get_weather_by_city - Tool Parameters (switch to Expression mode):
{ "city": "{{ $fromAI('city', 'City name', 'string') }}"}
Part 4 — Connecting Everything
Here's the complete connection map:
| From | To | Connection Type |
|---|---|---|
| Webhook | AI Agent | Main (top) |
| Gemini Model | AI Agent | ai_languageModel (bottom) |
| Memory | AI Agent | ai_memory (bottom) |
| MCP Client Tool |
AI Agent | ai_tool (bottom) |
The bottom connectors on the AI Agent node (Chat Model, Memory, Tool) are special sub-connectors — drag from the small diamond shapes beneath the node.
Part 5 — Testing the Workflow
Step 1 — Activate the Workflow
Toggle the Active switch in the top-right corner of the N8N editor. This registers the webhook URL permanently.
Important: While building, you can use "Execute workflow" for testing. But for real API calls via curl, the workflow must be Active.
Step 2 — Send a Test Request
Open your Windows Command Prompt and run:
D:\>curl -X POST http://localhost:5678/webhook/weather -H "Content-Type: application/json" -d "{\"message\": \"What is the weather like in Austin, TX?\", \"sessionId\": \"test143\"}"
You should get back a response like:
{
"reply": "The weather in Austin, TX today is warm and partly cloudy.
Current temperature is around 86°F (30°C) with a high of
91°F and a low of 73°F. Winds are from the south at
15-20 mph. There is a slight chance of thunderstorms
this evening."
}
Step 3 — Test Conversation Memory
Send a follow-up using the same sessionId:
D:\>curl -X POST http://localhost:5678/webhook-test/2dfe9033-459f-421d-9fde-5e626466afe3 -H "Content-Type: application/json" -d "{\"message\": \"What's the weather in Austin, TX?\", \"sessionId\": \"test143\"}"
The agent will remember you were asking about Austin and give you the forecast.How It All Works Together?
Here's the full flow when you send a request:
- You send a POST request with
{"message": "What's the weather in Austin?", "sessionId": "test143"}- Webhook node receives it and passes the data along
- AI Agent reads your message and checks its memory for any prior conversation context
- Gemini Model (the AI brain) understands your question and decides to call the
get_weather_by_citytool withcity = "Austin"- MCP Client Tool calls your local weather MCP server, which fetches real weather data from the National Weather Service API
- The weather data comes back to the AI Agent, which asks Gemini to summarize it in plain English
- The final answer is returned as a JSON response
Part 6 — Troubleshooting Common Errors
"The requested webhook is not registered"
The workflow is not active. Toggle the Active switch in the top-right corner.
"No prompt specified"
The AI Agent's Prompt field is set to chatInput (default for Chat Trigger). Change it to {{ $json.body.message }} since you're using a Webhook, not a Chat Trigger.
"Too Many Requests" from Gemini
You've hit the free API rate limit. Wait 30 seconds, or switch to a different Gemini model like gemini-1.5-flash.
"City '' not found"
The $fromAI() expression in Tool Parameters isn't being evaluated — the field is likely in "Fixed" mode. Switch it to "Expression" mode.
MCP Tool returns empty results
Never test MCP tool nodes in isolation using "Execute step" — $fromAI() can't resolve without the Agent's context. Always test by running the full workflow via the webhook.
"No session ID found" in Memory node
You're using a Webhook (not Chat Trigger), so the session ID doesn't come automatically. Make sure your Session ID is set to "Define below" with {{ $json.body.sessionId }}, and always include sessionId in your request body.
Note: As I use all the free trials, I have faced the above issues and errs while working on this implementation.
Key Concepts to Remember
| Concept | What It Means |
|---|---|
| MCP Server | A local program that gives the AI agent special tools/abilities |
| STDIO | The MCP server communicates via standard input/output (command-line process) |
| $fromAI() | Lets the AI dynamically fill in tool parameters based on the user's question |
| sessionId | Identifies a conversation so the memory node knows which history to load |
| Tool input | The special bottom connector on AI Agent nodes for attaching tools |
| Active workflow | Required for production webhook URLs to work (vs temporary test URLs) |
What's Next?
Now that you have a working weather agent, you can extend it:
- Add more MCP servers — connect to GitHub, Linear, Gmail, or any other MCP-compatible service
- Add more tools — attach multiple MCP Client Tool nodes to the AI Agent for different capabilities
- Use a database for memory — replace Simple Memory with a Redis or Postgres memory node for persistent, scalable conversation history
- Build a front-end — connect the webhook to a chat UI so users can interact via a browser instead of curl
- Deploy to production — host N8N on a cloud server and expose the webhook publicly
The pattern you've learned here — Webhook → AI Agent → MCP Tool — is the foundation for building any kind of AI-powered automation with N8N.