# MCP Server: Technical Analysis

FastAPI + MCP server for generating AI-powered technical analysis reports. Fetches Yahoo Finance data, calculates technical indicators, generates charts, sends to Gemini Vision API for interpretation, produces PDF and HTML reports.

## Links
- App: https://rbicc.net/mcp-server-technical-analysis
- Docs: https://tigzig.com/app-documentation/mcp-server-technical-analysis.html
- GitHub: https://github.com/amararun/shared-fastapi-mcp-technical-analysis
- Live API: https://ta.hosting.tigzig.com
- MCP Endpoint: https://ta.hosting.tigzig.com/mcp
- API Docs: https://ta.hosting.tigzig.com/docs

## Tags
mcp-servers, portfolio-analysis, technical-analysis, fastapi, gemini

## Architecture

```
Web UI / API Client / MCP Client → FastAPI Server → Yahoo Finance (via yfin.hosting.com)
                                                  → Finta (technical indicators)
                                                  → Matplotlib (chart generation)
                                                  → Gemini Vision API (AI interpretation)
                                                  → mdtopdf.hosting.com (PDF conversion)
```

### How It Works
1. Fetches historical price data (daily + weekly) from Yahoo Finance via custom FastAPI server
2. Calculates technical indicators: EMAs, MACD, RSI, Bollinger Bands
3. Generates custom charts for both timeframes via Matplotlib
4. Sends data and charts to Google Gemini AI for comprehensive market interpretation
5. Converts analysis to PDF and HTML reports via mdtopdf server

### API Endpoints
- `GET /` - Flask web interface
- `POST /api/technical-analysis` - Direct API (JSON body: ticker, daily_start_date, daily_end_date, weekly_start_date, weekly_end_date)
- `POST /mcp` - MCP endpoint for AI/LLM clients

### Example Request
```json
POST /api/technical-analysis
{
  "ticker": "AAPL",
  "daily_start_date": "2023-07-01",
  "daily_end_date": "2023-12-31",
  "weekly_start_date": "2022-01-01",
  "weekly_end_date": "2023-12-31"
}
```

### Response
```json
{
  "pdf_url": "https://mdtopdf.hosting.com/reports/analysis_123.pdf",
  "html_url": "https://mdtopdf.hosting.com/reports/analysis_123.html"
}
```

### Environment Variables
```
GEMINI_API_KEY=your_gemini_api_key
GEMINI_MODEL_NAME=gemini-1.5-flash-latest
```

### Dependencies
FastAPI, fastapi-mcp, Flask, yfinance, pandas, matplotlib, google-generativeai

### API Monitoring
Uses tigzig-api-monitor (PyPI) for centralized logging. IP addresses hashed, fails silently if logger unavailable.

## Setup

```bash
git clone https://github.com/amararun/shared-fastapi-mcp-technical-analysis.git
pip install -r requirements.txt
# Set GEMINI_API_KEY in .env
uvicorn main:app --reload
```

## Related Services
- Yahoo Finance data: https://github.com/amararun/shared-yfin-coolify
- PDF conversion: https://github.com/amararun/shared-reportlab-md-to-pdf
- FastAPI-MCP: https://github.com/tadata-org/fastapi_mcp
