关于 yfinance-mcp-server
yfinance-mcp-server 是一个非官方 MCP 服务,通过 yfinance 获取 Yahoo Finance 股票数据,面向需要在 MCP 客户端中查询行情的用户。它提供可配置周期和间隔的历史数据查询工具。
主要功能
- 01查询股票历史数据
- 02配置数据周期与间隔
- 03兼容 MCP 客户端
- 04使用 TypeScript 构建
适用场景
- 01查看指定股票的历史行情
- 02按日、周或月间隔获取数据
MCP 相关
该服务向 MCP 客户端提供 getStockHistory 工具,用于获取指定股票代码的历史数据。
配置
本地服务的配置在各客户端中通用,复制后粘贴到客户端的 MCP 配置文件即可。
工具
1收录的工具列表 · 更新于 2 周前
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| period | string | 是 | |
| symbol | string | 是 | |
| interval | enum | 否 | 1d | 1wk | 1mo |
详细介绍
yfinance-mcp-server
重要说明:这是一个非官方的 MCP 服务。
一个用于访问 Yahoo Finance 数据的消息控制协议(MCP)服务。此服务通过 yfinance 提供简单的接口来获取股票市场数据。
功能
- 获取历史股票数据,并可自定义时间段和间隔
- 可轻松与任何 MCP 客户端搭配使用
- 使用 TypeScript 构建,确保类型安全并改善开发体验
用法
Cursor MCP 客户端示例。
{
"mcpServers": {
"yfinance": {
"command": "npx",
"args": [
"@onori/yfinance-mcp-server"
]
}
}
}
getStockHistory
获取指定股票代码的历史股票数据。
参数:
symbol(必填):股票代码(例如,Apple Inc. 的代码为 "AAPL")period(必填):要获取数据的时间段(例如,"1d"、"5d"、"1mo"、"3mo"、"6mo"、"1y"、"2y"、"5y"、"10y"、"ytd"、"max")interval(可选):数据间隔("1d"、"1wk"、"1mo")
MCP 请求示例:
> (Request)
Please use the `getStockHistory` tool to fetch the daily stock data for AAPL for the past week (`period`='1w', `interval`='1d'). Then, render the results as a markdown table.
> (Response Example)
I'll help you fetch Apple's stock data and format it nicely as a markdown table.
First, I'll call the getStockHistory tool to fetch the data:
Let me format this data into a more readable markdown table:
| Date | Open | High | Low | Close | Volume |
|------|------|------|-----|-------|---------|
| Mar 31, 2025 | $217.01 | $225.62 | $216.23 | $222.13 | 65.30M |
| Apr 1, 2025 | $219.81 | $223.68 | $218.90 | $223.19 | 36.41M |
| Apr 2, 2025 | $221.32 | $225.19 | $221.02 | $223.89 | 35.91M |
| Apr 3, 2025 | $205.54 | $207.49 | $201.25 | $203.19 | 103.42M |
| Apr 4, 2025 | $193.89 | $199.88 | $187.34 | $188.38 | 125.57M |
Some notable observations from this data:
- The stock showed significant volatility over this period
- There was a sharp decline in the last two trading days
- Trading volume increased substantially during the declining days, with the highest volume (125.57M shares) on April 4th
- The stock price range was from a high of $225.62 to a low of $187.34 during this period
Would you like any specific analysis of this data or would you like to see different metrics?
开发
设置开发环境:
- 克隆仓库
- 安装依赖:
npm install
- 启动开发服务器:
npm run dev
贡献
欢迎贡献!欢迎提交 Pull Request。
许可证
ISC 许可证(ISC)
评论
支持 Markdown
一个开放协议,规定了 AI 应用如何以统一方式连接外部工具与数据源。客户端负责与模型对话,MCP 服务负责提供工具、资源和提示模板,两者通过标准消息通信,同一个服务可以被不同客户端复用。