Equity Screener MCP Server
README.md
<div align="center">
# ๐ Equity Screener MCP Server
**Give your AI assistant real stock market data โ from any country, in seconds.**
[](https://github.com/MatheusFernandesDuarte/equity-screener-mcp-server/actions/workflows/ci.yml)
[](https://www.python.org/)
[](LICENSE)
[](https://modelcontextprotocol.io)
[](https://docs.astral.sh/uv/)
<br/>
*Tired of asking Claude about the stock market and getting hallucinated tickers?*
*This project fixes that.*
[Getting Started](#-getting-started) ยท [MCP Setup](#-connect-to-your-ai) ยท [Tools Reference](#-available-tools) ยท [Architecture](#๏ธ-architecture) ยท [Contributing](#-contributing)
</div>
---
## ๐ค The Problem
When you ask an AI assistant *"Which stocks spiked in Brazil today?"*, it either:
- โ Refuses: *"I don't have access to real-time data"*
- โ Hallucinates: Makes up tickers with confident-sounding prices
**This project solves that.** It fetches equity screener data for any region, stores it locally in DuckDB, and exposes it as MCP tools that AI agents can call directly.
```
You: "Which stock spiked the most in Argentina today?"
Claude: [calls get_top_movers("argentina", sort_by="change_pct")]
"NVDA.BA surged 8.3% today, followed by AAPL.BA at +5.1%..."
```
Real data. No hallucinations. No browser needed.
---
## โจ Features
- **๐ Fast** โ HTTP-based scraper (no Selenium, no ChromeDriver). ~10ร faster than browser automation.
- **๐๏ธ Persistent** โ DuckDB stores all snapshots locally. Queries are instant.
- **๐ Stale-while-revalidate** โ AI always gets a response immediately; fresh data loads in background.
- **๐ค AI-native** โ 5 MCP tools purpose-built for LLM consumption, with freshness-aware descriptions.
- **๐ Any region** โ Argentina, Brazil, Japan, Germany, India, and [60+ more](#supported-regions).
- **๐ Rich data** โ Symbol, name, price, and `change_pct` (daily % change) for every stock.
- **๐ Multi-provider** โ Works with Claude, OpenAI, Perplexity, or fully offline with no API key.
---
## ๐ Getting Started
**Requirements:** Python 3.11+ and [uv](https://docs.astral.sh/uv/getting-started/installation/)
```bash
# 1. Clone the repo
git clone https://github.com/MatheusFernandesDuarte/equity-screener-mcp-server.git
cd equity-screener-mcp-server
# 2. Install dependencies
uv sync
# 3. Scrape your first region
python run.py Argentina
# 4. Start the MCP server
python mcp_server.py
```
Output goes to `data/outputs/` (CSV) and `data/market.duckdb`.
---
## ๐ Connect to Your AI
### Claude Code (recommended)
```bash
claude mcp add yahoo-finance -- python /path/to/equity-screener-mcp-server/mcp_server.py
```
### Claude Desktop
Add to `~/.claude/claude_desktop_config.json`:
```json
{
"mcpServers": {
"yahoo-finance": {
"command": "python",
"args": ["/path/to/equity-screener-mcp-server/mcp_server.py"],
"env": {
"AI_PROVIDER": "local"
}
}
}
}
```
### With Claude AI (richer summaries)
```json
{
"mcpServers": {
"yahoo-finance": {
"command": "python",
"args": ["/path/to/equity-screener-mcp-server/mcp_server.py"],
"env": {
"AI_PROVIDER": "claude",
"ANTHROPIC_API_KEY": "sk-ant-..."
}
}
}
}
```
---
## ๐ฌ Example Conversations
Once connected, just ask naturally:
> **"Which stock spiked the most in Argentina today?"**
> โ Claude calls `get_top_movers("argentina", sort_by="change_pct")` and returns ranked results with % change.
> **"Give me a market summary for Brazil."**
> โ Claude calls `get_market_summary("brazil")` โ returns AI-generated summary, anomaly detection, and trend analysis.
> **"Find any ticker with 'petro' in the name."**
> โ Claude calls `search_symbol("petro")` โ partial match across all scraped regions.
> **"Are there anomalies in the Japanese market right now?"**
> โ Claude scrapes Japan if needed, analyzes Z-scores, flags statistical outliers.
> **"What are the top 5 most expensive stocks in Germany?"**
> โ Claude calls `get_top_movers("germany", n=5, sort_by="price")`.
---
## ๐ ๏ธ Available Tools
| Tool | Parameters | What it does |
|------|-----------|-------------|
| `get_stocks_by_region` | `region` | Compact snapshot: count + top 10 + freshness status. Auto-triggers refresh if stale. |
| `get_top_movers` | `region`, `n=10`, `sort_by="price"` | Top N stocks sorted by `price` or `change_pct` (daily % change). |
| `search_symbol` | `symbol` | Case-insensitive partial match across all scraped regions. |
| `get_market_summary` | `region` | AI-generated summary with anomaly detection and trend analysis. |
| `trigger_refresh` | `region` | Queue a background scrape without blocking. |
> **Freshness logic:** Claude checks the `freshness` field (`fresh` / `stale` / `expired`) on every response and decides whether to use cached data or trigger a refresh first.
---
## ๐ค AI Providers
| Provider | Env var | Quality |
|----------|---------|---------|
| `local` *(default)* | None required | Rule-based: Z-score anomalies, median trends. Works offline. |
| `claude` | `ANTHROPIC_API_KEY` | Best narrative summaries and market context. |
| `openai` | `OPENAI_API_KEY` | GPT-4o-mini by default, configurable. |
| `perplexity` | `PERPLEXITY_API_KEY` | Good for combining live web context. |
If the API key is missing, the system **automatically falls back** to `local` โ no crashes.
```bash
# Run with Claude AI
AI_PROVIDER=claude ANTHROPIC_API_KEY=sk-ant-... python mcp_server.py
# Run fully offline
python mcp_server.py
```
---
## ๐๏ธ Architecture
```
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ Claude / GPT / any MCP client โ
โ โ MCP tool calls โ
โ MarketService โโโ DuckDB (reads, always fast) โ
โ โ โ
โ โโโโ ScrapeManager.submit() [non-blocking] โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ background thread
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ScraperEngine โโโ Equity Screener API (HTTP) โ
โ Auth: GET screener host โ cookies โ crumb โ
โ Data: POST /v1/finance/screener (JSON) โ
โ โ โ
โ DuckDB (writes, single lock) โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
```
**Key design invariants:**
- MCP tools **never block** on a network call โ always served from DuckDB
- Scraping only happens in background workers (no Selenium, no Chrome)
- **Stale-while-revalidate**: return cached data instantly, refresh in background
- AI layer is **optional** โ runs fully offline by default
---
## ๐ Supported Regions
<details>
<summary>Click to expand โ 60+ regions supported</summary>
| Region | Code | Region | Code |
|--------|------|--------|------|
| Argentina | `ar` | Japan | `jp` |
| Australia | `au` | Malaysia | `my` |
| Austria | `at` | Mexico | `mx` |
| Belgium | `be` | Netherlands | `nl` |
| Brazil | `br` | New Zealand | `nz` |
| Canada | `ca` | Nigeria | `ng` |
| Chile | `cl` | Norway | `no` |
| China | `cn` | Pakistan | `pk` |
| Colombia | `co` | Peru | `pe` |
| Czech Republic | `cz` | Philippines | `ph` |
| Denmark | `dk` | Poland | `pl` |
| Egypt | `eg` | Portugal | `pt` |
| Finland | `fi` | Qatar | `qa` |
| France | `fr` | Romania | `ro` |
| Germany | `de` | Saudi Arabia | `sa` |
| Greece | `gr` | Singapore | `sg` |
| Hong Kong | `hk` | South Africa | `za` |
| Hungary | `hu` | South Korea | `kr` |
| India | `in` | Spain | `es` |
| Indonesia | `id` | Sweden | `se` |
| Ireland | `ie` | Switzerland | `ch` |
| Israel | `il` | Taiwan | `tw` |
| Italy | `it` | Thailand | `th` |
| Jordan | `jo` | Turkey | `tr` |
| Kenya | `ke` | United Arab Emirates | `ae` |
| Kuwait | `kw` | United Kingdom | `gb` |
| Latvia | `lv` | United States | `us` |
| Lithuania | `lt` | Venezuela | `ve` |
| Luxembourg | `lu` | Vietnam | `vn` |
</details>
---
## ๐ณ Docker
```bash
# Default: scrape Argentina
docker compose up
# Custom region
docker compose run equity-screener python run.py Brazil
# MCP server via HTTP (for remote clients)
MCP_TRANSPORT=http MCP_PORT=8000 docker compose up
```
Data persists to `./data/outputs/` on the host.
---
## โ๏ธ Environment Variables
| Variable | Default | Description |
|----------|---------|-------------|
| `AI_PROVIDER` | `local` | `local`, `claude`, `openai`, `perplexity` |
| `MCP_TRANSPORT` | `stdio` | `stdio` or `http` |
| `MCP_PORT` | `8000` | HTTP transport port |
| `ANTHROPIC_API_KEY` | โ | Required for `claude` provider |
| `OPENAI_API_KEY` | โ | Required for `openai` provider |
| `PERPLEXITY_API_KEY` | โ | Required for `perplexity` provider |
| `ANTHROPIC_MODEL` | `claude-haiku-4-5-20251001` | Claude model override |
| `OPENAI_MODEL` | `gpt-4o-mini` | OpenAI model override |
| `DUCKDB_PATH` | `data/market.duckdb` | Custom database path |
---
## ๐งช Development
```bash
uv sync
python -m pytest tests/ -v # 109 tests, no browser, no network
uv run ruff check src/ tests/ # lint
```
### Project structure
```
src/
scraper/ ScraperEngine (HTTP) + ScrapeManager (background workers)
storage/ DuckDB schema + StockRepository
services/ MarketService (SWR cache, freshness, dynamic TTL)
ai/ AIProvider abstraction + LocalProvider + cloud providers
mcp/ Tool handlers + stdio/HTTP transports
app/ CLI orchestrator + factories
tests/ One test file per module, TDD throughout
mcp_server.py MCP entrypoint
run.py CLI entrypoint
```
---
## ๐ค Contributing
Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for setup, rules, and how to add a new AI provider or data source.
```bash
# Fork, clone, and get started
git checkout -b feat/your-feature
uv sync
python -m pytest tests/ # must be green before opening a PR
```
---
## ๐ License
MIT โ see [LICENSE](LICENSE).
---
<div align="center">
**Built by [Matheus Fernandes](https://github.com/MatheusFernandesDuarte)**
[](https://github.com/MatheusFernandesDuarte)
[](https://www.linkedin.com/in/matheusfernandesduarte/)
[](https://x.com/matheusfeeer_)
*If this project helped you, consider giving it a โญ*
</div>
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo recent community issues