mcp-stock-market-analysis

mcp-stock-market-analysis

3.1

If you are the rightful owner of mcp-stock-market-analysis 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.

A powerful stock market analysis application that leverages the AlphaVantage API to provide real-time stock data and technical analysis.

MCP Stock Market Analysis

A powerful stock market analysis application that leverages the AlphaVantage API to provide real-time stock data and technical analysis. This application integrates with the Model Context Protocol (MCP) to enable AI assistants to access stock market data and analysis.

This project is based on the excellent article Step-by-Step Guide: Building an MCP Server using Python SDK, AlphaVantage & Claude AI by Syed Hasan, with improvements to follow the latest MCP Python SDK best practices.

Features

  • Real-time Stock Quotes: Get up-to-date stock prices and trading information
  • Technical Analysis: Calculate and visualize key indicators like RSI and moving averages
  • MCP Integration: Seamless integration with AI assistants through the Model Context Protocol
  • REST API: FastAPI endpoints for programmatic access to stock data
  • Interactive Dashboard: Streamlit-based visualization dashboard

Getting Started

Prerequisites

Installation

  1. Clone the repository

    git clone https://github.com/yourusername/mcp-stock-market-analysis.git
    cd mcp-stock-market-analysis
    
  2. Create and activate a virtual environment

    For Windows:

    python -m venv venv
    venv\Scripts\activate
    

    For macOS/Linux:

    python -m venv venv
    source venv/bin/activate
    
  3. Install dependencies

    Using pip:

    pip install -e .
    

    Or using uv (faster):

    pip install uv
    uv install
    
  4. Set up environment variables

    Create a .env file in the project root with your AlphaVantage API key:

    ALPHA_VANTAGE_API_KEY=your_api_key_here
    

    You can get a free API key by signing up at AlphaVantage.

Usage

Running the Complete Application

The easiest way to run the entire application (API server, MCP server, and dashboard) is:

python server.py

This will start:

Running Components Separately

API and MCP Server
python main.py
Dashboard Only
cd dashboard
streamlit run app.py

API Reference

REST API Endpoints

EndpointMethodDescriptionExample
/quote/{symbol}GETGet the latest stock quote/quote/AAPL
/analyze/{symbol}GETGet detailed stock analysis with indicators/analyze/MSFT
/historical/{symbol}GETGet historical data with technical indicators/historical/GOOGL

MCP Tools

ToolDescriptionParameters
get_stock_quoteGet the latest stock quotesymbol: Stock symbol (e.g., AAPL)
analyze_stockGet detailed stock analysis with technical indicatorssymbol: Stock symbol (e.g., AAPL)

MCP Resources

ResourceDescriptionExample URI
Stock QuoteGet formatted stock quote informationstock://AAPL/quote
Stock AnalysisGet formatted stock analysis informationstock://AAPL/analysis

Examples

Getting a Stock Quote

curl http://localhost:8000/quote/AAPL

Response:

{
  "symbol": "AAPL",
  "price": 221.53,
  "change": -2.21,
  "change_percent": "-0.9889%",
  "volume": 58932401,
  "latest_trading_day": "2025-03-26"
}

Using with Claude or Other AI Assistants

Once the MCP server is running, you can connect it to Claude Desktop or other MCP-compatible AI assistants. The AI can then use commands like:

Get me the latest stock quote for Apple.
Analyze the recent performance of Microsoft stock.

Troubleshooting

  • API Key Issues: Ensure your AlphaVantage API key is correctly set in the .env file
  • Port Conflicts: If you get "address already in use" errors, ensure no other applications are using ports 8000, 8080, or 8501
  • Rate Limiting: The free tier of AlphaVantage has usage limits. If you encounter errors, you might be exceeding these limits

License

This project is licensed under the MIT License - see the LICENSE file for details.

Related MCP Servers

View all finance servers →