NWS Weather MCP Server

$git clone <REPOSITÓRIO_URL> && cd mcp-server-sample && npm install && npm run build
README.md

Provides weather alerts for US states and geographic forecasts via NWS API.

Exemplo de Servidor MCP

Este projeto demonstra como construir um servidor MCP com integração a APIs externas e validação de dados.

Este repositório contém um exemplo de implementação de um servidor MCP (Model Context Protocol) em Node.js/TypeScript, que fornece duas ferramentas para obter informações meteorológicas usando a API do National Weather Service (NWS) dos EUA.

Funcionalidades

  • get-alerts: Retorna alertas meteorológicos ativos para um estado (código de duas letras, ex: CA, NY).
  • get-forecast: Retorna a previsão do tempo para coordenadas geográficas (latitude, longitude).
  • Validação de entrada usando Zod.
  • Integração com a API do NWS usando fetch (camada de infraestrutura).
  • Comunicação via stdio usando o protocolo MCP (@modelcontextprotocol/sdk).

Arquitetura

O projeto segue uma arquitetura em camadas inspirada em padrões de Domain-Driven Design (DDD):

  • Domain (src/domain): Definição de interfaces e tipos que representam as estruturas de dados (ex: AlertFeature, ForecastPeriod, AlertsResponse).

  • Infrastructure (src/infrastructure): Implementação de serviços externos, como o NWSApiService, responsável por realizar as chamadas HTTP à API do NWS.

  • Application (src/application): Contém a lógica de negócio no WeatherService, que processa e formata os dados vindos da infraestrutura.

  • Interface (src/interface): Inclui controladores (WeatherToolsController) que registram as ferramentas no servidor MCP, definem schemas de validação e retornam os resultados.

  • Entry Point (src/main.ts): Inicializa o McpServer, configura o transporte (StdioServerTransport), instancia serviços e controladores, e inicia escuta em stdio.

A estrutura de pastas é a seguinte:

src/
├── domain/
│   └── models/           # Interfaces de domínio
├── infrastructure/
│   └── services/         # Implementações da API externa (NWS)
├── application/
│   └── services/         # Lógica de negócio e formatação de dados
├── interface/
│   └── controllers/      # Registro das ferramentas MCP e validação
└── main.ts               # Ponto de entrada do servidor
build/                     # Código JavaScript compilado

Instalação

git clone <REPOSITÓRIO_URL>
cd mcp-server-sample
npm install
npm run build

Uso

Após o build, você pode executar o servidor diretamente:

node build/main.js

Ou, se registrado como binário (weather):

npm link
weather

O servidor iniciará na saída padrão (stdio) e aguardará requisições MCP.

Consumir com clients IA (Claude Desktop)

Em Arquivo > Configurações > Desenvolvedor

Editar configuração

claude_desktop_config.json

{
    "mcpServers": {
        "weather": {
            "command": "node",
            "args": ["C:\\Fontes\\mcp-server-sample\\build\\main.js"]
        }
    }
}

Tools (2)

get-alertsRetorna alertas meteorológicos ativos para um estado (código de duas letras, ex: CA, NY).
get-forecastRetorna a previsão do tempo para coordenadas geográficas (latitude, longitude).

Configuration

claude_desktop_config.json
{
    "mcpServers": {
        "weather": {
            "command": "node",
            "args": ["C:\\Fontes\\mcp-server-sample\\build\\main.js"]
        }
    }
}

Try it

Check for active weather alerts in California.
What is the weather forecast for the coordinates 34.0522, -118.2437?
Are there any weather warnings for New York right now?
Get the current forecast for latitude 40.7128 and longitude -74.0060.

Frequently Asked Questions

What are the key features of NWS Weather MCP Server?

Active weather alerts retrieval by US state code.. Geographic coordinate-based weather forecasting.. Zod-based input validation for reliable data handling.. Layered architecture following Domain-Driven Design (DDD) principles.. Standard I/O (stdio) communication protocol for MCP clients..

What can I use NWS Weather MCP Server for?

Monitoring severe weather conditions in specific US states.. Integrating real-time meteorological data into AI-assisted workflows.. Retrieving localized forecasts for specific GPS coordinates.. Building weather-aware automation scripts using the MCP protocol..

How do I install NWS Weather MCP Server?

Install NWS Weather MCP Server by running: git clone <REPOSITÓRIO_URL> && cd mcp-server-sample && npm install && npm run build

What MCP clients work with NWS Weather MCP Server?

NWS Weather MCP Server works with any MCP-compatible client including Claude Desktop, Claude Code, Cursor, and other editors with MCP support.

Use NWS Weather MCP Server with Conare

Manage MCP servers visually, upload persistent context, and never start from zero with Claude Code & Codex.

Try Free