Skip to main content
Glama
mcp-yahoo-stock

mcp-yahoo-stock

by lagrot
README.md
# Stock MCP (Yahoo Finance + Claude/Gemini)

[![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0)

A local Model Context Protocol (MCP) server for stock analysis using Yahoo Finance and official SDKs. This server provides tools for LLMs (like Claude or Gemini) to fetch market data, financials, and sentiment analysis directly.

---

## ๐Ÿš€ Features

* ๐Ÿ“ˆ Historical stock prices
* ๐Ÿ’พ SQLite caching (fast + persistent)
* ๐Ÿ“Š Financial statements
* ๐Ÿง  Analyst recommendations
* ๐Ÿ“ฐ News + basic sentiment analysis
* โšก AI-optimized summary output
* ๐Ÿ› ๏ธ Official MCP SDK (Compatible with Claude Desktop & Gemini CLI)

---

## ๐Ÿงฑ Architecture

```text
src/
  data/        # Data fetching + caching
  services/    # Analysis logic
  mcp/         # MCP server (Standard JSON-RPC 2.0)
```

---

## โš™๏ธ Setup

```bash
# Install dependencies
uv sync
```

---

## ๐Ÿ› ๏ธ Tech Stack
- **Language:** Python 3.12+
- **Environment:** [uv](https://github.com/astral-sh/uv)
- **Data Source:** `yfinance`
- **Caching:** `sqlite3`
- **MCP Framework:** `FastMCP` (via official `mcp` Python SDK)

---

## ๐Ÿงช Standalone Testing (WSL / Linux)

### Option A: Automated (Recommended)
Use the included test script which handles the complex MCP handshake automatically:
```bash
uv run python tests/test_mcp_client.py
```

---

## ๐Ÿค– Usage with Gemini CLI

To use this with the [Gemini CLI](https://github.com/google/gemini-cli), register it as an MCP server. Using the `--project` flag and absolute paths ensures the server is available globally from any directory.

Run this command from your terminal, replacing `<PROJECT_PATH>` with the absolute path where you cloned this repository:

```bash
gemini mcp add mcp-yahoo-stock uv -- --project <PATH_TO_PROJECT> run env PYTHONPATH=<PATH_TO_PROJECT> python -m src.mcp.server
```

*Note: Replace `<PROJECT_PATH>` with your full path (e.g., `/home/username/git/mcp-yahoo-stock`).*

Once registered, you can use the analysis tools from any directory:

### Example Usage

**1. Check Market Status (No arguments):**
```bash
gemini tool call mcp-yahoo-stock:yahoo_finance_market_overview '{}'
```

**2. Analyze a Company by Name (Smart Lookup):**
```bash
gemini tool call mcp-yahoo-stock:yahoo_finance_lookup_and_analyze '{"query": "Apple"}'
```

**3. Deep Dive into a Specific Ticker:**
```bash
gemini tool call mcp-yahoo-stock:yahoo_finance_analyze_stock '{"symbol": "AAPL", "period": "1mo"}'
```

---

## ๐Ÿค– Usage with Claude Desktop

Add this to your `claude_desktop_config.json`:

```json
{
  "mcpServers": {
    "mcp-yahoo-stock": {
      "command": "uv",
      "args": [
        "run",
        "--project",
        "/path/to/mcp-yahoo-stock",
        "python",
        "-m",
        "src.mcp.server"
      ]
    }
  }
}
```

---

## ๐Ÿ’พ Caching & Database

* **SQLite:** This project uses a local SQLite database (`cache.db`) for caching. You **do not** need to install SQLite on your system manually; it is included in the Python standard library.
* **Logic:** Caches historical prices only and refreshes data older than 1 day.

---

## ๐Ÿณ Running with Docker

This project is containerized for production deployment.

### Building the Docker Image
From the project root directory, run:
```bash
podman build -t mcp-yahoo-stock .
```

### Running the Docker Container
To run the server in a container:
```bash
podman run --rm -i --network host mcp-yahoo-stock:latest python -m src.mcp.server
```

### Registering with Gemini CLI (from Docker)
Register the server using the `podman` command:
```bash
gemini mcp add mcp-yahoo-stock podman run --rm -i --network host mcp-yahoo-stock:latest python -m src.mcp.server
```

---

## ๐Ÿ› ๏ธ Development

This project uses **Ruff** for linting and formatting.

```bash
# Check for issues
uv run ruff check .

# Fix and format
uv run ruff check --fix .
uv run ruff format .
```

---

## ๐Ÿฉบ Troubleshooting & Logging

This server logs all activity to `stderr`. This is the industry standard for production MCP servers, as it allows the host environment (Gemini CLI or Claude Desktop) to capture and manage your logs automatically.

### Checking logs in real-time (WSL/Linux):
If you are running the server manually for debugging, pipe the output to a file:
```bash
uv run python -m src.mcp.server --debug 2> mcp_server.log
# Then view it in a separate terminal:
tail -f mcp_server.log
```

### Enable Debug Mode
To enable more verbose logging, update your MCP configuration to include the `--debug` flag:

**Gemini CLI:**
```bash
gemini mcp add mcp-yahoo-stock "uv -- --project <PATH_TO_PROJECT> run env PYTHONPATH=<PATH_TO_PROJECT> python -m src.mcp.server" --trust -s project
```

**Claude Desktop:**
```json
{
  "mcpServers": {
    "mcp-yahoo-stock": {
      "command": "uv",
      "args": ["run", "--project", "/path/to/mcp-yahoo-stock", "python", "-m", "src.mcp.server"]
    }
  }
}
```

---

## ๐Ÿ“„ License

This project is licensed under the GPL-3.0 License. See the [LICENSE](LICENSE) file for details.

TDQS

A3.6/5.0

Scored across 5 tools

Disambiguation3/5

The five tools mostly target distinct functions, but lookup_and_analyze is essentially a combination of search_symbol plus analyze_stock, creating real overlap and misselection risk. get_delayed_prices also overlaps with analyze_stock in returning prices. Descriptions help somewhat but the boundaries between the lookup/analyze trio remain fuzzy.

Naming Consistency4/5

All tools share a consistent yahoo_finance_ prefix and most use a verb_noun suffix (get_delayed_prices, search_symbol, analyze_stock). Minor deviations exist: lookup_and_analyze is verb_and_verb and market_overview is noun-only, but the set remains readable and predictable.

Tool Count4/5

Five tools is a reasonable, focused scope for a stock-data server covering search, analysis, prices, and market status. It is on the lean side but each tool earns its place without bloat.

Completeness4/5

The surface covers symbol search, deep analysis, delayed prices, and market overview, which addresses the core domain well. Minor gaps exist โ€” no explicit watchlist management, news, or historical time-series retrieval โ€” but agents can work around these via the analysis tool.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues