Exemplo de Servidor MCP
About
Modelo de Servidor MCP baseado na documentação oficial
Details
- Author
- gabrielfroes
- GitHub stars
- 81
- Downloads
- 182
- Categories
- Other
Jump to
- Two weather tools: get-alerts and get-forecast
- Input validation using Zod schemas
- Integration with the National Weather Service API
- Layered architecture inspired by Domain-Driven Design (DDD)
- Communication via stdio using the MCP SDK
- Written in TypeScript with compiled JavaScript output
Setting up with Highlight
This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:
- Download and install Highlight from highlightai.com/download
- Navigate to the plugins tab and select "Add Custom Plugin"
-
Configure the plugin with the settings below
Plugin Name
Exemplo de Servidor MCPCommand (node, npx, python, etc.)Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.
- Enable "Start Automatically" if you want the plugin to start when Highlight launches
From the repository
Install by cloning the repository, running npm install and npm run build. After building, start the server with node build/main.js or, if linked as a binary, with weather. The server listens on stdio and accepts MCP requests.
Claude Desktop / Cursor
Paste into your MCP client config file to install this server.
{
"mcpServers": {
"exemplo de servidor mcp": {
"mcp-server-sample": {
"command": "node",
"args": [
"build/main.js"
]
}
}
}
}
McpServers
{
"mcp-server-sample": {
"command": "node",
"args": [
"build/main.js"
]
}
}
Exemplo de Servidor MCP
Criado para fins educacionais no canal Código Fonte TV, 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.
Contribuição
Pull requests são bem-vindos! Sinta-se à vontade para abrir issues e discutir melhorias.
Código Fonte TV
Para mais detalhes sobre a implementação, assista ao vídeo no canal Código Fonte TV.
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



