返回市场
雅虎财经服务器

雅虎财经服务器

作者:AgentX-ai6 星标更新:2025-07-23

项目介绍

Yahoo Finance MCP 服务器

网站 Discord

📈 一个让您的AI与Yahoo Finance互动的模型上下文协议(MCP)服务器 - 获取全面的股市数据、新闻、财务信息等。

✨ 特性

  • 📊 股票数据 - 获取包括公司详情、财务信息和交易指标在内的综合股票信息
  • 📰 新闻推送 - 获取与特定股票代码相关的最新新闻文章
  • 🔍 搜索 - 查找股票、ETF和其他金融工具及其相关新闻结果
  • 🏆 顶级实体 - 按行业获取表现最佳的公司、ETF和共同基金
  • 📈 价格历史 - 获取可定制时间段和间隔的历史价格数据
  • 期权链 - 获取包括认购和认沽在内的股票期权链数据
  • 💰 收益 - 访问包括即将发布的收益日期在内的收益数据
  • 🌐 代理支持 - 支持HTTP/HTTPS/SOCKS代理
  • 🚀 快速且异步 - 使用asyncio进行非阻塞操作
  • 🔧 易于集成 - 标准MCP协议用于AI助手

🚀 快速开始

预备条件

  • Python 3.11或更高版本
  • pip或uvx包管理器
  • (可选)代理服务器以提高可靠性

安装

使用uvx(推荐)

# 带命名空间安装
uvx yahoo-finance-server

使用pip

pip install yahoo-finance-server

从源码安装

git clone https://github.com/AgentX-ai/AgentX-mcp-servers.git
cd AgentX-mcp-servers/yahoo_finance_server
pip install -e .

配置

代理设置(推荐)

为了提高可靠性和避免速率限制,请设置代理:

# HTTP/HTTPS代理
export PROXY_URL="http://proxy.example.com:8080"

# 带认证的SOCKS代理
export PROXY_URL="socks5://user:pass@127..0.0.1:1080/"

运行服务器

# 基本运行
yahoo-finance-server

# 使用代理运行
PROXY_URL="http://127.0.0.1:7890" yahoo-finance-server

🛠️ API参考

可用工具

1. get-ticker-info

获取包括公司详情、财务信息和交易指标在内的综合股票信息。

{
  "name": "get-ticker-info",
  "arguments": {
    "symbol": "AAPL"
  }
}

2. get-ticker-news

获取特定股票代码的最新新闻文章。

{
  "name": "get-ticker-news",
  "arguments": {
    "symbol": "AAPL",
    "count": 10
  }
}

3. search

搜索股票、ETF和其他金融工具及其相关新闻。

{
  "name": "search",
  "arguments": {
    "query": "Apple Inc",
    "count": 10
  }
}

4. get-top-entities

获取某个行业的顶级实体。

{
  "name": "get-top-entities",
  "arguments": {
    "entity_type": "companies", // 选项:"etfs", "mutual_funds", "companies", "growth_companies", "performing_companies"
    "sector": "technology", // 查看支持的行业列表
    "count": 10
  }
}

支持的行业:

  • basic-materials
  • communication-services
  • consumer-cyclical
  • consumer-defensive
  • energy
  • financial-services
  • healthcare
  • industrials
  • real-estate
  • technology
  • utilities

5. get-price-history

获取可定制时间段和间隔的历史价格数据。

{
  "name": "get-price-history",
  "arguments": {
    "symbol": "AAPL",
    "period": "1y", // 选项:1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max
    "interval": "1d" // 选项:1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo
  }
}

6. ticker-option-chain

获取股票的期权链数据。

{
  "name": "ticker-option-chain",
  "arguments": {
    "symbol": "AAPL",
    "option_type": "call", // 选项:"call", "put", "both"
    "date": "2024-01-19" // 可选:YYYY-MM-DD 格式
  }
}

7. ticker-earning

获取包括历史和即将发布的收益数据。

{
  "name": "ticker-earning",
  "arguments": {
    "symbol": "AAPL",
    "period": "annual", // 选项:"annual", "quarterly"
    "date": "2023-12-31" // 可选:YYYY-MM-DD 格式
  }
}

🧪 测试

使用MCP Inspector

npx @modelcontextprotocol/inspector yahoo-finance-server

手动测试

python -c "
import asyncio
from yahoo_finance_server.helper import get_ticker_info

async def test():
    info = await get_ticker_info('AAPL')
    print(f'✅ 股票: {info[\"longName\"]}')

asyncio.run(test())
"

📋 要求

  • Python 3.11+
  • yfinance==0.2.62
  • requests>=2.31.0
  • pandas>=2.0.0
  • mcp>=1.9.3

🤝 贡献

  1. 分叉仓库
  2. 创建功能分支
  3. 修改代码
  4. 添加测试
  5. 提交拉取请求

📄 许可证

MIT 许可证 - 详情见LICENSE文件。

🔗 链接


为金融社区制作 ❤️