股票市场分析服务器

一个连接印度股票经纪商API与AI助手的MCP服务器,提供实时投资组合分析、市场数据获取和智能投资建议。

  • by mahendraxceed
  • TypeScript
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 mahendraxceed/stock_mcp

使用说明

库存MCP服务器

人工智能驱动的印度股市分析

连接 Upstox & 鲁皮齐 经纪人账户 克劳德代码 和 光标 实时投资组合洞察。

入门指南 · MCP提示 · 工具 · 仪表盘


它的作用

Your Broker Accounts  ──►  Stock MCP Server  ──►  Claude / Cursor AI
    (Upstox, Rupeezy)        (Express + SSE)       (Portfolio Analysis)

一个MCP服务器,将印度股票经纪人API与人工智能助手连接起来。通过浏览器OAuth授权您的经纪人,然后让Claude或Cursor通过自然语言分析您的投资组合、跟踪头寸、检查资金和获取市场数据。


特性

功能 描述
多经纪人 Upstox+Rupeezy 跨经纪商的统一数据格式
内置OAuth 基于浏览器的登录 无需手动复制令牌
6个MCP工具 投资组合、头寸、报价、历史、基金、分析 完整的市场数据访问
AI分析 损益、多元化、集中风险 明智的投资组合见解
Web仪表板 顺风黑暗主题 经纪人身份验证、数据视图、工具测试
苏格兰和南方能源公司运输 Express服务器 与Claude代码和游标配合使用

工具

工具 说明
get_portfolio 从Upstox/Rupeezy/两者获取长期持股
get_positions 获取当前未平仓的日内和交割头寸
get_stock_quote 实时股票报价——LTP、OHLC、交易量、变动百分比
get_historical_data 历史OHLCV蜡烛数据(1分钟至每月)
analyze_portfolio 损益表摘要、最大赢家/输家、多元化得分、集中度风险
get_funds 账户余额、可用保证金、已用保证金、抵押品

快速开始

1.安装和构建

pnpm install
pnpm build

2.配置环境

cp .env.example .env

添加您的broker API凭据(访问令牌通过OAuth自动获取):

PORT=3001

# Upstox (https://account.upstox.com/developer/apps)
UPSTOX_API_KEY=your_client_id
UPSTOX_API_SECRET=your_client_secret

# Rupeezy (https://vortex.rupeezy.in/login)
RUPEEZY_APPLICATION_ID=your_app_id
RUPEEZY_API_SECRET=your_api_secret

3.启动服务器

node dist/index.js
# or dev mode with auto-reload
pnpm dev

4.授权经纪人

打开 http://localhost:3001 在您的浏览器中。点击 连接Upstox 或 连接Rupeezy 通过OAuth授权。

5.连接AI客户端

添加到您的Claude代码或Cursor MCP配置中:

{
  "mcpServers": {
    "stock-mcp": {
      "command": "npx",
      "args": ["mcp-remote", "http://localhost:3001/sse"]
    }
  }
}

MCP提示示例

连接后,在中尝试这些提示 克劳德代码 或 光标:

投资组合和控股

> Show all my stock holdings across brokers

> Which stocks am I holding in Upstox?

> What's my total invested value and current portfolio value?

> List my top 5 holdings by current value

投资组合分析

> Analyze my portfolio — show P&L, top gainers, top losers

> What's my portfolio diversification score? Am I too concentrated in any stock?

> Which stocks are dragging my portfolio down the most?

> Compare my Upstox vs Rupeezy portfolio performance

头寸(日内/交易)

> Do I have any open positions today?

> Show my intraday positions and their P&L

> What's my total day P&L across all brokers?

市场数据和报价

> What's the current price of Reliance? (instrument: NSE_EQ|INE002A01018)

> Get me a real-time quote for TCS including volume and day change

> Show OHLC data for Infosys today

历史数据

> Show me daily candle data for HDFC Bank for the last 30 days

> Get weekly historical data for Nifty 50 from Jan to March 2025

> Fetch 15-minute candles for Reliance for yesterday

资金和账户

> How much available margin do I have?

> Show my account balance and collateral across all brokers

> What's my total fund balance in Upstox?

多步分析

> Fetch my portfolio, then analyze which sectors I'm overweight in
  based on the stocks I hold

> Get my holdings and current prices, then calculate which stocks
  have fallen more than 10% from my buy price

> Show my portfolio analysis and suggest which positions I might
  consider rebalancing for better diversification

仪表盘

web仪表板位于 http://localhost:3001 提供:

选项卡 说明
仪表盘 代理连接状态、OAuth登录按钮、MCP客户端配置
投资组合 持有损益表,汇总卡(投资、流动、损益)
职位 带有日损益跟踪的未结头寸表
资金 每个经纪商的账户保证金、余额、抵押品
工具 使用JSON响应查看器进行交互式工具测试

身份验证流程

┌─────────────┐    ┌──────────────┐    ┌──────────────┐
│   Browser    │───►│  MCP Server  │───►│ Broker OAuth │
│  localhost   │◄───│  :3001       │◄───│ Upstox/Rupzy │
└─────────────┘    └──────┬───────┘    └──────────────┘
                          │
                   ┌──────▼───────┐
                   │ Claude/Cursor│
                   │  (MCP SSE)   │
                   └──────────────┘
  1. 启动服务器→ Open http://localhost:3001
  2. 点击 连接Upstox → 登录Upstox→ 已重定向回→ 经纪人活跃
  3. 点击 连接Rupeezy → 登录Rupeezy→ 已重定向回→ 经纪人活跃
  4. AI客户端通过以下方式连接 npx mcp-remote http://localhost:3001/sse

注: Upstox代币每天凌晨3:30到期。每天早上通过仪表板重新授权。 您还可以设置 UPSTOX_ACCESS_TOKEN / RUPEEZY_ACCESS_TOKEN 在 .env 作为退路。


API终点

端点 方法 描述
/ GET Web仪表板
/sse GET MCP SSE流
/messages POST MCP消息处理程序
/auth/upstox GET 启动Upstox OAuth
/auth/upstox/callback GET Upstox OAuth回调
/auth/rupeezy GET 启动Rupeezy OAuth
/auth/rupeezy/callback GET Rupeezy OAuth回调
/auth/status GET 代理连接状态(JSON)
/api/portfolio GET 投资组合持股
/api/positions GET 空缺职位
/api/funds GET 账户资金
/api/analysis GET 投资组合分析
/api/quote 获取 股票报价
/api/history GET 历史蜡烛数据

仪器密钥格式

经纪人 格式 示例(Reliance)
Upstox {EXCHANGE}_{SEGMENT}|{ISIN} NSE_EQ|INE002A01018
鲁皮齐 {EXCHANGE}_{SEGMENT}-{TOKEN} NSE_EQ-2885

项目结构

src/
├── index.ts                    # Entry point — starts Express server
├── server.ts                   # Express app with SSE + OAuth + REST API
├── config.ts                   # Environment config loader
├── types/                      # Unified type definitions
│   ├── portfolio.ts            #   Holding, Position
│   ├── market.ts               #   StockQuote, OHLCVCandle
│   ├── funds.ts                #   FundsInfo
│   └── common.ts               #   BrokerSource
├── brokers/
│   ├── broker.interface.ts     # IBroker contract
│   ├── upstox/
│   │   ├── client.ts           #   Upstox adapter (upstox-js-sdk)
│   │   ├── mapper.ts           #   Response mappers
│   │   └── auth.ts             #   OAuth helpers
│   └── rupeezy/
│       ├── client.ts           #   Rupeezy adapter (@rupeezy/jsvortex)
│       ├── mapper.ts           #   Response mappers
│       └── auth.ts             #   OAuth helpers
├── services/                   # Business logic layer
│   ├── portfolio.service.ts    #   Holdings & positions aggregation
│   ├── market.service.ts       #   Quotes & historical data
│   ├── funds.service.ts        #   Account balance & margin
│   └── analysis.service.ts     #   P&L, diversification, risk
├── views/                      # Dashboard view components
│   ├── index.ts                #   Composes all views
│   ├── layout.ts               #   HTML shell, header, nav, footer
│   ├── dashboard.view.ts       #   Broker cards + MCP config
│   ├── portfolio.view.ts       #   Holdings table
│   ├── positions.view.ts       #   Positions table
│   ├── funds.view.ts           #   Funds cards
│   ├── tools.view.ts           #   Tool testing UI
│   └── scripts.ts              #   Client-side JavaScript
├── tools/                      # MCP tool definitions
└── utils/                      # Logger, cache, rate limiter

技术栈

技术 目的
TypeScript+ESM 类型安全,现代JS
快速 HTTP服务器+SSE传输
@模型上下文协议/sdk MCP服务器框架
upstox js sdk Upstox API客户
@鲁佩齐/jsvortex API卢比客户
佐德 架构验证
顺风 CSS 仪表板样式(CDN)

专为AI驱动的股票分析而构建

报告问题 · 请求功能