yfinance-mcp

everdeep/yfinance-mcp

3.2

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

Yahoo Finance MCP Server provides access to a wide range of financial data and tools through a Model Context Protocol server.

Tools
28
Resources
0
Prompts
0

Yahoo Finance MCP Server

A comprehensive Model Context Protocol (MCP) server that provides access to Yahoo Finance data including stock prices, financial statements, market analysis, options data, and more.

Features

This MCP server provides 30 tools organized into 7 categories:

Stock Information (6 Tools)
  • get_stock_info – Comprehensive company information and key metrics
  • get_current_price – Real-time stock price and quote data
  • get_market_cap – Market capitalization and valuation metrics
  • get_major_holders – Major shareholders information
  • get_institutional_holders – Detailed institutional holder data
  • get_mutualfund_holders – Mutual fund holder information
Historical Data (5 Tools)
  • get_historical_data – Historical price data with flexible periods/intervals
  • get_dividends – Dividend payment history
  • get_splits – Stock split history
  • get_actions – Combined dividends and splits
  • get_capital_gains – Capital gains distribution (for funds/ETFs)
Financial Statements (4 Tools)
  • get_income_statement – Income statement (quarterly/annual)
  • get_balance_sheet – Balance sheet (quarterly/annual)
  • get_cash_flow – Cash flow statement (quarterly/annual)
  • get_financials – All financial statements combined
Market Analysis (5 Tools)
  • get_analyst_recommendations – Analyst buy/sell/hold recommendations
  • get_analyst_price_targets – Analyst price target estimates
  • get_earnings – Historical and estimated earnings data
  • get_earnings_dates – Upcoming earnings calendar
  • get_calendar – Company events calendar
Options & Derivatives (4 Tools)
  • get_options_dates – Available option expiration dates
  • get_options_chain – Full options chain for a date
  • get_calls – Call options data
  • get_puts – Put options data
News & Insights (2 Tools)
  • get_news – Latest news articles with summaries
  • get_upgrades_downgrades – Analyst rating changes
Bulk Operations (2 Tools)
  • download_multiple – Batch download data for multiple tickers
  • compare_stocks – Compare key metrics across stocks

Installation

Prerequisites

  • Python 3.10 or higher
  • uv package manager

Install with uv

# Clone the repository
git clone <repository-url>
cd yahoo-finance-mcp

# Install dependencies
uv sync

Usage

With Claude Desktop

Add this configuration to your Claude Desktop config file:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "yahoo-finance": {
      "command": "uv",
      "args": [
        "--directory",
        "/path/to/yahoo-finance-mcp",
        "run",
        "yahoo-finance-mcp"
      ]
    }
  }
}

With Claude Code

claude mcp add yahoo-finance --scope local -- uv --directory /path/to/yahoo-finance-mcp run yahoo-finance-mcp

Development Mode

Test the server using the MCP inspector:

# Run in development mode
uv run mcp dev src/yahoo_finance_mcp/server.py

This opens a web interface where you can test all the tools interactively.

As a Standalone Server

# Run the server
uv run yahoo-finance-mcp

Tool Examples

Get Stock Information

# Get comprehensive stock info
get_stock_info(ticker="AAPL")

# Get current price
get_current_price(ticker="MSFT")

# Get valuation metrics
get_market_cap(ticker="GOOGL")

Historical Data

# Get 1 year of daily data
get_historical_data(ticker="TSLA", period="1y", interval="1d")

# Get 5 days of hourly data
get_historical_data(ticker="NVDA", period="5d", interval="1h")

# Get dividend history
get_dividends(ticker="JNJ")

Financial Statements

# Get quarterly income statement
get_income_statement(ticker="AAPL", frequency="quarterly")

# Get annual balance sheet
get_balance_sheet(ticker="MSFT", frequency="annual")

# Get all financials at once
get_financials(ticker="GOOGL", frequency="quarterly")

Market Analysis

# Get analyst recommendations
get_analyst_recommendations(ticker="TSLA")

# Get price targets
get_analyst_price_targets(ticker="NVDA")

# Get earnings data
get_earnings(ticker="AAPL")

Options Data

# Get available expiration dates
get_options_dates(ticker="AAPL")

# Get full options chain for nearest expiration
get_options_chain(ticker="AAPL")

# Get options for specific date
get_options_chain(ticker="AAPL", expiration_date="2024-12-20")

# Get only calls
get_calls(ticker="AAPL", expiration_date="2024-12-20")

News & Insights

# Get latest 10 news articles
get_news(ticker="TSLA", limit=10)

# Get analyst upgrades/downgrades
get_upgrades_downgrades(ticker="NVDA")

Bulk Operations

# Compare multiple stocks
compare_stocks(tickers=["AAPL", "MSFT", "GOOGL"])

# Download historical data for multiple stocks
download_multiple(
    tickers=["AAPL", "MSFT", "GOOGL"],
    period="1mo",
    interval="1d"
)

Project Structure

yahoo-finance-mcp/
ā”œā”€ā”€ src/
│   └── yahoo_finance_mcp/
│       ā”œā”€ā”€ __init__.py           # Package initialization
│       ā”œā”€ā”€ server.py             # Main MCP server with tool registration
│       ā”œā”€ā”€ models.py             # Pydantic models for validation
│       ā”œā”€ā”€ utils.py              # Helper functions and utilities
│       └── tools/
│           ā”œā”€ā”€ __init__.py
│           ā”œā”€ā”€ stock_info.py    # Stock information tools
│           ā”œā”€ā”€ historical.py    # Historical data tools
│           ā”œā”€ā”€ financials.py    # Financial statement tools
│           ā”œā”€ā”€ analysis.py      # Market analysis tools
│           ā”œā”€ā”€ options.py       # Options data tools
│           ā”œā”€ā”€ news.py          # News and insights tools
│           └── bulk.py          # Bulk operations tools
ā”œā”€ā”€ tests/
│   └── test_tools.py
ā”œā”€ā”€ pyproject.toml
ā”œā”€ā”€ README.md
└── .gitignore

Technical Details

Data Source

This server uses the yfinance library to fetch data from Yahoo Finance. Please note:

  • This is an unofficial API and is intended for research and educational purposes
  • Data availability and accuracy depend on Yahoo Finance
  • Some data may not be available for all tickers
  • Rate limiting may apply for excessive requests

Error Handling

All tools include comprehensive error handling and will return structured error responses when:

  • Invalid ticker symbols are provided
  • Data is not available for the requested ticker
  • Network issues occur
  • Invalid parameters are passed

Error responses follow this format:

{
  "error": true,
  "message": "Description of the error",
  "ticker": "SYMBOL"
}

Data Formatting

  • All dates are returned in ISO 8601 format (YYYY-MM-DD or full datetime)
  • Pandas DataFrames are converted to lists of dictionaries for easy consumption
  • NaN/None values are handled gracefully
  • Large datasets are formatted efficiently

Development

Running Tests

# Run all tests
uv run pytest

# Run with coverage
uv run pytest --cov=yahoo_finance_mcp

Adding New Tools

  1. Create a new function in the appropriate tool module (or create a new module)
  2. Import the function in server.py
  3. Register it with the @mcp.tool() decorator
  4. Add documentation to this README

Code Style

The project follows standard Python conventions:

  • Type hints for all function parameters and returns
  • Comprehensive docstrings
  • Error handling for all external API calls
  • Modular organization by functionality

Limitations

  • Not for Production Trading: This server is for informational and research purposes only
  • Data Accuracy: Relies on Yahoo Finance data accuracy and availability
  • Rate Limiting: Heavy usage may encounter rate limits
  • No Real-time Guarantees: Data may have delays depending on source
  • Terms of Service: Users must comply with Yahoo Finance's Terms of Service

Contributing

Contributions are welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes with tests
  4. Submit a pull request

Acknowledgments

Support

For issues, questions, or contributions, please open an issue on GitHub.


Disclaimer: This project is not affiliated with, endorsed by, or connected to Yahoo Finance or Yahoo Inc. Use at your own risk and ensure compliance with Yahoo Finance's Terms of Service.