Stock Data MCP Server

Stock Data MCP Server

Provides real-time stock market data through Yahoo Finance without requiring an API key. Get quotes, historical data, company information, financial statements, and ticker search capabilities.

Category
访问服务器

README

Stock Data MCP Server

A Model Context Protocol (MCP) server that provides real-time stock market data through Yahoo Finance without requiring an API key. Get quotes, historical data, company information, financial statements, and more.

Features

  • 🔍 Real-time Stock Quotes - Current prices, changes, volume, and market data
  • 📊 Historical Data - OHLCV data with customizable periods and intervals
  • 🏢 Company Information - Detailed company profiles, sectors, and metrics
  • 💰 Financial Statements - Income statements, balance sheets, and cash flow
  • 🔎 Ticker Search - Find ticker symbols by company name
  • 🆓 No API Key Required - Uses public Yahoo Finance data via yfinance
  • 🚀 Railway Ready - Deploy to Railway.app with one click

Available Tools

1. get_stock_quote

Get current stock price and trading data.

Parameters:

  • symbol (string, required): Stock ticker symbol (e.g., "AAPL", "MSFT")
  • response_format (string, optional): "markdown" or "json" (default: "markdown")

Example:

{
  "symbol": "AAPL",
  "response_format": "markdown"
}

2. get_stock_info

Get comprehensive company information and metrics.

Parameters:

  • symbol (string, required): Stock ticker symbol
  • response_format (string, optional): "markdown" or "json"

Example:

{
  "symbol": "TSLA",
  "response_format": "json"
}

3. get_stock_history

Get historical price and volume data.

Parameters:

  • symbol (string, required): Stock ticker symbol
  • period (string, optional): "1d", "5d", "1mo", "3mo", "6mo", "1y", "2y", "5y", "10y", "ytd", "max" (default: "1mo")
  • interval (string, optional): "1m", "5m", "1h", "1d", "1wk", "1mo", etc. (default: "1d")
  • response_format (string, optional): "markdown" or "json"

Example:

{
  "symbol": "NVDA",
  "period": "6mo",
  "interval": "1d",
  "response_format": "json"
}

4. get_stock_financials

Get company financial statements.

Parameters:

  • symbol (string, required): Stock ticker symbol
  • statement_type (string, optional): "income", "balance", "cashflow" (default: "income")
  • quarterly (boolean, optional): true for quarterly, false for annual (default: false)
  • response_format (string, optional): "markdown" or "json"

Example:

{
  "symbol": "GOOGL",
  "statement_type": "income",
  "quarterly": false,
  "response_format": "markdown"
}

5. search_ticker

Search for ticker symbols by company name.

Parameters:

  • query (string, required): Company name or partial name
  • response_format (string, optional): "markdown" or "json"

Example:

{
  "query": "Apple",
  "response_format": "json"
}

Local Development

Prerequisites

  • Python 3.11 or higher
  • pip

Installation

  1. Clone this repository:
git clone <your-repo-url>
cd stock-mcp-server
  1. Install dependencies:
pip install -r requirements.txt
  1. Run the server locally (stdio mode):
python stock_mcp.py --transport stdio

Testing with MCP Inspector

npx @modelcontextprotocol/inspector python stock_mcp.py

This opens a web interface where you can test all the tools interactively.

Railway Deployment

Quick Deploy

  1. Push to GitHub:
git init
git add .
git commit -m "Initial commit"
git remote add origin <your-github-repo>
git push -u origin main
  1. Deploy to Railway:

    • Go to railway.app
    • Click "New Project" → "Deploy from GitHub repo"
    • Select your repository
    • Railway will automatically detect the Dockerfile and deploy
  2. Get Your Server URL:

    • Once deployed, Railway provides a public URL like: https://your-app.railway.app
    • Copy this URL for Claude Desktop configuration

Environment Variables

No environment variables required! This server doesn't need API keys because it uses public Yahoo Finance data.

Railway automatically sets the PORT variable - don't override it.

Claude Desktop Integration

After deploying to Railway, add this to your Claude Desktop config:

Config location:

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

Configuration:

{
  "mcpServers": {
    "stock-data": {
      "url": "https://your-app.railway.app",
      "transport": "streamable-http"
    }
  }
}

Replace your-app.railway.app with your actual Railway URL.

Restart Claude Desktop after saving the configuration.

Docker Usage

Build the Image

docker build -t stock-mcp-server .

Run Locally

docker run -p 8080:8080 -e PORT=8080 stock-mcp-server

Test the Server

# Health check
curl http://localhost:8080

# List available tools
curl -X POST http://localhost:8080/mcp \
  -H "Content-Type: application/json" \
  -d '{"jsonrpc":"2.0","method":"tools/list","params":{},"id":1}'

Usage Examples

Get Apple Stock Quote

Request to Claude:

"What's the current price of Apple stock?"

Behind the scenes: Claude calls get_stock_quote with {"symbol": "AAPL"}

Analyze Tesla Financials

Request to Claude:

"Show me Tesla's latest income statement"

Behind the scenes: Claude calls get_stock_financials with {"symbol": "TSLA", "statement_type": "income"}

Compare Historical Performance

Request to Claude:

"Compare the 6-month performance of NVIDIA and AMD"

Behind the scenes: Claude calls get_stock_history multiple times and analyzes the data

Troubleshooting

"Unable to fetch data for symbol"

  • Verify the ticker symbol is correct
  • Use search_ticker to find the right symbol
  • Some international stocks may not be available

Railway Deployment Issues

  • Check Railway logs in the dashboard
  • Verify the Dockerfile builds successfully locally
  • Ensure you're not setting the PORT environment variable manually

Claude Desktop Connection Issues

  1. Verify the URL has no trailing slash
  2. Confirm transport is set to "streamable-http"
  3. Check Claude Desktop logs (Help → View Logs)
  4. Restart Claude Desktop after config changes

Data Source

This server uses yfinance, an open-source library that retrieves data from Yahoo Finance. The data is provided for informational purposes only and should not be used for trading decisions without verification.

Data Limitations:

  • Real-time data may have a 15-20 minute delay
  • Some international stocks may have limited data
  • Historical data availability varies by symbol
  • Financial statements may not be available for all companies

Architecture

Transport: SSE (Server-Sent Events) for Railway, stdio for local development Framework: FastMCP (MCP Python SDK) Data Validation: Pydantic v2 Stock Data: yfinance (Yahoo Finance API wrapper)

License

MIT License - See LICENSE file for details

Contributing

Contributions welcome! Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

Support

For issues or questions:

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选