StockMCP

StockMCP

Provides real-time stock market data and financial analysis through Yahoo Finance integration. Enables users to get quotes, historical prices, fundamentals, dividends, analyst forecasts, and growth projections for any stock symbol.

Category
访问服务器

README

📈 StockMCP

A comprehensive Model Context Protocol (MCP) server for real-time stock market data using Yahoo Finance

Python 3.10+ FastAPI License: MIT Tests

StockMCP provides a powerful, JSON-RPC 2.0 compliant interface for accessing comprehensive stock market data, built on the Model Context Protocol standard. Perfect for AI applications, financial analysis tools, and trading bots.

🌐 Free Hosted Endpoint

Use StockMCP immediately without any setup! We provide a free hosted endpoint at:

  • Endpoint: https://stockmcp.leoguerin.fr/mcp
  • No API key required - Just add to your MCP client configuration

Claude Desktop Configuration

For immediate access, use this configuration in your claude_desktop_config.json:

{
  "mcpServers": {
    "stock-mcp": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "https://stockmcp.leoguerin.fr/mcp",
        "--header",
        "--allow-http"
      ]
    }
  }
}

Configuration file locations:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\\Claude\\claude_desktop_config.json

🛠️ Available Tools

Tool Name Description
get_realtime_quote Retrieve current market data including price, volume, market cap, and key financial ratios
get_fundamentals Access comprehensive financial statements (income, balance sheet, cash flow) and calculated ratios
get_price_history Get historical OHLCV data with optional total return calculation including reinvested dividends
get_dividends_and_actions Analyze dividend payment history and corporate actions with quality metrics and consistency scoring
get_analyst_forecasts Get analyst price targets, consensus ratings (Buy/Hold/Sell), and EPS forecasts from professional analysts
get_growth_projections Forward growth projections for revenue, earnings (EPS), and free cash flow with 1-year, 3-year, and 5-year CAGR estimates

🚀 Quick Start

API Key Setup

  1. Get a free Alpha Vantage API key: Visit https://www.alphavantage.co/support/#api-key
  2. Configure environment:
    # Copy the example environment file
    cp .env.example .env
    
    # Edit .env and add your API key
    ALPHAVANTAGE_KEY=your-actual-api-key-here
    

Using Docker (Recommended)

# Clone the repository
git clone https://github.com/yourusername/StockMCP.git
cd StockMCP

# Configure your API key (see API Key Setup above)
cp .env.example .env
# Edit .env with your Alpha Vantage API key

# Build and run with Docker
docker build -t stockmcp .
docker run -p 3001:3001 --env-file .env stockmcp

Local Development

# Install dependencies with uv (fastest)
uv sync

# Or with pip
pip install -e .

# Configure your API key (see API Key Setup above)
cp .env.example .env
# Edit .env with your Alpha Vantage API key

# Run the server
python src/main.py
# Server runs on http://localhost:3001/mcp

MCP Client Integration

Once your server is running, integrate it with MCP clients:

Claude Desktop

Edit the configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json

Add this configuration:

{
  "mcpServers": {
    "stock-mcp": {
      "command": "npx",
      "args": [
        "mcp-remote",
        "http://localhost:3001/mcp",
        "--header",
        "--allow-http"
      ]
    }
  }
}

Cursor

Add to your MCP configuration:

{
  "stock-mcp": {
    "command": "npx",
    "args": [
      "mcp-remote",
      "http://localhost:3001/mcp",
      "--header",
      "--allow-http"
    ]
  }
}

Other MCP Clients

For any MCP-compatible client, use:

  • Endpoint: http://localhost:3001/mcp
  • Protocol: JSON-RPC 2.0 over HTTP
  • Tools: Available via tools/list method

🔗 Usage

StockMCP implements the Model Context Protocol (MCP) for seamless integration with AI applications. Once running, the server provides:

  • Endpoint: http://localhost:3001/mcp
  • Protocol: JSON-RPC 2.0 over HTTP
  • Discovery: Use tools/list to get available tools
  • Execution: Use tools/call to execute tools with parameters

For detailed API examples and JSON schemas, access the interactive documentation at http://localhost:3001/mcp/docs when the server is running.

🛠️ Development

Project Structure

StockMCP/
├── src/
│   ├── main.py              # FastAPI server and endpoints
│   ├── models.py            # Pydantic models for MCP and stock data
│   ├── mcp_handlers.py      # MCP protocol request handlers
│   ├── tools.py             # Tools package entry point
│   └── tools/               # Modular tools implementation
│       ├── market_data.py   # Real-time quotes, history, fundamentals
│       ├── analysis.py      # Forecasts and growth projections
│       └── registry.py      # Tool registration and execution
├── tests/                   # Comprehensive test suite (100 tests)
├── Dockerfile              # Container configuration
├── pyproject.toml          # Project dependencies and configuration
└── README.md              # This file

Running Tests

# Run all tests
uv run pytest

# Run with verbose output
uv run pytest -v

# Run specific test file
uv run pytest tests/test_api.py

# Run with coverage
uv run pytest --cov=src

Dependencies

Core Dependencies:

  • FastAPI - Modern web framework for APIs
  • Pydantic - Data validation using Python type hints
  • yfinance - Yahoo Finance data retrieval (primary data source)
  • pandas - Data manipulation and analysis
  • scipy - Scientific computing (required by yfinance)

Development Dependencies:

  • pytest - Testing framework
  • httpx - HTTP client for testing
  • pytest-mock - Mocking utilities

🐳 Docker Deployment

Build and Run

# Build the image
docker build -t stockmcp .

# Run the container
docker run -p 3001:3001 stockmcp

# Run in background
docker run -d -p 3001:3001 --name stockmcp-server stockmcp

Environment Configuration

The container exposes the API on port 3001 by default. You can customize this:

# Custom port mapping
docker run -p 8080:3001 stockmcp

# With environment variables
docker run -p 3001:3001 -e LOG_LEVEL=DEBUG stockmcp

🔧 Configuration

Server Configuration

The server can be configured through environment variables:

  • LOG_LEVEL - Logging level (DEBUG, INFO, WARNING, ERROR)
  • HOST - Server host (default: 0.0.0.0)
  • PORT - Server port (default: 3001)

API Limits & Data Sources

Primary Data Source: Yahoo Finance (yfinance)

  • Free tier with reasonable rate limits
  • Real-time and historical data
  • No API key required for basic usage

Secondary Data Source: Alpha Vantage (optional)

  • Enhanced earnings estimates and forecasts
  • Requires free API key for extended features
  • Graceful fallback when unavailable

Production Recommendations:

  • Implement request caching
  • Add retry logic with exponential backoff
  • Monitor API usage patterns
  • Consider data source redundancy

🤝 Contributing

We welcome contributions! Here's how to get started:

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Make your changes with proper tests
  4. Run the test suite (uv run pytest)
  5. Commit your changes (git commit -m 'Add amazing feature')
  6. Push to the branch (git push origin feature/amazing-feature)
  7. Open a Pull Request

Development Guidelines

  • Type Hints - All functions should have proper type annotations
  • Tests - New features must include comprehensive tests
  • Documentation - Update README and docstrings for any API changes
  • Code Style - Follow PEP 8 and use meaningful variable names

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

  • Yahoo Finance - For providing free stock market data
  • Model Context Protocol - For the excellent protocol specification
  • FastAPI - For the amazing web framework
  • Pydantic - For robust data validation

📞 Support

  • 🐛 Bug Reports - Open an issue
  • 💡 Feature Requests - Start a discussion
  • 📖 Documentation - Check our comprehensive API docs
  • 💬 Community - Join our discussions for help and ideas

<div align="center">

Made with ❤️ for the financial data community by Léo Guerin

⭐ Star this repo | 🍴 Fork it | 📖 Docs

</div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选