MCP-Quant Financial Research
by art3mis-xo
README.md
# MCP-Quant Financial Research
An [MCP](https://modelcontextprotocol.io) server that gives LLM clients (Claude Desktop, VS Code, etc.) three deterministic financial tools. The LLM decides which tool to call; the server fetches daily prices from Yahoo Finance and computes the numbers with pandas/numpy, so no figure in the output is generated by a language model.
Every response includes where the data came from, when it was retrieved, and basic data-quality counts.
## Tools
| Tool | Input | Returns |
|---|---|---|
| `get_price_history` | `symbols`, `start_date`, `end_date` (ISO dates) | `{"prices": [{"Date": ..., "<SYMBOL>": price, ...}], "provenance": {...}}` |
| `calculate_risk_metrics` | `symbols`, `start_date`, `end_date` | `{"metrics": [...], "provenance": {...}}`, one metrics object per symbol |
| `research` | `query` (free text, e.g. `"Compare TSLA and NVDA over the last year"`) | A report with the parsed plan, metrics, provenance and a one-paragraph summary |
There is also one resource, `research://capabilities`, which returns a short text description of the server.
Inputs are validated with Pydantic before any data is fetched: 1–10 symbols (upper-cased), and `end_date` must be after `start_date`.
### Metrics
Computed per symbol from adjusted daily closes in [`analytics.py`](src/financial_mcp/analytics.py):
| Metric | Definition |
|---|---|
| Cumulative return | last price / first price − 1 |
| Annualized return | (1 + cumulative)^(252 / trading days) − 1 |
| Annualized volatility | sample std of daily returns × √252 |
| Sharpe ratio | mean / std of daily returns × √252, risk-free rate 0; `null` if returns have zero variance |
| Maximum drawdown | worst fall from a running peak |
| Beta | cov(symbol, SPY) / var(SPY) on date-aligned daily returns |
### Provenance
`source`, `retrieved_at` (UTC), `symbols`, `start_date`, `end_date`, and `quality`: `rows`, `missing_rows`, `duplicate_rows`, `first_date`, `last_date`, `adjusted_prices`.
## Setup
Requires Python 3.12+.
```bash
python -m venv venv
source venv/bin/activate
pip install -e ".[dev]"
cp .env.example .env # no keys are required today
```
## Run
Smoke test (one live query, prints the report):
```bash
python main.py
```
Start the MCP server over stdio:
```bash
python -m financial_mcp.server
```
VS Code picks it up from [`.vscode/mcp.json`](.vscode/mcp.json).
## Test and lint
```bash
pytest -q
ruff check src tests main.py
```
The tests replace Yahoo Finance with fixed prices, so they run offline. They cover the metric calculations and each tool's output.
## Roadmap
Next: LLM-based query planner with an evaluation against the current rule-based parser.
---
For research and education only. Not investment advice.