MCP Weather & News Assistant

MCP Weather & News Assistant

An MCP server that provides real-time weather data and latest news headlines via custom tools.

Category
访问服务器

README

MCP Weather & News Assistant

An AI assistant project built with the Model Context Protocol (MCP) that connects an LLM to real-world data sources via custom MCP tools.
It provides real-time weather information and latest news headlines by allowing the model to call external APIs through an MCP server.


Features

  • Real-time Weather Data: Get current weather conditions (temperature, humidity, wind speed, description) for any city
  • Latest News Articles: Fetch top 5 news articles by topic using NewsAPI
  • MCP Protocol: Standards-based integration with any MCP-compatible client using FastMCP
  • Two Tools: weather(city) and news(topic) tools exposed via MCP
  • Secure: API keys stored in environment variables using python-dotenv

Prerequisites

Before deploying this MCP server, ensure you have:


Installation

1. Clone the Repository

git clone https://github.com/ZiliOussema/mcp_weather_and_news_assistant.git
cd mcp_weather_and_news_assistant

2. Create Virtual Environment

# Windows
python -m venv venv
venv\Scripts\activate

# macOS/Linux
python3 -m venv venv
source venv/bin/activate

3. Install Dependencies

pip install -r requirements.txt

4. Set Up Environment Variables

Create a .env file in the project root (you can copy from .env.sample):

# Copy the sample file
cp .env.sample .env

# Then edit .env and add your API keys

Your .env file should contain:

OPENWEATHER_API_KEY=your_openweather_api_key_here
NEWS_API_KEY=your_newsapi_key_here

IMPORTANT: Never commit your .env file to version control!


Finding Your Project Path

Before configuring any MCP client, you need to know your project's full path.

Windows

Open Command Prompt in your project folder and run:

cd

Or use PowerShell:

pwd

macOS/Linux

Open Terminal in your project folder and run:

pwd

Deployment

1. Claude Desktop

Windows

Step 1: Locate the Claude Desktop configuration file

Path: %APPDATA%\Claude\claude_desktop_config.json

Step 2: Open claude_desktop_config.json and add your MCP server:

{
  "mcpServers": {
    "weather-news": {
      "command": "C:\\path\\to\\your\\project\\venv\\Scripts\\python.exe",
      "args": [
        "src/server.py"
      ],
      "cwd": "C:\\path\\to\\your\\project"
    }
  }
}

Important Notes:

  • Replace C:\\path\\to\\your\\project\\ with your actual project path
  • Use double backslashes (\\) in Windows paths
  • Paths must be absolute (full path from C:)

Step 3: Verify the paths exist

"C:\path\to\your\project\mcp_weather_and_news_assistant\venv\Scripts\python.exe" --version

Step 4: Restart Claude Desktop

  • Completely close Claude Desktop
  • Check Task Manager to ensure no Claude processes are running
  • Reopen Claude Desktop

Step 5: Verify the server is loaded

  • Look for a plug icon or "MCP" section in Claude Desktop
  • You should see weather and news tools available
  • Try asking: "What's the weather in Paris?"

macOS

Step 1: Locate the configuration file

~/Library/Application Support/Claude/claude_desktop_config.json

Step 2: Edit the configuration:

nano ~/Library/Application\ Support/Claude/claude_desktop_config.json

Add:

{
  "mcpServers": {
    "weather-news": {
      "command": "/Users/YOUR_USERNAME/mcp_weather_and_news_assistant/venv/bin/python",
      "args": [
        "src/server.py"
      ],
      "cwd": "/Users/YOUR_USERNAME/mcp_weather_and_news_assistant"
    }
  }
}

Step 3: Restart Claude Desktop

killall Claude

Then reopen Claude Desktop from Applications.


Linux

Step 1: Configuration location

~/.config/Claude/claude_desktop_config.json

Step 2: Edit configuration:

nano ~/.config/Claude/claude_desktop_config.json

Add:

{
  "mcpServers": {
    "weather-news": {
      "command": "/home/YOUR_USERNAME/mcp_weather_and_news_assistant/venv/bin/python",
      "args": [
        "src/server.py"
      ],
      "cwd": "/home/YOUR_USERNAME/mcp_weather_and_news_assistant"
    }
  }
}

Step 3: Restart Claude Desktop

pkill claude

2. Continue (VS Code)

Step 1: Install Continue extension

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "Continue"
  4. Click Install

Step 2: Open Continue configuration

  • Press Ctrl+Shift+P (Windows/Linux) or Cmd+Shift+P (macOS)
  • Type: Continue: Open config.json
  • Press Enter

Step 3: Add MCP server to Continue config

For Windows:

mcpServers:
  weather-news:
    command: C:\path\to\your\project\venv\Scripts\python.exe
    args:
      - src/server.py
    cwd: C:\path\to\your\project

For macOS/Linux:

mcpServers:
  weather-news:
    command: /Users/YOUR_USERNAME/mcp_weather_and_news_assistant/venv/bin/python
    args:
      - src/server.py
    cwd: /Users/YOUR_USERNAME/mcp_weather_and_news_assistant

Step 4: Reload VS Code

  • Press Ctrl+Shift+P / Cmd+Shift+P
  • Type: Developer: Reload Window
  • Press Enter

Step 5: Test in Continue

Open Continue sidebar and ask:

What's the weather in New York?

3. Cline

Step 1: Install Cline

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X)
  3. Search for "Cline"
  4. Click Install

Step 2: Configure Cline MCP settings

  • Click the Cline icon in VS Code sidebar
  • Go to Cline Settings (gear icon)
  • Find "MCP Servers" section

Step 3: Add configuration

Click "Add MCP Server" and fill in:

  • Name: weather-news
  • Command: Path to your Python executable
  • Args: Path to your server.py

Or edit settings.json:

{
  "cline.mcpServers": [
    {
      "name": "weather-news",
      "command": "C:\\path\\to\\your\\project\\venv\\Scripts\\python.exe",
      "args": [
        "src/server.py"
      ],
      "cwd": "C:\\path\\to\\your\\project"
    }
  ]
}

Step 4: Restart Cline or reload VS Code


Usage Examples

Weather Queries

User: What's the weather like in Tokyo?

Response:

The current weather in Tokyo is 18°C with clear skies. 
Humidity is at 65% with a light breeze of 5 m/s.

News Queries

User: Show me the latest technology news

Response:

Here are the top 5 tech headlines:
1. New AI breakthrough announced by researchers
   Source: TechCrunch | Published: 2026-02-03
2. Tech company releases innovative product
   Source: The Verge | Published: 2026-02-03
...

Combined Queries

User: What's the weather in London and any technology news?

Troubleshooting

Server Not Loading in Claude Desktop

  1. Check configuration file location

    # Windows
    echo %APPDATA%\Claude\claude_desktop_config.json
    
    # macOS
    echo ~/Library/Application\ Support/Claude/claude_desktop_config.json
    
    # Linux
    echo ~/.config/Claude/claude_desktop_config.json
    
  2. Verify JSON syntax at jsonlint.com

  3. Check Python path

    # Windows
    "C:\path\to\your\project\venv\Scripts\python.exe" --version
    
    # macOS/Linux
    /path/to/your/project/venv/bin/python --version
    
  4. View Claude logs

    • Windows: %APPDATA%\Claude\logs\
    • macOS: ~/Library/Logs/Claude/
    • Linux: ~/.local/state/Claude/logs/

"Module not found" Error

  1. Activate virtual environment and reinstall

    # Windows
    venv\Scripts\activate
    pip install -r requirements.txt
    
    # macOS/Linux
    source venv/bin/activate
    pip install -r requirements.txt
    
  2. Verify packages are installed

    pip list
    

API Errors (401, 403, 404)

  1. Verify API keys in .env file

    cat .env
    
  2. Test API keys manually

    # Test OpenWeatherMap
    curl "https://api.openweathermap.org/data/2.5/weather?q=Paris&appid=YOUR_KEY&units=metric"
    
    # Test NewsAPI
    curl "https://newsapi.org/v2/everything?q=technology&apiKey=YOUR_KEY&pageSize=5"
    
  3. Check API key limits

    • OpenWeatherMap: 60 calls/minute
    • NewsAPI: 100 requests/day (free tier)

Tools Not Appearing in Continue/Cline

  1. Reload VS Code: Ctrl+Shift+P → "Developer: Reload Window"

  2. Check logs in VS Code Output panel

  3. Test server manually

    python src/server.py
    

"Permission Denied" on macOS/Linux

chmod +x server.py

Project Structure

mcp_weather_and_news_assistant/
├── src/
│   ├── __pycache__/           
│   ├── tools/
│   │   ├── __pycache__/      
│   │   ├── __init__.py
│   │   ├── news.py            # News tool implementation
│   │   └── weather.py         # Weather tool implementation
│   └── server.py              # Main MCP server entry point
├── test/
│   ├── interactive_test.py    # Interactive testing script
│   └── test_tools.py          # Unit tests for tools
├── venv/                      # Virtual environment 
├── .env                       # Environment variables
├── .env.sample                # Sample environment file
├── .gitignore
├── requirements.txt           # Python dependencies
└── README.md                  # Documentation

Testing the Server

Manual Testing

# Activate environment
source venv/bin/activate  # or venv\Scripts\activate on Windows

# Run server
python src/server.py

Interactive Testing

The project includes an interactive test script to verify your API keys and tools:

# Activate environment
source venv/bin/activate  # or venv\Scripts\activate on Windows

# Run interactive test
python test/interactive_test.py

This will test both the weather and news tools with sample queries.

Unit Tests

Run the unit tests to verify tool functionality:

# Run all tests
python -m pytest test/

# Run specific test file
python test/test_tools.py

Security Best Practices

  1. Never commit API keys - Always use .env file
  2. Add .env to .gitignore
  3. Rotate keys regularly
  4. Use read-only keys when possible

MCP Weather & News Assistant - A portfolio project demonstrating Model Context Protocol integration

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选