deepansh-saxena/Stocks-Analyzer-AI
If you are the rightful owner of Stocks-Analyzer-AI and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Stock Advisor Agent MCP is a sophisticated stock market analysis assistant that combines real-time stock data, news analysis, and AI-powered recommendations.
get_stock_data
Fetches stock data from Zacks quote feed.
get_news
Gets news articles from NewsAPI.
Stock Advisor Agent MCP
A sophisticated stock market analysis assistant that combines real-time stock data, news analysis, and AI-powered recommendations.
Features
- Real-time Stock Data: Fetches stock information from Zacks quote feed
- News Analysis: Gets latest news headlines using NewsAPI
- AI-Powered Analysis: Uses GPT-4 to analyze stock data and news sentiment
- Web Interface: Modern React frontend with markdown formatting
- Contextual Chat: Maintains conversation history for follow-up questions
- MCP Integration: Uses Model Context Protocol for tool integration
Architecture
Frontend (React) ā API Server (Flask) ā MCP Client ā Stocks Server (MCP Tools)
Setup Instructions
1. Create Virtual Environment (Recommended)
# Create virtual environment
python -m venv venv
# Activate virtual environment
# On macOS/Linux:
source venv/bin/activate
# On Windows:
# venv\Scripts\activate
2. Install Dependencies
# Install Python dependencies
pip install mcp langchain-mcp-adapters langgraph openai flask flask-cors requests newsapi-python
# Install frontend dependencies
cd frontend
npm install
3. Configure API Keys
Update the API keys in the following files:
api_server.py
: Update your OpenAI API key (replace#OPENAI_API_KEY
with your actual key)stocks_server.py
: Update your NewsAPI key (replace"Api Key Here"
with your actual key)
4. Start the Servers
# Terminal 1: Start API server (this will automatically start the stocks server as needed)
python api_server.py
# Terminal 2: Start frontend
cd frontend
npm run dev
Note: You do NOT need to manually start stocks_server.py
. It is automatically launched as a subprocess by the API server when needed.
5. Access the Application
- Frontend: http://localhost:5173 (or the port shown by Vite)
- API Server: http://localhost:5050
- Health Check: http://localhost:5050/api/health
Usage
- Open the frontend in your browser
- Ask questions about stocks, for example:
- "How is Microsoft looking today?"
- "Should I buy Apple stock?"
- "Get news about Tesla and analyze the stock"
- "What's the latest on NVIDIA?"
The AI agent will:
- Fetch real-time stock data from Zacks
- Get relevant news headlines from NewsAPI
- Analyze the information using GPT-4
- Provide a BUY/HOLD/SELL recommendation with detailed reasoning
- Format responses with markdown tables, bold text, and clear structure
API Endpoints
POST /api/analyze
: Analyze stock based on user messageGET /api/health
: Health check endpoint
Tools Available
get_stock_data(ticker)
: Fetches stock data from Zacks quote feedget_news(keyword, category, language, country)
: Gets news articles from NewsAPI
Features
Contextual Chat
- Maintains conversation history per session
- Follow-up questions reference previous analysis
- Avoids repeating information unnecessarily
Rich Formatting
- Markdown tables for key metrics
- Bold text for important numbers and headers
- Clickable news links
- Blockquotes for recommendations
- Professional but conversational tone
Real-time Analysis
- Current stock prices and performance
- Analyst ratings and recommendations
- Financial metrics (P/E ratio, EPS, revenue growth)
- Technical indicators and trends
- Recent news sentiment analysis
Troubleshooting
Dependencies Issues
- Ensure you're in the virtual environment:
source venv/bin/activate
- Install all required packages:
pip install -r requirements.txt
(if available) - For frontend issues:
cd frontend && npm install
API Connection Issues
- Verify the API server is running on port 5050
- Check CORS settings if frontend can't connect
- Ensure OpenAI API key is set in
api_server.py
News API Issues
- Verify your NewsAPI key is valid and set in
stocks_server.py
- Check API quota limits
- Ensure the keyword is not too specific
Stocks Server Issues
- The stocks server runs as a subprocess - no manual startup needed
- Only
stdio
transport is supported (no TCP) - Check logs in the API server output for errors
Development
To modify the system:
- Add new tools: Edit
stocks_server.py
and add new@mcp.tool()
functions - Update frontend: Modify
frontend/src/App.tsx
- Change API: Edit
api_server.py
for new endpoints - Update prompts: Modify the system message in
api_server.py
- Add logging: Use
print()
statements in tools for debugging
Project Structure
Stocks-Advisor-Agent-MCP/
āāā api_server.py # Flask API server
āāā stocks_server.py # MCP server with stock tools
āāā client.py # MCP client for testing
āāā frontend/ # React frontend
ā āāā src/
ā āāā package.json
ā āāā ...
āāā README.md
License
This project is for educational and demonstration purposes.