Skip to main content
Glama

Yahoo Finance MCP for LLaMA 3.2 3B

by Shak2000

雅虎财经模型上下文协议 (MCP),适用于 LLaMA 3.2 3B

此代码库包含一个模型上下文协议 (MCP) 实现,它将雅虎财经 API 与 LLaMA 3.2 3B 集成。MCP 允许模型检索实时财务数据、股票信息和市场新闻,同时保留 LLaMA 的所有常规功能。

特征

  • 在 LLaMA 3.2 3B 中直接获取实时股票价格
  • 检索详细的公司信息(部门、行业、市值等)
  • 获取具有可自定义时间段和间隔的历史股票数据
  • 获取最新市场新闻头条
  • 无缝增强 LLaMA 的功能,且不干扰非财务查询

要求

  • Python 3.8+
  • Ollama - 用于本地运行 LLaMA 3.2 3B
  • LLaMA 3.2 3B 型号拉入 Ollama
  • Python 包:
    • 奥拉马
    • yfinance
    • 请求
    • 熊猫

安装

  1. https://ollama.ai/安装 Ollama
  2. 使用 Ollama 拉取 LLaMA 3.2 3B 模型:
    ollama pull llama3.2:3b
  3. 克隆此存储库:
    git clone <repository-url> cd mcp_yahoo_finance
  4. 安装所需的 Python 依赖项:
    pip install -r requirements.txt

用法

使用 Ollama 集成运行 MCP

要通过 Ollama 将 Yahoo Finance MCP 与 LLaMA 3.2 3B 结合使用:

python mcp_ollama_integration.py

这将启动一个交互式会话,您可以在其中:

  • 提出财务问题,这些问题将通过雅虎财经数据得到丰富
  • 询问任何其他问题,这些问题通常会由 LLaMA 3.2 3B 处理

示例查询

财务查询(通过雅虎财经数据增强)
  • “苹果股票的当前价格是多少?”
  • “跟我讲讲特斯拉这家公司吧”
  • “微软的股票在过去一个月表现如何?”
  • “最新的市场新闻标题是什么?”
  • “亚马逊的 52 周最高价是多少?”
  • “Nvidia 从事哪个行业?”
  • “标准普尔 500 指数今年的表现如何?”
非财务查询(通常由 LLaMA 处理)
  • “法国的首都是哪里?”
  • “解释量子计算”
  • “写一首关于秋天的诗”
  • “勾股定理是什么?”

使用不同的LLaMA模型

您可以使用--model参数指定不同的模型:

python mcp_ollama_integration.py --model llama3.2:8b

工作原理

  1. MCP 分析每个用户查询以确定其是否与财务相关
  2. 对于财务查询,它:
    • 确定要调用的相关财务功能(价格、信息、历史、新闻)
    • 通过 MCP 调用 Yahoo Finance API
    • 格式化实时数据并将其作为上下文提供给 LLaMA 3.2 3B
    • LLaMA 3.2 3B 结合财务数据提供自然的响应
  3. 对于非财务查询,它会直接将其传递给 LLaMA 3.2 3B,无需修改

这种方法无缝增强了 LLaMA 的实时财务数据功能,同时保留了其所有原有的功能。

高级用法

直接 API 函数

如果您想在代码中直接使用 Yahoo Finance MCP 函数:

from yahoo_finance_mcp import YahooFinanceMCP # Initialize the MCP mcp = YahooFinanceMCP() # Get stock price price_data = mcp.execute_function("get_stock_price", {"symbol": "AAPL"}) # Get company information company_data = mcp.execute_function("get_stock_info", {"symbol": "TSLA"}) # Get historical data history_data = mcp.execute_function("get_stock_history", {"symbol": "MSFT", "period": "1mo"}) # Get market news news_data = mcp.execute_function("get_market_news", {"limit": 5})

故障排除

  • “连接 Ollama 时出错” :请确保 Ollama 已安装并正在运行
  • 未找到公司:请尝试使用官方股票代码代替公司名称
  • 未找到 LLaMA 3.2 3B 模型:运行ollama pull llama3.2:3b下载模型

致谢

该项目使用yfinance库检索雅虎财经数据,并使用Ollama在本地运行 LLaMA 3.2 3B。

-
security - not tested
F
license - not found
-
quality - not tested

local-only server

The server can only run on the client's local machine because it depends on local resources.

将雅虎财经 API 与 LLaMA 3.2 3B 集成,允许用户检索实时股票价格、公司信息、历史数据和市场新闻,同时保留模型的原有功能。

  1. 特征
    1. 要求
      1. 安装
        1. 用法
          1. 使用 Ollama 集成运行 MCP
          2. 示例查询
          3. 使用不同的LLaMA模型
        2. 工作原理
          1. 高级用法
            1. 直接 API 函数
          2. 故障排除
            1. 致谢

              Related MCP Servers

              • -
                security
                A
                license
                -
                quality
                Provides comprehensive stock screening capabilities through Yahoo Finance. Enables LLMs to screen stocks based on technical, fundamental, and options criteria, with support for watchlist management and result storage.
                Last updated -
                13
                Python
                MIT License
              • -
                security
                A
                license
                -
                quality
                A Model Context Protocol server providing real-time stock data and options analysis through Yahoo Finance, enabling LLMs to access market data, analyze stocks, and evaluate options strategies.
                Last updated -
                4
                Python
                MIT License
              • -
                security
                F
                license
                -
                quality
                Provides access to real-time and historical Indian stock data via Yahoo Finance API, enabling local LLMs to retrieve stock information through MCP-compatible agents like Claude Desktop and Cursor.
                Last updated -
                TypeScript
              • A
                security
                A
                license
                A
                quality
                A Model Context Protocol server that enables interaction with Yahoo Finance to retrieve stock pricing, company information, and historical financial data through natural language queries.
                Last updated -
                9
                2
                Python
                MIT License

              View all related MCP servers

              MCP directory API

              We provide all the information about MCP servers via our MCP API.

              curl -X GET 'https://glama.ai/api/mcp/v1/servers/Shak2000/StockMCP'

              If you have feedback or need assistance with the MCP directory API, please join our Discord server