Stock_Advisor_MCP

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.

Category
Visit Server

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

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.

Recommended Servers

playwright-mcp

playwright-mcp

A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.

Official
Featured
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.

Official
Featured
Local
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

Official
Featured
Local
TypeScript
VeyraX MCP

VeyraX MCP

Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.

Official
Featured
Local
graphlit-mcp-server

graphlit-mcp-server

The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.

Official
Featured
TypeScript
Kagi MCP Server

Kagi MCP Server

An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

Official
Featured
Python
Neon Database

Neon Database

MCP server for interacting with Neon Management API and databases

Official
Featured
E2B

E2B

Using MCP to run code via e2b.

Official
Featured
Exa Search

Exa Search

A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.

Official
Featured
Qdrant Server

Qdrant Server

This repository is an example of how to create a MCP server for Qdrant, a vector search engine.

Official
Featured