TradingAssistantMCP
TradingAssistantMCP
学習用プロジェクトです。エージェント(例: Claude)が株価データを取得し、最終的にはバックテストやカスタム取引戦略を実行できるようにするMCP(Model Context Protocol)サーバーです。
セットアップ
Python 3.11+ が必要です。現時点ではAPIキーは不要です(現在のツールはyfinanceを使用しており、サインアップは不要です)。
python3 -m venv .venv
.venv/bin/pip install -e .これにより .venv/ 内に分離された環境が作成され、このプロジェクトの依存関係がインストールされます。.venv/ はgitignoreされているため、このリポジトリをクローンした人は、何かを動かす前に自分でこの2つのコマンドを実行する必要があります。
Related MCP server: Yahoo Finance MCP Server
サーバーの実行
サーバー(src/trading_assistant_mcp/server.py)は、あなたが直接実行するためのものではなく、MCPクライアント(エージェント)がstdio経由で起動するためのものです。試す方法は2つあります。
1. MCP Inspector(手動テスト用、エージェント不要)— ツールを直接呼び出すためのブラウザUIです。
.venv/bin/mcp dev src/trading_assistant_mcp/server.pyローカルURL(例: http://127.0.0.1:6274)が開きます。Connectをクリックし、Toolsタブに移動して、ツールを手動で呼び出します。
uvのインストールが必要です(mcp devは内部でuv runを介してサーバーを起動するため、上記のvenvは関係ありません)。
2. Claude Code(実際のエージェント)— .mcp.json にプロジェクトスコープのMCPサーバーとして登録されています。このディレクトリでClaude Codeセッションを開き、「AAPLの価格は?」のような質問をするだけで、Claudeがツールを呼び出すかどうかを自分で判断します。
移植性に関する注意:
.mcp.jsonにはこのマシンの.venv/bin/pythonへの絶対パスがハードコードされています。このリポジトリを別の場所にクローンした場合は、以下を再実行してください:claude mcp add -s project trading-assistant -- /absolute/path/to/.venv/bin/python /absolute/path/to/src/trading_assistant_mcp/server.py
現在の機能
get_quote(symbol)— 株式ティッカーの現在価格、日中レンジ、出来高。
プロジェクト構成
src/trading_assistant_mcp/
├── server.py # MCP server: wraps data functions as tools
├── data/
│ └── yfinance_client.py # plain Python, no MCP dependency — reusable/testable on its own
└── analysis/ # reserved for indicators (SMA/EMA/RSI/MACD), not yet builtserver.py は意図的に薄いアダプターになっています。mcp をインポートする唯一のファイルです。データ取得や(将来的な)分析ロジックはプレーンなPythonモジュールに保持され、プロトコル層から独立してテスト可能かつ再利用可能になっています。
ロードマップ
バックテストやカスタム自然言語戦略(例:「AMDが1%下がるたびに買い、5%上がるたびに売る」)の前に、現在のデータ分析(ローソク足、ファンダメンタルズ/指標、テクニカル指標)を行います。完全な計画はプロジェクトの決定事項を参照してください。
Available Tools
4 toolsget_candlesA
Get historical OHLCV candlestick bars for a stock symbol.
Args: symbol: Stock ticker symbol, e.g. "AAPL" or "MSFT". period: How far back to fetch, e.g. "1mo", "3mo", "6mo". interval: Bar size, e.g. "1h", "1d".
Inputs: symbol (required), period, interval. Returns: result
get_fundamentalsA
Get valuation/financial ratios for a stock symbol (P/E, market cap, EPS, dividend yield, beta, 52-week range, margins, growth, etc.).
Fields may be null if not available for a given symbol/exchange.
Args: symbol: Stock ticker symbol, e.g. "AAPL" or "MSFT".
Inputs: symbol (required).
get_quoteA
Get the current price and day range for a stock symbol.
Args: symbol: Stock ticker symbol, e.g. "AAPL" or "MSFT".
Inputs: symbol (required).
get_technical_indicatorsA
Compute standard technical indicators (SMA-20/50, RSI-14, MACD, Bollinger Bands, ATR-14, volume vs its 20-period average) for a stock symbol.
Fetches its own candle data internally (not via get_candles - that tool's raw output is too large to round-trip through a tool call). Needs at least 50 candles for every indicator to be non-null (fewer still works, but indicators requiring more history than is available return null).
Args: symbol: Stock ticker symbol, e.g. "AAPL" or "MSFT". period: How far back to fetch, e.g. "1mo", "3mo", "6mo". interval: Bar size, e.g. "1h", "1d".
Inputs: symbol (required), period, interval.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool targets a distinct data domain: real-time quote, fundamentals, historical OHLCV, and computed indicators. Descriptions clearly separate concerns, so an agent should not confuse them.
All tools follow a consistent get_<noun> pattern with snake_case naming. The naming convention is uniform and predictable across the entire set.
Four tools is a focused, well-scoped set for a market-data-only server. Each tool covers a meaningful and non-redundant aspect of stock research.
The set covers the core read-only stock data needs: real-time price, fundamentals, historical price data, and technical indicators. Minor gaps exist, such as no symbol search/disambiguation or batch quote support, but these are workable around.
Maintenance
Related MCP Connectors
Live stock quotes, a stock screener, crypto prices and FX rates as agent tools.
Yahoo Finance stock quotes and multi-ticker comparison as agent tools.
Yahoo Finance for AI agents: quotes, price history, options with Greeks, financials, news, movers.
Live crypto + IDX stock market intelligence for AI agents — 19 tools, no API key.
Related MCP Servers
- FlicenseCqualityDmaintenanceEnables LLMs to retrieve real-time stock and cryptocurrency prices and news using ticker symbols through the yfinance API.25-
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to retrieve stock market data and financial information from Yahoo Finance using the yfinance Python library. Supports querying stock prices, historical data, and other financial metrics through natural language.MIT
- AlicenseNot gradedqualityCmaintenanceProvides real-time stock quotes, historical data, and stock search via Yahoo Finance, enabling AI assistants to access and analyze financial market data.24 npm19MIT
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to access real-time stock, crypto, and market index data from Yahoo Finance, supporting queries for prices, history, company info, and comparisons.MIT