Intelligent news analysis with AI-powered sentiment and summarization
mcp-news-analysis-agent
A comprehensive Model Context Protocol (MCP) implementation for intelligent news analysis, featuring advanced LLM-powered sentiment analysis, AI summarization, and natural language query processing using Mistral AI.
š§ LLM-Powered Architecture
This project leverages Mistral AI for advanced natural language processing capabilities:
- Sentiment Analysis: Uses Mistral's LLM for nuanced sentiment understanding with confidence scoring
- Text Summarization: AI-powered content summarization with customizable length and style
- Intent Detection: Smart query interpretation for natural language interaction
- Structured Outputs: JSON-formatted responses with detailed reasoning and metadata
š Features
- News Fetching: Retrieve real-time news articles from RapidAPI
- Sentiment Analysis: Advanced sentiment analysis using Mistral AI with confidence scoring and detailed reasoning
- Text Summarization: AI-powered summarization using Mistral AI
- Intelligent Agent: Natural language query processing with enhanced intent detection
- MCP Architecture: Fully compliant with Model Context Protocol standards
š Project Structure
MCPDemo/
āāā server/
ā āāā mcp_server.py # MCP server implementation
āāā client/
ā āāā mcp_client.py # Enhanced MCP client with intelligent intent detection and quote parsing
āāā tools/
ā āāā news_tool.py # News fetching from RapidAPI
ā āāā sentiment_tool.py # sentiment analysis tools
ā āāā summary_tool.py # Text summarization tools
ā āāā __init__.py
āāā config/
ā āāā settings.py # Configuration management
ā āāā .env # Environment variables
ā āāā __init__.py
āāā requirements.txt # Python dependencies
āāā README.md # This file
āļø Setup Instructions
1. Environment Setup
First, create a Python virtual environment:
# Navigate to project directory
cd "C:\Users\mayssen\Desktop\mcp project\MCPDemo"
# Create virtual environment
python -m venv .venv
# Activate virtual environment
.\.venv\Scripts\Activate # Windows
# source .venv/bin/activate # macOS/Linux
# Install dependencies
pip install -r requirements.txt
2. API Keys Configuration
Edit the config/.env file and add your API keys:
# News API key from RapidAPI (already provided)
RAPIDAPI_KEY=6d35e9aa82msh4c8550ffb3e08b4p15bf78jsna3f5a47eeb4d
RAPIDAPI_HOST=real-time-news-data.p.rapidapi.com
# Get your Mistral AI API key from https://console.mistral.ai/
MISTRAL_API_KEY=your_mistral_api_key_here
# Optional: Adjust other settings as needed
MAX_NEWS_ARTICLES=10
MAX_SUMMARY_LENGTH=500
LOG_LEVEL=INFO
3. Install Additional Dependencies
Some packages might need special installation:
# Ensure Mistral AI client is properly installed
pip install mistralai
# If you encounter any import errors, install packages individually:
pip install httpx langchain-mistralai fastmcp
š§ Usage
Running the MCP Server
# Make sure you're in the project directory with activated virtual environment
python server/mcp_server.py
Running the Interactive Agent
In a separate terminal:
# Activate the same virtual environment
.\.venv\Scripts\Activate
# Run the client
python client/mcp_client.py
Example Queries
Once the agent is running, try these natural language queries:
- "Get latest news about technology"
- "Analyze sentiment of recent news about climate change"
- "Summarize news about the economy"
- "Show me top 5 news from UK"
- "How do people feel about the latest political news?"
- "Get French news about sports and analyze sentiment"
- "This new AI technology is amazing but also quite expensive" (direct text analysis)
š Available Tools
1. News Tool
- Function:
fetch_news - Purpose: Fetches news articles from RapidAPI
- Parameters: topic, country, language, limit
- Example: Retrieve tech news from US in English
2. Sentiment Analysis Tool
- Function:
analyze_sentiment - Purpose: Analyzes sentiment using advanced Mistral AI LLM with confidence scoring and detailed reasoning
- Parameters: text, analysis_type (simple/detailed)
- Features:
- Structured JSON responses with confidence scores
- Detailed reasoning and emotion detection
- Support for complex, nuanced sentiment analysis
- Direct text analysis through quotes
- Example: Determine sentiment with confidence: "Mixed sentiment (0.80 confidence) - expresses both excitement and concern"
3. Summary Tool (Requires Mistral AI)
- Function:
summarize_text - Purpose: Summarizes text using Mistral AI
- Parameters: text, max_length, summary_type
- Example: Create brief summaries of long articles
4. Combined Workflows
- Function:
analyze_news_sentiment - Purpose: Fetches news and analyzes sentiment in one step
Tools (4)
fetch_newsFetches news articles from RapidAPIanalyze_sentimentAnalyzes sentiment using advanced Mistral AI LLM with confidence scoring and detailed reasoningsummarize_textSummarizes text using Mistral AIanalyze_news_sentimentFetches news and analyzes sentiment in one stepEnvironment Variables
RAPIDAPI_KEYrequiredAPI key for accessing real-time news dataRAPIDAPI_HOSTrequiredHost URL for the news APIMISTRAL_API_KEYrequiredAPI key for Mistral AI servicesConfiguration
{"mcpServers": {"news-analysis": {"command": "python", "args": ["/path/to/mcp_server.py"], "env": {"RAPIDAPI_KEY": "your_key", "MISTRAL_API_KEY": "your_key"}}}}