Weather MCP Server

Weather MCP Server

A Model Context Protocol compatible server that provides weather information for any city using Ollama's LLM capabilities through an exposed get-weather tool.

Category
访问服务器

README

🌦️ Weather MCP Server Demo

A Model Context Protocol (MCP) compatible server that provides weather information using Ollama's LLM capabilities. This server exposes a get-weather tool that can be used by MCP clients to retrieve weather information for any city.


🛠 Prerequisites

  • Node.js v18+
  • Ollama installed and running locally
  • Ollama model: llama3 (or configure your preferred model)

🚀 Complete Setup & Installation

✅ Step 1: Clone and Install

git clone https://github.com/codewith1984/weather-mcp-server-typescript.git
cd weather-mcp-server
npm install

⚙️ Step 2: Setup Environment

# Copy environment template
cp .env.example .env

####Edit the .env file to contain: OLLAMA_API_URL=http://localhost:11434/api/generate OLLAMA_MODEL=llama3

🤖 Step 3: Install and Setup Ollama

# Install Ollama (if not already installed)
# Visit https://ollama.com/ for installation instructions

# Start Ollama service
ollama serve

# In another terminal, pull the model
ollama pull llama3

# Verify Ollama is working
curl http://localhost:11434/api/version


Step 4: Test Ollama Connection

# Test if Ollama can generate responses
curl http://localhost:11434/api/generate -d '{
  "model": "llama3",
  "prompt": "Hello world",
  "stream": false
}'

Step 5: Run Diagnostics

# Run diagnostic to check if everything is working
npm run diagnose

🎯 Running the MCP Server

Start the Server

npm start

Expected output:

🚀 MCP Weather Server starting... 📡 Ollama URL: http://localhost:11434/api/generate 🤖 Model: llama3 ✅ MCP Server connected and ready!

🔍 Testing with MCP Inspector

Method 1: CLI Inspector

# Install MCP Inspector globally
npm install -g @modelcontextprotocol/inspector

# Run inspector
mcp-inspector

# Follow the web interface instructions

⚙️ Configuration

Environment Variables (.env file)

OLLAMA_API_URL=http://localhost:11434/api/generate
OLLAMA_MODEL=llama3

Performance Tuning

The server is optimized for quick responses:

15-second timeout for HTTP requests Aggressive Ollama parameters for faster generation Fallback from HTTP API to CLI if needed

##🔧 Troubleshooting

Quick Diagnosis

# Run the diagnostic script
npm run diagnose

Common Issues & Solutions

Issue: "Request timed out" errors

# Check if Ollama is running
ps aux | grep ollama

# Start Ollama if not running
ollama serve

# Check if model is available
ollama list | grep llama3

# If model not found, pull it
ollama pull llama3

Issue: "Request timed out" errors

# Check if Ollama is running
ps aux | grep ollama

# Start Ollama if not running
ollama serve

# Check if model is available
ollama list | grep llama3

# If model not found, pull it
ollama pull llama3

Issue: "Model not found" errors

# List available models
ollama list

# Pull the required model
ollama pull llama3

# Or try a smaller model for faster responses
ollama pull llama3:8b


Issue: Connection errors

# Verify Ollama is accessible
curl http://localhost:11434/api/version

# Check if port 11434 is open
netstat -an | grep 11434

# Restart Ollama service
pkill ollama
ollama serve

Issue: MCP Inspector connection fails

# Make sure your server is running
npm start

# Check the working directory path is correct
pwd

# Verify tsx is available
npm list tsx

Performance Tips

# Use a smaller model for faster responses
ollama pull llama3:8b

# Update .env to use the smaller model
echo "OLLAMA_MODEL=llama3:8b" >> .env

# Monitor system resources
top -p $(pgrep ollama)

📁 Project Structure

weather-mcp-server/ ├── .env # Environment configuration ├── .env.example # Environment template ├── .gitignore # Git ignore rules ├── main.ts # MCP server implementation ├── ollamaClient.ts # Ollama API client ├── diagnose.ts # Diagnostic tool ├── package.json # Dependencies and scripts ├── tsconfig.json # TypeScript configuration └── README.md # This file

✅ Success Checklist

Complete this checklist to ensure everything is working:

Node.js v18+ installed Ollama installed and running (ollama serve) Model downloaded (ollama pull llama3) Project dependencies installed (npm install) Environment configured (.env file exists) Diagnostic passes (npm run diagnose) MCP server starts successfully (npm start) MCP Inspector connects successfully Weather tool responds to test quer

🚀 Quick Start Commands

# Complete setup in one go
git clone https://github.com/your-username/weather-mcp-server.git
cd weather-mcp-server
npm install
cp .env.example .env
ollama serve &
ollama pull llama3
npm run diagnose
npm start

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature-name
  3. Make your changes
  4. Test with MCP Inspector
  5. Submit a pull request

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选