一个通过Yahoo Finance提供实时股票数据和期权分析的模型上下文协议(MCP)服务器。使大型语言模型能够访问市场数据、分析股票并评估期权策略。
# 安装依赖
pip install mcp yfinance
# 克隆仓库
git clone https://github.com/twolven/stockflow
cd stockflow
git clone https://github.com/twolven/mcp-stockflow.git
cd mcp-stockflow
pip install -r requirements.txt
claude-desktop-config.json文件中,在mcpServers部分添加以下内容:{
"mcpServers": {
"stockflow": {
"command": "python",
"args": ["path/to/stockflow.py"]
}
}
}
将"path/to/stockflow.py"替换为你保存stockflow.py文件的实际路径。
当你与Claude一起工作时,可以使用以下提示帮助它理解可用工具:
“我已经启用了stockflow工具,这让你能够访问股市数据。你可以使用这三个主要功能:
get_stock_data - 获取综合股票信息:{
"symbol": "AAPL",
"include_financials": true, # 可选
"include_analysis": true, # 可选
"include_calendar": true # 可选
}
get_historical_data - 获取价格历史和技术指标:{
"symbol": "AAPL",
时期: "1y", # 1d, 5d, 1mo, 3mo, 6mo, 1y, 2y, 5y, 10y, ytd, max
间隔: "1d", # 1m, 2m, 5m, 15m, 30m, 60m, 90m, 1h, 1d, 5d, 1wk, 1mo, 3mo
prepost: false # 可选 - 包含盘前/盘后数据
}
get_options_chain - 获取期权数据:{
"symbol": "AAPL",
到期日: "2024-12-20", # 可选 - 如果未指定则使用最近日期
include_greeks: true # 可选
}
所有响应都包含当前价格数据、错误处理和全面的市场信息。”
python stockflow.py
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(
command="python",
args=["stockflow.py"]
)
async def run():
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
# 获取当前股票数据
result = await session.call_tool(
"get-stock-data",
arguments={"symbol": "AAPL"}
)
# 获取期权链
options = await session.call_tool(
"get-options-chain",
arguments={
"symbol": "AAPL",
"expiration_date": "2024-12-20"
}
)
if __name__ == "__main__":
import asyncio
asyncio.run(run())
get-stock-data
get-historical-data
get-options-chain
company-info://{symbol}
financials://{symbol}
analyze-options
欢迎贡献!请随时提交Pull Request。
本项目根据MIT许可证发布 - 查看LICENSE文件以获取详细信息。
Todd Wolven - (https://github.com/twolven)