Stock_Advisor_MCP
A FastMCP server that provides stock research, technical analysis, fundamental analysis, and scoring, exposed as MCP tools, resources, and prompts for AI agents.
README
Stock Advisor
A FastMCP server that provides stock research, technical analysis, fundamental analysis, and scoring — all exposed as MCP tools, resources, and prompts for AI agents.
Features
- Real-time quotes – Fetch near-real-time stock prices via Finnhub with an automatic yfinance fallback.
- Price history – Retrieve OHLCV history for any ticker with configurable periods and intervals.
- Price & market-cap classification – Classify a stock by share-price band and market-cap band.
- Technical indicators – Compute RSI, MACD, moving averages (SMA 50/200), golden/death cross detection, Bollinger Bands, volume ratio, and volatility.
- Fundamental analysis – Collect trailing & forward P/E, EPS, dividend yield, debt-to-equity, ROE, revenue growth, profit margin, beta, and sector context.
- Scoring engine – Combine technical and fundamental inputs into a transparent 0–100 score with a Strong Buy / Buy / Hold / Avoid label. Customisable technical vs. fundamental weighting.
- Multi-stock comparison – Compare several tickers side-by-side on price, valuation, RSI, and overall score.
- Watchlist resource – Exposes a simple, persisted watchlist for the current session.
- Agent prompts – Built-in prompts (
analyze_stock,compare_portfolio) that guide AI agents through the analysis workflow.
Architecture
stock-advisor/
├── server.py # Entry point (PATH setup + main call)
├── pyproject.toml # Project metadata & dependencies
├── requirements.txt # Pinned dependencies
├── Dockerfile # Docker image
├── .env.example # Environment template
├── README.md
├── src/
│ └── stock_advisor/
│ ├── __init__.py
│ ├── server.py # FastMCP server: tools, resources, prompts, transport config
│ ├── data_source.py # Finnhub (primary) + yfinance (fallback) data fetching
│ ├── indicators.py # Technical indicator computations (RSI, MACD, SMA, Bollinger, volatility)
│ ├── models.py # Pydantic models for all tool inputs & outputs
│ ├── scoring.py # Scoring engine: combines technical & fundamental signals
│ └── utils.py # Ticker normalisation, period/interval validation
└── tests/
└── test_core.py # Pytest suite (150+ lines of test coverage)
Quick Start
Prerequisites
- Python 3.11+
- A Finnhub API key (free tier available)
Installation
# Clone the repository
git clone <repo-url>
cd stock-advisor
# Create and activate a virtual environment
python -m venv .venv
source .venv/bin/activate # macOS/Linux
# .venv\Scripts\activate # Windows
# Install dependencies
pip install -r requirements.txt
# Configure your Finnhub API key
cp .env.example .env
# Edit .env and add your Finnhub API key:
# FINNHUB_API_KEY=your_key_here
Running
Start the server over HTTP (default):
python server.py
The server listens on http://127.0.0.1:8765/mcp by default.
Using stdio transport:
MCP_TRANSPORT=stdio python server.py
Custom host / port:
HOST=0.0.0.0 PORT=8080 python server.py
MCP Tools
All tools are registered with the FastMCP server and are automatically available to any MCP-compatible AI agent (Claude, Cline, etc.).
| Tool | Description |
|---|---|
get_quote_tool(ticker) |
Fetch a near-real-time quote (Finnhub → yfinance fallback). Returns price, change %, day high/low, open, previous close. |
get_price_history_tool(ticker, period, interval) |
OHLCV history with configurable period (1d, 5d, 1mo, 6mo, 1y, 5y, max) and interval (1m, 5m, 1h, 1d, 1wk). |
classify_by_price_range_tool(ticker) |
Classify by share-price band (penny / small-cap / mid-range / high-price) and market-cap band (micro / small / mid / large). |
get_technical_indicators_tool(ticker, period) |
RSI, MACD (line + signal + histogram), SMA 50/200, golden/death cross, Bollinger Bands, volume ratio, annualised volatility. |
get_fundamentals_tool(ticker) |
Trailing & forward P/E, EPS, dividend yield, D/E, ROE, revenue growth YoY, profit margin, beta, sector. |
score_stock_tool(ticker, technical, fundamentals, tech_weight, fundamental_weight) |
0–100 composite score with transparent breakdown and label. Default weights: 40 % technical, 60 % fundamental. |
compare_stocks_tool(tickers) |
Side-by-side comparison of price, P/E, RSI, and score for up to several tickers. |
MCP Resources
| Resource URI | Description |
|---|---|
watchlist:// |
Exposes a simple comma-separated watchlist (e.g. AAPL,MSFT,NVDA,TSLA) for the current session. |
MCP Prompts
| Prompt | Description |
|---|---|
analyze_stock |
Guides an AI agent to call tools in the correct order: quote → technicals → fundamentals → scoring, then summarise. |
compare_portfolio |
Guides an AI agent to call compare_stocks_tool and summarise trade-offs across price, valuation, momentum, and score. |
Scoring Engine
The scoring engine produces a transparent, explainable 0–100 score:
| Score Range | Label |
|---|---|
| 80–100 | Strong Buy |
| 65–79 | Buy |
| 45–64 | Hold |
| 0–44 | Avoid |
Technical factors scored (40 % default weight):
- RSI oversold / neutral / overbought
- Price relative to SMA trend (above → bullish, below → bearish)
- Volume confirmation (ratio > 1.0)
Fundamental factors scored (60 % default weight):
- P/E ratio (sector-relative when sector is known, absolute otherwise)
- Debt-to-equity ratio (< 1.0 → healthy)
- Revenue growth (positive → good)
- Profit margin (positive → good)
Weights are fully customisable via the tech_weight and fundamental_weight parameters in score_stock_tool.
Data Sources
| Data | Primary Source | Fallback |
|---|---|---|
| Real-time quote | Finnhub API | yfinance |
| Price history | yfinance | — |
| Fundamentals | yfinance | — |
| Technical indicators | Computed in-house from yfinance history | — |
Configuration
All configuration is via environment variables:
| Variable | Default | Description |
|---|---|---|
FINNHUB_API_KEY |
— | Your Finnhub API key (required for quote tool) |
MCP_TRANSPORT |
http |
Transport protocol (http or stdio) |
HOST |
127.0.0.1 |
Bind address |
PORT |
8765 |
Listen port |
MCP_PATH |
/mcp |
HTTP path for the MCP endpoint |
SSL_CERTFILE |
— | Path to SSL certificate (enables HTTPS) |
SSL_KEYFILE |
— | Path to SSL private key (enables HTTPS) |
Docker
# Build
docker build -t stock-advisor .
# Run
docker run -e FINNHUB_API_KEY=your_key_here -p 8765:8765 stock-advisor
Development
Running tests
pytest
Code structure
src/stock_advisor/server.py— FastMCP server definition; all tools, resources, and prompts are registered here.src/stock_advisor/data_source.py— Data fetching layer (Finnhub API + yfinance).src/stock_advisor/indicators.py— Pure-function technical indicator computations.src/stock_advisor/models.py— Pydantic models for input validation and structured output.src/stock_advisor/scoring.py— Composite scoring logic with weighted technical/fundamental signals.src/stock_advisor/utils.py— Ticker normalisation and period/interval validation.
Disclaimer
All tools and outputs from Stock Advisor are for educational and informational purposes only. Nothing provided by this server constitutes financial advice. Always do your own research before making investment decisions.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。