Skip to main content
Glama
Zerodha MCP Server

Zerodha MCP Server

by anish5256

Zerodha MCP Server

Query your Zerodha trading account via MCP (Model Context Protocol). Works with Claude Code, Claude Desktop, Cursor, and other MCP-compatible AI tools.

Tools Available

Tool

Description

get_account_funds

Available balance and margins

get_portfolio_holdings

Long-term demat holdings

get_open_positions

Intraday/F&O positions with P&L

get_todays_orders

Today's order history

get_current_pnl

Combined P&L summary

get_instrument_ltp

Last traded price of any instrument

get_instrument_ohlc

OHLC data of any instrument

get_pnl_summary

Historical P&L summary for a date range (max 3 months)

get_pnl_heatmap

Daily P&L breakdown for a date range (max 3 months)

Related MCP server: Trade-MCP

Installation

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

Configuration

Environment Variables

The server requires these environment variables for authentication:

Variable

Description

ZERODHA_USER_ID

Your Zerodha client ID (e.g., AB1234)

ZERODHA_PASSWORD

Your Zerodha login password

ZERODHA_TOTP_KEY

Your TOTP secret key (32-character base32 string)

Getting Your TOTP Key

Your TOTP secret key is the 32-character code you used when setting up 2FA in Google Authenticator/Authy. It looks like: ABCD1234EFGH5678IJKL9012MNOP3456

If you don't have it saved, reset 2FA in Zerodha Console to get a new one.


Setup by Platform

Claude Code (CLI)

Add to ~/.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"
      }
    }
  }
}

Then restart Claude Code.


Claude Desktop (macOS)

Edit ~/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"
      }
    }
  }
}

Then restart Claude Desktop.


Claude Desktop (Windows)

Edit %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"
      }
    }
  }
}

Then restart Claude Desktop.


Cursor

Add to Cursor's MCP settings (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"
    }
  }
}

Other MCP Clients

For any MCP-compatible client, configure:

  • Command: python

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

  • Environment Variables:

    • ZERODHA_USER_ID = Your client ID

    • ZERODHA_PASSWORD = Your password

    • ZERODHA_TOTP_KEY = Your TOTP secret


Usage Examples

Once configured, ask your AI assistant:

  • "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?"

  • "Get OHLC for NIFTY 50"

  • "What was my F&O profit in 2024?"

  • "Show me my daily P&L for last month"

Security Notes

  • Your credentials are stored locally in your MCP config file

  • Credentials are never sent to the AI model, only used server-side

  • Tokens are cached locally in zerodha_enctoken.txt and zerodha_console_token.txt (gitignored)

  • Each user must configure their own credentials on their own machine

License

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
      -