gaforov/mcp-stock-server
If you are the rightful owner of mcp-stock-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.
The MCP Stock Query System is a stock data retrieval system that leverages the Model Context Protocol (MCP) to provide real-time stock prices using natural language queries.
MCP Stock Query System
A stock data retrieval system built on the Model Context Protocol (MCP) with natural language query parsing. Get real-time stock prices from Yahoo Finance with a simple CLI interface.
✨ Features
- 🔍 Natural Language Queries - Just type "price of Apple" or "AAPL"
- 📊 Real-time Data - Live stock prices from Yahoo Finance
- 🛡️ CSV Fallback - Works offline with local stock data
- 🆓 No API Keys - Works out of the box
- ⚡ Async Processing - Fast, non-blocking operations
🚀 Quick Start
# Clone the repository
git clone https://github.com/YOUR_USERNAME/mcp-stock-server.git
cd mcp-stock-server
# Install dependencies
pip install -r requirements.txt
# Run the client
python mcp_client.py
📋 Requirements
- Python 3.10+
- Internet connection (optional - CSV fallback available)
💬 Usage Examples
📊 Stock Query → AAPL
Stock: AAPL
Price: $286.10
Source: Yahoo Finance
📊 Stock Query → Compare Apple and Microsoft
AAPL ($286.10) is lower than MSFT ($481.22)
Difference: $195.12 (68.21%)
📊 Stock Query → What's the price of Tesla?
Company: Tesla, Inc.
Stock: TSLA
Price: $352.56
Source: Yahoo Finance
🏗️ Architecture
┌─────────────────┐ stdio ┌─────────────────┐
│ mcp_client.py │ ◄────────────► │ mcp_server.py │
│ (User Input) │ │ (Stock Tools) │
└─────────────────┘ └─────────────────┘
│
▼
┌────────────────────────┐
│ Yahoo Finance API │
│ (or CSV fallback) │
└────────────────────────┘
🛠️ Available Tools
| Tool | Description | Example |
|---|---|---|
get_stock_price | Get current price for a symbol | "AAPL", "price of Microsoft" |
compare_stocks | Compare two stock prices | "compare AAPL and MSFT", "TSLA vs NVDA" |
📁 File Structure
mcp-stock-server/
├── mcp_client.py # Interactive CLI client
├── mcp_server.py # MCP server with stock tools
├── stocks_data.csv # Fallback stock data
├── requirements.txt # Python dependencies
└── README.md
🔧 Configuration
No configuration needed! The system:
- Auto-detects the project directory
- Uses the current Python interpreter
- Falls back to CSV if Yahoo Finance is unavailable
Adding More Stocks to CSV Fallback
Edit stocks_data.csv:
symbol,price,last_updated
NEWSTOCK,123.45,2024-12-03
❓ Troubleshooting
| Issue | Solution |
|---|---|
| "Could not retrieve price" | Check symbol spelling, or add to stocks_data.csv |
| "Couldn't understand query" | Use simpler format: "AAPL" or "price of Apple" |
| Yahoo Finance errors | System auto-falls back to CSV data |
| Import errors | Run pip install -r requirements.txt |
📦 Dependencies
- mcp[cli] - Model Context Protocol framework
- yfinance - Yahoo Finance API wrapper
📄 License
MIT License - feel free to use and modify!
Note: This is a simplified demo that uses pattern matching instead of AI for query parsing, making it lightweight and free to run.