RatnadeepSimhadri/weather-mcp-server
If you are the rightful owner of weather-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
This document provides a structured summary of a Model Context Protocol (MCP) server designed to deliver weather information.
weather-mcp-server
MCP Weather Server Explanation
This file implements a Model Context Protocol (MCP) server that provides weather information tools. MCP enables AI models to interact with external tools in a structured way.
Overview The server exposes two weather tools:
get-alerts
: Gets weather alerts for a specific US stateget-forecast
: Gets weather forecast for a specific location by coordinates It uses the National Weather Service (NWS) API to fetch real weather data.
How MCP Clients Understand Tool Inputs
The key to how MCP clients understand tool inputs lies in how tools are registered:
server.tool(
"get-forecast", // Tool name
"Get weather forecast for a location", // Tool description
{ // Input schema
latitude: z.number().min(-90).max(90).describe("Latitude of the location"),
longitude: z.number().min(-180).max(180).describe("Longitude of the location"),
},
async ({ latitude, longitude }) => { // Handler function
// Implementation
}
);
Here's how clients understand the inputs:
- Schema Definition: The third parameter uses Zod (z) to define the expected inputs and their constraints:
- Input parameter names (e.g., latitude, longitude)
- Data types (z.number(), z.string())
- Validation rules (min(-90), max(90), length(2))
- Descriptions (describe("Latitude of the location"))
- Client Discovery: When an MCP client connects to this server:
- It receives metadata about available tools
- For each tool, it gets the name, description, and input schema
- The client can use this information to validate inputs before sending them
- Communication: The StdioServerTransport handles the serialization and communication of this schema information between the server and client.
This schema-based approach ensures that clients know exactly what parameters each tool expects, their types, constraints, and what they represent.