這是一個簡單封裝經典yFinance的工具,作為MCP工具運行。該工具主要用於獲取單個金融工具的每日股票價格,它將Pandas數據框返回給MCP主機,因此要求主機能夠理解此格式。此工具使用Goose作為MCP主機,Claude Sonnet 3.5作為集成的LLM編寫,可作為演示、起點或概念驗證。
🚀 快速開始
此工具在使用過程中,作者之前主要用它獲取單個金融工具的每日股票價格,但當要求LLM執行一些更復雜的聚合操作時,很快就遇到了Anthropic的token限制。
📦 安裝指南
在您的MCP主機中將其註冊為擴展。在Goose上進行如下操作:
☁ mcp-yfinance [main] ⚡ goose configure
這將更新您現有的配置文件
如果您願意,可以直接編輯位於 /home/nicholasf/.config/goose/config.yaml 的文件
┌ goose-configure
│
◇ What would you like to configure?
│ Add Extension
│
◇ What type of extension would you like to add?
│ Command-line Extension
│
◇ What would you like to call this extension?
│ yf
│
◇ What command should be run?
│ uv run server.py
│
◇ Please set the timeout for this tool (in secs):
│ 5
│
◇ Would you like to add environment variables?
│ No
│
└ Added yf extension
然後調用它:
☁ mcp-yfinance [main] ⚡ goose session -n yf
starting session | provider: anthropic model: claude-3-5-sonnet-latest
logging to /home/nicholasf/.local/share/goose/sessions/yf.jsonl
working directory: /home/nicholasf/code/github/nicholasf/mcp-yfinance
Goose is running! Enter your instructions, or try asking what goose can do.
( O)> yf__history AAPL
I'll try getting Apple's stock history now.
─── 歷史 | yf ──────────────────────────
symbol: AAPL
Great! The command is now working correctly. The data shows Apple's stock performance over the last month (from February 19, 2025 to March 18, 2025). Here are some key observations:
1. The stock has shown a general downward trend over this period
2. Starting price (Feb 19): Around $244.66
3. Latest price (March 18): Around $214.16
4. Highest point: Around $250.00 (Feb 25)
5. Notable decline: A sharp drop occurred around March 11, falling from ~$235 to ~$223
The data includes Open, High, Low, Close prices, Volume, Dividends, and Stock Splits (though no dividends or splits occurred during this period).
Would you like to:
1. See the data for a different time period?
2. Look at a different stock symbol?
3. Get more detailed analysis of specific aspects of this data?
Just let me know what information would be most helpful!
💻 使用示例
運行測試
pytest -v
⚠️ 重要提示
此工具將Pandas數據框返回給MCP主機,因此期望主機能夠理解此格式。
💡 使用建議
該工具旨在作為一個演示、起點或概念驗證,在使用過程中如果要求LLM執行一些更復雜的聚合操作,可能會遇到Anthropic的token限制。