
Lesson Description
The "MCP Weather API" Lesson is part of the full, Complete Intro to MCP course featured in this preview video. Here's what you'd learn in this lesson:
Brian creates a weather tool for the MCP server that retrieves the current weather conditions from the Open-Meteo API. The response provides Claude Desktop with the temperature, humidity, precipitation information, and wind conditions, allowing Claude to respond to questions about the current weather.
Transcript from the "MCP Weather API" Lesson
[00:00:00]
>> Brian Holt: So we just did addition, which is probably not the most exciting thing. I mean, let's look at what Claude actually responded to me that one time because it was pretty funny. He's like, I don't have access to this, but however, I can easily help you at 2 and 7.
[00:00:14]
The answer is 9, right? It's a little like, I do know how to do this. Why are you subjecting me to this? That's funny, then it gave me advice. And then it's gonna say, you're absolutely right. Just kidding. So let's look at our course website here. We are going to be working with OpenMedio.
[00:00:39]
I actually did talk to their person before. This is like, hey, we're about to hammer your API with a bunch of students doing this all at once. And they're like, we don't care, that's fine. So we're going to be trying this API. I think it's free. You don't even have to sign up, which is really cool.
[00:00:57]
They're just hoping that people start using it professionally. So if you do have weather needs, it seems like it's a pretty cool service. So, yeah, they did graciously agree to let me use their sample API as a sample for this course. It is real information. In the event in the future that this API is not working, I did link there's this repo of a bunch of public APIs that you can try.
[00:01:20]
So building MCP service for this might be something that you might try later. The only reason I did this is because one of my react courses used to use pet adoption as an API, which was really cool because it was real pets that people could adopt and people would actually adopt pets from the course, which I thought was pretty cool.
[00:01:36]
But their API just did not hold up over the years, unfortunately. Anyway, there's a ton of cool stuff in here. There's one for movies, that would be a really cool one to build. I don't know, all sorts of fun stuff, but for now, OpenMedio. Very cool. So you and I could write this if you want to, but as you can see here, this actually really isn't too much interesting information.
[00:02:02]
We're going to install the OpenMedio SDK, we're going to make a weather server, and then we're just going to register this tool and get weather. It's going to get the current weather and then you're going to get a current weather for a given latitude and longitude. This only works for latitude and longitude, but LLMs are really good at getting longitude and latitude for things.
[00:02:23]
If you say give me the weather from Minneapolis, it's like, yeah, I know Minneapolis is this latitude and longitude. And it'll just do it for you, so you don't actually have to geocode or anything like that, the LLM will just figure it out for you or it'll lie to you.
[00:02:35]
You don't know. That's part of the fun you define. Here's the parameters you're gonna get back, the temperature, humidity, apparent temperature is a day, precipitation, rain, and wind speed. And I'm asking for miles per hour is Fahrenheit and inches of rain. And then this is just, you're telling it, this is the output that it's going to get back again.
[00:03:01]
We could just write this ourselves. But nothing in here I just showed you was very interesting, was it? So what we're gonna do here, I'm gonna open my VS Code and we're gonna say npm install openmeteo like this. Okay, so now if I look in my package.json, you can see I have openmeteo here.
[00:03:27]
1.2 is what I'm on at the moment. And I am fully blessing you that if you just want to copy and paste this because again, nothing here we did is quite very different from what we did before. The only really interesting part about this is now this is actually doing something more interesting than adding.
[00:03:45]
It's actually adding real capability to an LLM. Because if you ask an LLM, hey, what's the temperature right now in Minneapolis? It's going to tell you, I don't know, it doesn't have access. That's not part of its training data is current weather. Okay, so I'm just going to create a new file here.
[00:04:04]
I'm gonna save this as weather.js and I'm just gonna paste all of that. Let's look at the Zod types for just a sec because I think that's useful. The Zod type that you just is the number, you describe it, what it is, you say that. You can say that this is optional.
[00:04:25]
However, it's not optional. You can't have just longitude and just say tell me everything around the equator. It doesn't make a lot of sense, but that's how you would do it there. Then here you're just telling the weather data that you're expecting to get back, which is what's going to be given back to the LLM.
[00:04:46]
Let's add this as an MCP server. I'm going to come back to that same Claude desktop here, I'm just going to copy and paste this because it's more or less the same thing. So I'm going to have Weather Server, same node, binary args is just going to be weather js.
[00:05:13]
That's it. We don't have to reinstall the packages, cuz it's in the same directory, right? It's just going to be running a different file. And again, Tome's done the exact same way. So now if we go into Cloud Desktop, quit, restart it. New chat. If we look down here, we should see Weather Server and get weather.
[00:05:39]
And I'm just going to ask do I need a raincoat today in Minneapolis, Minnesota. If you'd asked this yesterday, though, it would have said yes. So you can see here with latitude launches. Someone probably should check that to make sure it's actually true. I have no idea. I'm just trusting it.
[00:06:20]
But it got back this information, which this information looks pretty plausible based on what I can see out the window right now. Okay, pretty cool, right? We've basically added a new capability to our to Claude Desktop that it didn't have before. It didn't have any ability to access that now, actually, I think you can turn on web Search, which I have on right now, and it would have been able to find that, but we'll just kind of like pretend that that's not the case.
[00:06:52]
That used to not be true.
Learn Straight from the Experts Who Shape the Modern Web
- In-depth Courses
- Industry Leading Experts
- Learning Paths
- Live Interactive Workshops