Stocks-Analyzer-AI

deepansh-saxena/Stocks-Analyzer-AI

3.3

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.

Tools
  1. get_stock_data

    Fetches stock data from Zacks quote feed.

  2. 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

Usage

  1. Open the frontend in your browser
  2. 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 message
  • GET /api/health: Health check endpoint

Tools Available

  • get_stock_data(ticker): Fetches stock data from Zacks quote feed
  • get_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:

  1. Add new tools: Edit stocks_server.py and add new @mcp.tool() functions
  2. Update frontend: Modify frontend/src/App.tsx
  3. Change API: Edit api_server.py for new endpoints
  4. Update prompts: Modify the system message in api_server.py
  5. 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.