股票交易分析器
STDIO股票交易技术分析工具服务器
股票交易技术分析工具服务器
A simplified Model Context Protocol (MCP) server for stock and cryptocurrency analysis. This version is optimized for learning with minimal configuration and clear code structure.
The server provides the following tools for market analysis:
analyze-stock: Performs technical analysis on a given stock symbol
symbol
(string, e.g. "NVDA")analyze-crypto: Performs technical analysis on cryptocurrency assets
symbol
(string, e.g. "BTC", "ETH", "BTCUSDT" for Binance)provider
(string, default: "tiingo", options: "tiingo", "binance")lookback_days
(integer, default: 365)quote_currency
(string, default: "usd" for Tiingo, "USDT" for Binance)relative-strength: Calculates a stock's relative strength compared to a benchmark
symbol
(string, e.g. "AAPL")benchmark
(string, default: "SPY")volume-profile: Analyzes volume distribution by price
symbol
(string, e.g. "MSFT")lookback_days
(integer, default: 60)detect-patterns: Identifies chart patterns in price data
symbol
(string, e.g. "AMZN")position-size: Calculates optimal position size based on risk parameters
symbol
(string, e.g. "TSLA")stop_price
(number)risk_amount
(number)account_size
(number)price
(number, default: current price)suggest-stops: Suggests stop loss levels based on technical analysis
symbol
(string, e.g. "META")The server now supports FastMCP resources for direct market data access:
stock://{symbol}
- Get current stock price and statisticsstock://{symbol}/history
- Get historical price datacrypto://{symbol}
- Get current crypto price (supports Tiingo & Binance)crypto://{symbol}/history
- Get historical crypto datamarket://cache/clear
- Clear the data cachemarket://cache/status
- View cache statisticsCreate a .env
file in your project root:
# MCP Trader # Copy this file to .env for API access # Tiingo API Key (free tier works great) # Get yours at: https://www.tiingo.com/ TIINGO_API_KEY=your_tiingo_api_key_here # Optional: For higher rate limits BINANCE_API_KEY=your_binance_api_key_here BINANCE_API_SECRET=your_binance_api_secret_here
# Clone the repository git clone https://github.com/wshobson/mcp-trader.git cd mcp-trader # Create virtual environment and install dependencies uv venv --python 3.11 source .venv/bin/activate # On Windows: .venv\Scripts\activate uv sync # Copy the example environment file cp .env.example .env # Edit .env and add your Tiingo API key
The configuration file location varies by platform:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%/Claude/claude_desktop_config.json
{ "mcpServers": { "stock-analyzer": { "command": "uv", "args": [ "--directory", "/absolute/path/to/mcp-trader", "run", "mcp-trader" ], "env": { "TIINGO_API_KEY": "your_api_key_here" } } } }
To enable FastMCP resources alongside the standard tools:
{ "mcpServers": { "stock-analyzer": { "command": "uv", "args": [ "--directory", "/absolute/path/to/mcp-trader", "run", "python", "-m", "mcp_trader.fastmcp_server" ], "env": { "TIINGO_API_KEY": "your_api_key_here" } } } }
The project includes a comprehensive test suite with 80% code coverage:
# Run all tests pytest # Run with coverage report pytest --cov=src/mcp_trader --cov-report=term-missing # Run specific test file pytest src/mcp_trader/tests/test_indicators.py # Run with verbose output pytest -v
Runs the MCP server with all tools:
uv run mcp-trader
For development and debugging:
# Run with Python directly uv run python -m mcp_trader.server # Run with MCP Inspector for debugging npx @modelcontextprotocol/inspector uv --directory . run mcp-trader
# Build the Docker image docker build -t mcp-trader . # Run the container docker run -e TIINGO_API_KEY=your_api_key_here -p 8000:8000 mcp-trader # Run in HTTP server mode docker run -e TIINGO_API_KEY=your_api_key_here -p 8000:8000 mcp-trader uv run mcp-trader --http
In Claude Desktop, simply ask:
Analyze the technical setup for NVDA
The server will return a comprehensive technical analysis including trend status, momentum indicators, and key metrics.
For crypto analysis:
Analyze BTC using Binance data
mcp-trader/
├── src/mcp_trader/
│ ├── __init__.py # Package initialization
│ ├── server.py # Main MCP server (simplified)
│ ├── config.py # Simple configuration dataclass
│ ├── models.py # Pydantic models for type safety
│ ├── data.py # Market data providers
│ ├── indicators.py # Technical analysis calculations
│ └── tests/ # Comprehensive test suite
├── .env.example # Example environment configuration
├── pyproject.toml # Project dependencies
└── README.md # This file
"TIINGO_API_KEY not set" error
.env.example
to .env
.env
fileTest failures
uv sync
pytest -v
Import errors
source .venv/bin/activate
uv sync --force-reinstall
Core dependencies:
Optional:
See pyproject.toml for the complete list.
server.py
: The main entry point showing how MCP tools are definedmodels.py
: Learn about type-safe request/response handling with Pydanticindicators.py
: See how technical analysis calculations are implementedContributions that improve clarity and learning are especially welcome:
Learn more about this project:
This project is licensed under the MIT License - see the LICENSE file for details.