News Analysis Agent MCP Server
Provides tools for fetching real-time news and performing AI-powered sentiment analysis and summarization using Mistral AI. It enables users to analyze news trends and extract structured insights through natural language queries.
README
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
- Parameters: topic, country, language, limit
- Example: Get tech news and determine public sentiment
š Integration with Claude Desktop
To use this server with Claude Desktop, add this to your claude_desktop_config.json:
{
"mcpServers": {
"news-analysis": {
"command": "python",
"args": ["C:/Users/mayssen/Desktop/mcp project/MCPDemo/server/mcp_server.py"],
"env": {
"PYTHONPATH": "C:/Users/mayssen/Desktop/mcp project/MCPDemo"
}
}
}
}
šÆ Advanced Features
Intelligent Text Detection
The client automatically detects quoted text in user queries and analyzes it directly:
- Input:
"This product is amazing but expensive" - Result: Direct sentiment analysis of the quoted text
Structured LLM Responses
All LLM operations return structured JSON with:
- Classification: Primary sentiment/summary category
- Confidence: Numerical confidence score (0.0-1.0)
- Reasoning: Detailed explanation of the analysis
- Emotions: Additional emotional context (for detailed analysis)
š Troubleshooting
Common Issues
- Import Errors: Make sure all dependencies are installed and virtual environment is activated
- Mistral API Key Errors: Verify your Mistral AI API key is correctly set in
.envfile - RapidAPI Errors: Check if the provided RapidAPI key is still valid
- MCP Connection Issues: Ensure both server and client are using the same transport method
- LLM Response Issues: Verify Mistral AI API connectivity and sufficient API credits
Checking Logs
The system uses Python logging. Check console output for detailed error messages. You can adjust log level in .env:
LOG_LEVEL=DEBUG # For more detailed logs
Testing Individual Components
Test each tool separately:
# Test LLM-powered sentiment analysis
from tools.sentiment_tool import SentimentTool
import asyncio
async def test_sentiment():
tool = SentimentTool()
result = await tool.analyze_sentiment(
"This new AI technology is amazing but also quite expensive",
"detailed"
)
print(result)
asyncio.run(test_sentiment())
š Dependencies
Core MCP Dependencies
mcp>=1.2.0- Model Context Protocol implementationhttpx>=0.25.0- HTTP client for API requestspython-dotenv>=1.0.0- Environment variable management
AI/ML Dependencies
mistralai>=1.0.0- Mistral AI client for both summarization and sentiment analysislangchain-mistralai>=0.1.0- LangChain integration for enhanced LLM capabilitiesfastmcp>=2.11.0- FastMCP framework for efficient MCP implementation
Utility Dependencies
requests>=2.31.0- HTTP requestspydantic>=2.0.0- Data validationrich>=13.0.0- Pretty terminal output
š¤ Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
š License
This project is open source. Feel free to modify and distribute according to your needs.
š Support
If you encounter issues:
- Check the troubleshooting section
- Review logs for error messages
- Verify API keys and configuration
- Test individual components
For additional help, review the MCP documentation at Model Context Protocol.
76537c4 (initial commit)
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.