# MCP Server: Yahoo Finance Data Extractor

FastAPI + MCP server for extracting financial data from Yahoo Finance. Provides stock prices, financial statements (annual + quarterly), market data, and company profiles with MCP integration for AI/LLM clients.

## Links
- App: https://rbicc.net/mcp-server-yahoo-finance
- Docs: https://tigzig.com/app-documentation/mcp-server-yahoo-finance.html
- GitHub: https://github.com/amararun/shared-yfin-coolify
- Live API: https://yfin.hosting.tigzig.com
- MCP Endpoint: https://yfin.hosting.tigzig.com/mcp
- API Docs: https://yfin.hosting.tigzig.com/docs

## Tags
mcp-servers, yahoo-finance, fastapi

## Architecture

```
API Client / MCP Client → FastAPI Server → yfinance → Yahoo Finance API
```

### API Endpoints

**Financial Statements**
- `GET /yfin/get-balance-sheet/?tickers=AAPL,MSFT` - Annual balance sheet (pipe-delimited)
- `GET /yfin/get-income-statement/?tickers=AAPL` - Annual income statement
- `GET /yfin/get-cash-flow/?tickers=AAPL` - Annual cash flow

**Excel-Friendly JSON Endpoints**
- `GET /yfin/excel/get-balance-sheet/?tickers=AAPL` - JSON structured for Excel
- `GET /yfin/excel/get-income-statement/?tickers=AAPL`
- `GET /yfin/excel/get-cash-flow/?tickers=AAPL`
- `GET /yfin/excel/get-quarterly-income-statement/?tickers=AAPL`

**Market Data**
- `GET /yfin/get-adj-close/?tickers=AAPL,MSFT&start_date=2023-01-01&end_date=2023-12-31` - Historical adjusted close
- `GET /yfin/get-all-prices/?tickers=AAPL&start_date=2023-01-01&end_date=2023-12-31` - Full OHLCV data
- `GET /yfin/get-market-data/?tickers=AAPL,MSFT` - Market cap, float shares, shares outstanding

**MCP**
- `POST /mcp` - MCP SSE endpoint for AI/LLM clients

### OpenAPI Schema
`docs/OPENAI_JSON_YFIN.TXT` - OpenAPI 3.1.0 schema for ChatGPT Custom GPT integration. Includes all non-Excel endpoints with operation IDs.

### Notes
- Multiple tickers: comma-separated (e.g., `AAPL,MSFT,GOOG`)
- Date format: YYYY-MM-DD
- Built-in rate limiting delays for Yahoo Finance compliance
- CORS enabled for cross-origin requests

## Setup

```bash
git clone https://github.com/amararun/shared-yfin-coolify.git
pip install -r requirements.txt
uvicorn main:app --reload  # localhost:8000
```

Deployment: `uvicorn main:app --host 0.0.0.0 --port $PORT`

### Dependencies
FastAPI, fastapi-mcp, yfinance, pandas
