finwatch-mcp
by geraldo96
README.md
# π finwatch-mcp
**A custom MCP Server for financial portfolio monitoring, risk analysis, and compliance β powered by LangGraph + Claude.**
> Turn natural language into actionable financial intelligence. Ask your portfolio questions like *"What's my risk exposure to tech stocks?"* or *"Flag any anomalous movements in the last 24h"* and get data-driven answers in seconds.
[](https://python.org)
[](https://modelcontextprotocol.io)
[](https://github.com/langchain-ai/langgraph)
[](LICENSE)
---
## Architecture
```
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β CLIENT LAYER β
β Claude Desktop β Gradio UI β CLI β Telegram β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β MCP Protocol (JSON-RPC)
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β LANGGRAPH AGENT (Orchestrator) β
β Multi-step reasoning Β· Report generation Β· Triage β
β Claude API Β· StateGraph Β· Human-in-the-loop β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β MCP Tool Calls
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β FINWATCH MCP SERVER β
β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ β
β β get_portfolio β β analyze_risk β β detect_anomaly β β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ β
β βsearch_filingsβ βget_market_kpiβ βcompliance_checkβ β
β ββββββββββββββββ ββββββββββββββββ ββββββββββββββββββ β
ββββββββββββββββββββββββββ¬βββββββββββββββββββββββββββββββββ
β
ββββββββββββββββββββββββββΌβββββββββββββββββββββββββββββββββ
β DATA LAYER β
β SQLite (prices, KPIs) β ChromaDB (SEC filings, RAG) β
β Alpha Vantage Β· Finnhub Β· FRED Β· SEC EDGAR β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
```
## Features
### MCP Server Tools
| Tool | Description |
|------|-------------|
| `get_portfolio` | Real-time portfolio status: holdings, P&L, sector allocation |
| `analyze_risk` | Risk metrics: VaR, Sharpe ratio, Beta, max drawdown |
| `detect_anomaly` | Flag unusual price movements, volume spikes, correlation breaks |
| `search_filings` | RAG-powered semantic search over SEC filings and earnings reports |
| `get_market_kpi` | Macro indicators: interest rates, inflation, sector performance |
| `compliance_check` | Validate portfolio against exposure limits and concentration rules |
### LangGraph Agent
- **Multi-step reasoning**: chains tool calls to answer complex questions
- **Report generation**: automated daily/weekly portfolio summaries
- **Anomaly triage**: investigates detected anomalies with root cause analysis
- **Human-in-the-loop**: asks for confirmation before high-impact actions
## Quick Start
### Prerequisites
- Python 3.11+
- [uv](https://docs.astral.sh/uv/) (recommended) or pip
- API keys: Alpha Vantage (free), Finnhub (free), Anthropic (for agent)
### Installation
```bash
# Clone the repo
git clone https://github.com/geraldo96/finwatch-mcp.git
cd finwatch-mcp
# Install with uv (recommended)
uv sync
# Or with pip
pip install -e ".[dev]"
# Copy environment template
cp .env.example .env
# Edit .env with your API keys
```
### Run the MCP Server
```bash
# Start the MCP server (Streamable HTTP)
uv run python -m src.mcp_server.server
# The server runs on http://localhost:8080/mcp
```
### Connect to Claude Desktop
Add to your `claude_desktop_config.json`:
```json
{
"mcpServers": {
"finwatch": {
"type": "http",
"url": "http://localhost:8080/mcp"
}
}
}
```
### Run the LangGraph Agent (standalone)
```bash
# Interactive CLI mode
uv run python -m src.agent.cli
# Example queries:
# > What's my current portfolio allocation?
# > Is my tech exposure within compliance limits?
# > Show me anomalies from the last week and explain them
```
### Run with Docker
```bash
docker compose up
# MCP server: http://localhost:8080/mcp
# Gradio UI: http://localhost:7860
```
## Data Sources
| Source | Data | API Key | Rate Limit (free) |
|--------|------|---------|-------------------|
| [Alpha Vantage](https://www.alphavantage.co/) | Stock prices, fundamentals | Free | 25 req/day |
| [Finnhub](https://finnhub.io/) | Real-time quotes, news, sentiment | Free | 60 req/min |
| [FRED](https://fred.stlouisfed.org/) | Macro indicators, interest rates | Free | 120 req/min |
| [SEC EDGAR](https://www.sec.gov/edgar) | 10-K, 10-Q filings | None | 10 req/sec |
| [Yahoo Finance](https://pypi.org/project/yfinance/) | Historical prices (backup) | None | Unofficial |
## Project Structure
```
finwatch-mcp/
βββ src/
β βββ mcp_server/
β β βββ server.py # MCP server entrypoint (Streamable HTTP)
β β βββ tools/
β β β βββ portfolio.py # get_portfolio tool
β β β βββ risk.py # analyze_risk tool
β β β βββ anomaly.py # detect_anomaly tool
β β β βββ filings.py # search_filings tool (RAG)
β β β βββ market_kpi.py # get_market_kpi tool
β β β βββ compliance.py # compliance_check tool
β β βββ config.py # Server configuration
β βββ agent/
β β βββ graph.py # LangGraph StateGraph definition
β β βββ nodes.py # Agent nodes (reason, act, report)
β β βββ state.py # Agent state schema
β β βββ cli.py # Interactive CLI client
β βββ data/
β β βββ ingester.py # Data fetching & sync logic
β β βββ models.py # SQLAlchemy / Pydantic models
β β βββ db.py # Database connection & queries
β βββ rag/
β βββ embeddings.py # BAAI embedding pipeline
β βββ indexer.py # SEC filing indexer
β βββ retriever.py # ChromaDB retrieval
βββ tests/
β βββ test_tools.py # Unit tests for MCP tools
β βββ test_agent.py # Agent integration tests
β βββ test_data.py # Data layer tests
βββ scripts/
β βββ seed_data.py # Seed DB with sample portfolio
β βββ ingest_filings.py # Download & index SEC filings
β βββ demo.py # Full demo walkthrough
βββ docs/
β βββ ARCHITECTURE.md # Detailed architecture docs
β βββ TOOLS.md # MCP tool specifications
βββ docker-compose.yml
βββ Dockerfile
βββ pyproject.toml
βββ .env.example
βββ README.md
```
## Development Roadmap
### Week 1 β Foundation
- [x] Project scaffold & CI setup
- [ ] MCP server with `get_portfolio` and `analyze_risk` tools
- [ ] SQLite data layer + Alpha Vantage / yfinance ingestion
- [ ] Sample portfolio seeding script
### Week 2 β RAG & Anomaly Detection
- [ ] ChromaDB setup + SEC EDGAR filing indexer
- [ ] `search_filings` tool with BAAI embeddings
- [ ] `detect_anomaly` tool (z-score + rolling stats)
- [ ] `get_market_kpi` tool (FRED integration)
### Week 3 β Agent & Orchestration
- [ ] LangGraph StateGraph with Claude API
- [ ] Multi-step reasoning chains
- [ ] `compliance_check` tool
- [ ] Interactive CLI client
### Week 4 β Polish & Deploy
- [ ] Docker Compose (server + agent + Gradio UI)
- [ ] Comprehensive tests
- [ ] Demo video / GIF
- [ ] Hugging Face Space (optional)
## Tech Stack
| Layer | Technology |
|-------|-----------|
| MCP Server | Python `mcp` SDK, Streamable HTTP |
| Agent | LangGraph, Claude API (Anthropic SDK) |
| Structured Data | SQLite + SQLAlchemy |
| Vector Store | ChromaDB + BAAI/bge-small-en-v1.5 |
| Data Sources | Alpha Vantage, Finnhub, FRED, SEC EDGAR, yfinance |
| UI | Gradio (demo), Claude Desktop (production) |
| Deploy | Docker Compose |
| Testing | pytest, pytest-asyncio |
## Contributing
Contributions are welcome! Please read the [contributing guidelines](CONTRIBUTING.md) first.
## License
MIT License β see [LICENSE](LICENSE) for details.
---
*Built by [Geraldo Margjini](https://github.com/geraldo96) as a portfolio project demonstrating MCP Server development, LangGraph agent orchestration, and financial data engineering.*
This server cannot be deployed
Maintenance
ActivityInactive
ResponsivenessNo issues