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


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.

  1. Open N8N in your browser (usually http://localhost:5678)
  2. Go to Settings → Community Nodes
  3. Search for and install: n8n-nodes-mcp
  4. Set this environment variables using command line before starting N8N:
D:\>set N8N_COMMUNITY_PACKAGES_ALLOW_TOOL_USAGE=true
D:\>n8n start
  1. Restart N8N after installing the package
  2. 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.

  1. Add a Webhook node
  2. Configure it:
    • HTTP Method: POST
    • Path: weather
    • Respond: Using Respond to Webhook Node
  3. 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.

  1. Add an AI Agent node 
  2. Connect Webhook → AI Agent (main connection)
  3. 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.

  1. Add a Google Gemini Chat Model node
  2. Add your Google Gemini API key as a credential
  3. Select model: gemini-2.5-flash
  4. Connect it to the AI Agent's "Chat Model" input (bottom connector)
Note on Rate Limits: The free tier of Google Gemini has limited requests per minute. If you see a "Too Many Requests" error, wait 30 seconds and try again, or upgrade to a paid API tier.

Node 4 — Memory (For Conversation Context)

This lets your agent remember previous messages in a conversation.

  1. Add a Simple Memory node
  2. Configure it:
    • Session ID: Define below
    • Session Key: {{ $json.body.sessionId }}
    • Context Window Length: 5
  3. Connect it to the AI Agent's "Memory" input (bottom connector)
Important: The sessionId comes from your API request body — this is how the agent knows which conversation belongs to which user.

Node 5 — Local Weather MCP Client (The Weather Tool)

This is the MCP tool that fetches real weather data.

  1. Add an MCP Client Tool node 
  2. 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
  3. 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:

  1. You send a POST request with {"message": "What's the weather in Austin?", "sessionId": "test143"}
  2. Webhook node receives it and passes the data along
  3. AI Agent reads your message and checks its memory for any prior conversation context
  4. Gemini Model (the AI brain) understands your question and decides to call the get_weather_by_city tool with city = "Austin"
  5. MCP Client Tool calls your local weather MCP server, which fetches real weather data from the National Weather Service API
  6. The weather data comes back to the AI Agent, which asks Gemini to summarize it in plain English
  7. 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.


Popular posts from this blog

Connecting Claude to Pega Infinity 25.1.3 via MCP — Step-by-Step

Build Pega Applications with GitHub Copilot CLI, Pega Infinity AI Plugin & MCP — Branch-Based Agentic Authoring

itextpdf API to generate PDF doc from an image file using Pega PE