Skip to main content
Glama
Zerodha MCP Server

Zerodha MCP Server

by anish5256

Zerodha MCP 服务器

通过 MCP(模型上下文协议)查询您的 Zerodha 交易账户。适用于 Claude Code、Claude Desktop、Cursor 以及其他兼容 MCP 的 AI 工具。

可用工具

工具

描述

get_account_funds

可用余额和保证金

get_portfolio_holdings

长期 demat 持仓

get_open_positions

带有盈亏的日内/期货与期权 (F&O) 仓位

get_todays_orders

今日订单历史

get_current_pnl

综合盈亏摘要

get_instrument_ltp

任何金融工具的最新成交价

get_instrument_ohlc

任何金融工具的 OHLC 数据

get_pnl_summary

指定日期范围(最长 3 个月)的历史盈亏摘要

get_pnl_heatmap

指定日期范围(最长 3 个月)的每日盈亏明细

Related MCP server: Trade-MCP

安装

git clone https://github.com/anish5256/zerodha-mcp.git
cd zerodha-mcp
pip install -e .

配置

环境变量

服务器需要以下环境变量进行身份验证:

变量

描述

ZERODHA_USER_ID

您的 Zerodha 客户 ID(例如 AB1234)

ZERODHA_PASSWORD

您的 Zerodha 登录密码

ZERODHA_TOTP_KEY

您的 TOTP 密钥(32 字符的 base32 字符串)

获取您的 TOTP 密钥

您的 TOTP 密钥是您在 Google Authenticator/Authy 中设置双重验证 (2FA) 时使用的 32 位代码。它看起来像这样:ABCD1234EFGH5678IJKL9012MNOP3456

如果您没有保存它,请在 Zerodha Console 中重置 2FA 以获取新的密钥。


各平台设置

Claude Code (CLI)

添加到 ~/.mcp.json:

{
  "mcpServers": {
    "zerodha": {
      "command": "python",
      "args": ["/path/to/zerodha-mcp/server.py"],
      "env": {
        "ZERODHA_USER_ID": "YOUR_USER_ID",
        "ZERODHA_PASSWORD": "YOUR_PASSWORD",
        "ZERODHA_TOTP_KEY": "YOUR_TOTP_SECRET"
      }
    }
  }
}

然后重启 Claude Code。


Claude Desktop (macOS)

编辑 ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "zerodha": {
      "command": "python",
      "args": ["/path/to/zerodha-mcp/server.py"],
      "env": {
        "ZERODHA_USER_ID": "YOUR_USER_ID",
        "ZERODHA_PASSWORD": "YOUR_PASSWORD",
        "ZERODHA_TOTP_KEY": "YOUR_TOTP_SECRET"
      }
    }
  }
}

然后重启 Claude Desktop。


Claude Desktop (Windows)

编辑 %APPDATA%\Claude\claude_desktop_config.json:

{
  "mcpServers": {
    "zerodha": {
      "command": "python",
      "args": ["C:\\path\\to\\zerodha-mcp\\server.py"],
      "env": {
        "ZERODHA_USER_ID": "YOUR_USER_ID",
        "ZERODHA_PASSWORD": "YOUR_PASSWORD",
        "ZERODHA_TOTP_KEY": "YOUR_TOTP_SECRET"
      }
    }
  }
}

然后重启 Claude Desktop。


Cursor

添加到 Cursor 的 MCP 设置中(Settings > MCP):

{
  "zerodha": {
    "command": "python",
    "args": ["/path/to/zerodha-mcp/server.py"],
    "env": {
      "ZERODHA_USER_ID": "YOUR_USER_ID",
      "ZERODHA_PASSWORD": "YOUR_PASSWORD",
      "ZERODHA_TOTP_KEY": "YOUR_TOTP_SECRET"
    }
  }
}

其他 MCP 客户端

对于任何兼容 MCP 的客户端,请配置:

  • 命令: python

  • 参数: ["/path/to/zerodha-mcp/server.py"]

  • 环境变量:

    • ZERODHA_USER_ID = 您的客户 ID

    • ZERODHA_PASSWORD = 您的密码

    • ZERODHA_TOTP_KEY = 您的 TOTP 密钥


使用示例

配置完成后,您可以询问您的 AI 助手:

  • "What's my current portfolio value?" (我当前的投资组合价值是多少?)

  • "Show me my open positions" (显示我的未平仓位)

  • "What's my P&L for today?" (我今天的盈亏是多少?)

  • "How much funds do I have available?" (我有多少可用资金?)

  • "What's the LTP of RELIANCE?" (RELIANCE 的最新成交价是多少?)

  • "Get OHLC for NIFTY 50" (获取 NIFTY 50 的 OHLC 数据)

  • "What was my F&O profit in 2024?" (我 2024 年的期货与期权利润是多少?)

  • "Show me my daily P&L for last month" (显示我上个月的每日盈亏)

安全说明

  • 您的凭据存储在本地的 MCP 配置文件中

  • 凭据绝不会发送给 AI 模型,仅在服务器端使用

  • 令牌会缓存在本地的 zerodha_enctoken.txt 和 zerodha_console_token.txt 中(已在 gitignore 中忽略)

  • 每个用户必须在自己的机器上配置自己的凭据

许可证

MIT

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    • Indian broker accounts for AI agents: positions, holdings, orders, P&L, option chains, 10+ brokers.

      https://mcp.quantplay.tech/mcp
    • OpenFinance gives any AI agent easy trading across every major market through one hosted MCP server. Trade crypto spot and perpetuals on Hyperliquid with market, limit and TWAP orders, leverage and margin control. Trade stocks, indices, commodities, forex and pre-IPO names as Hyperliquid HIP-3 perps. Trade Polymarket prediction markets with odds, order books, positions, PnL and trader leaderboards. Swap and bridge across 40+ EVM chains and Solana with Relay and Jupiter, find memecoins across 200+ chains, launch tokens on Robinhood Chain and Solana, and buy crypto with card, bank or UPI. Write actions are designed to ask for your confirmation first. Connect with OAuth (sign in to OpenFinance and approve) or an API key. Works with Claude, ChatGPT, Cursor, VS Code, Codex and any MCP client. No install. Home: https://openfinance.tech/agents · Docs: https://docs.openfinance.tech · GitHub: https://github.com/openfinance-tech/mcp

    • Connect Claude, ChatGPT, Codex, Claude Code or another MCP client to your real multi-broker investment portfolio. Fortunest tracks stocks, ETFs and crypto across brokers and exchanges; its MCP server lets your agent read holdings, returns, allocation, risk, trades and tax lots, calculated by Fortunest rather than guessed by the model. Reads run on their own; every change waits for your approval in the Fortunest app, and no tool places an order or moves money. Sign-in is OAuth 2.1 and needs Fortunest Pro (14-day trial, no card). A free demo that needs no account is listed as Fortunest demo.

      https://app.fortunest.ai/mcp
    • Connect brokerage accounts to AI assistants: holdings, orders, asset lookup, and approved trading.

      https://mcp.tradeit.app/mcp

    Related MCP Servers

    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to interact with the Zerodha trading platform for placing stock orders, viewing portfolio holdings, and managing mutual fund investments. Provides secure OAuth authentication and real-time trading capabilities through Zerodha's official API.
      1
      -
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables trading automation through Zerodha Kite Connect API, allowing users to place buy/sell orders and fetch holdings via MCP tools accessible to Claude Desktop and other MCP-compatible clients.
      -
    • A
      license
      Not graded
      quality
      D
      maintenance
      Enables natural language management of Zerodha trading accounts, including placing orders, checking portfolio, and viewing positions through MCP integration.
      32
      Apache 2.0
    • F
      license
      Not graded
      quality
      D
      maintenance
      Enables AI assistants to interact with the Zerodha trading platform for placing stock orders, viewing holdings, and managing mutual fund investments through the MCP protocol.
      4
      -