股票分析工具

一款基于FastMCP和LangGraph的股票分析工具,通过Model Context Protocol (MCP)提供实时市场数据分析,适用于金融投资和技术分析场景。

  • by aravind1808v
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 aravind1808v/mcp-stock-picker

使用说明

MCP库存分析仪

基于以下内容构建的股票分析工具 FastMCP 和 LangGraph.通过公开市场数据工具 模型上下文协议(MCP),让任何兼容MCP的主机(Cursor、Claude Desktop等)直接从聊天中调用实时股票分析。

它的作用

  • 获取 价格历史, 财务数据,以及 新闻 从 Polygon.io
  • 计算 50天SMA 本地技术信号
  • 运行a LangGraph代理 它将所有信号组合成一个 BUY / HOLD / SELL 按驾驶员细分进行评级

建筑

MCP Host (Cursor / Claude Desktop)
    └── FastMCP Server  (mcp_server.py)
            ├── price_history  → Polygon /v2/aggs
            ├── financials     → Polygon /vX/reference/financials
            ├── news           → Polygon /v2/reference/news
            ├── sma            → local computation over price history
            └── short_interest → placeholder (bring your own provider)

LangGraph Agent  (agent.py)
    ├── fetch_all  – calls all MCP tools in parallel
    └── decide     – deterministic scoring → BUY / HOLD / SELL

先决条件

  • Python 3.11+
  • uv 包管理器
  • 自由的 Polygon.io API密钥

设置

# 1. Clone the repo
git clone https://github.com/aravind1808v/MCP-Stocks.git
cd MCP-Stocks

# 2. Install dependencies
uv sync

# 3. Set your API key
export POLYGON_API_KEY=your_key_here
# or create a .env file:
echo "POLYGON_API_KEY=your_key_here" > .env

运行MCP服务器

uv run python mcp_server.py

服务器启动并通过stdio监听MCP工具调用。

连接到游标

将此添加到您的Cursor MCP配置中(~/.cursor/mcp.json):

{
  "mcpServers": {
    "stock-analyzer": {
      "command": "/path/to/MCP-Stocks/run_cursor_mcp.sh"
    }
  }
}

然后重新启动Cursor。你现在可以问这样的问题:

“适用于NVDA的SMA-50是什么?” “给我TSLA的最新消息。” “获取AAPL过去4个季度的财务数据。”

直接运行LangGraph代理

uv run python agent.py

这运行 analyze_stock("AAPL") 端到端并打印一个JSON评级对象:

{
  "ticker": "AAPL",
  "rating": "BUY",
  "score": 2,
  "drivers": {
    "technical": { "pct_vs_sma_50": 4.2, "signal": "bullish" },
    "fundamentals": "ok",
    "news": { "count": 10, "signal": "mixed" }
  },
  "sources": ["https://..."]
}

可用的MCP工具

工具 描述 关键参数
price_history 每日OHLCV酒吧 ticker, days (默认365)
financials 收入/余额/现金流 ticker, limit (默认值4)
news 最近的新闻文章 ticker, limit (默认值10)
sma 简单移动平均线 ticker, window (默认值50), days
short_interest 短期利息占位符 ticker

项目结构

mcp_server.py      – FastMCP server with all market data tools
agent.py           – LangGraph graph: fetch → decide → rating
main.py            – CLI entry point
run_cursor_mcp.sh  – Shell wrapper for Cursor MCP config
pyproject.toml     – Project metadata and dependencies

延伸

  • 更好的基本面评分 --解析收入增长、利润率和FCF financials 工具结果为 agent.py:decide()
  • 新闻情绪 --集成NLP模型或LLM调用以替换占位符 "mixed" 信号
  • 空头利息 --电线 short_interest 向Finviz或优质Polygon计划等提供商提供服务
  • LLM总结器 --替换确定性 decide 具有用于自然语言分析的Claude/GPT调用的节点

许可证

麻省理工学院