Skip to main content

MCP server for Zerodha Kite — trade Indian stocks via Claude and other AI assistants

Project description

kite-mcp

MCP server for Zerodha Kite -- trade Indian stocks through natural conversation with Claude and other AI assistants.

Why an MCP server instead of a Python library?

Traditional Kite wrappers require you to write Python code to trade. With kite-mcp, you just talk:

You:    "Buy 50 Reliance at market price"
Claude: checks quote, verifies funds, asks for confirmation, places order

You:    "How's my portfolio doing?"
Claude: fetches holdings, calculates P&L, summarizes gainers and losers

You:    "Set a stop-loss on my HAL position at 3400"
Claude: places a GTT trigger for you

No code. No scripts. No terminal. Just conversation.

kite-mcp connects Claude (or any MCP-compatible AI assistant) directly to your Zerodha account with 14 trading tools, automated TOTP login, and auto-retry on expired tokens.

How it works

You (natural language) --> Claude --> kite-mcp (MCP server) --> Zerodha Kite API

Claude interprets your intent, maps stock names to symbols (e.g., "Infosys" to NSE:INFY), checks your funds, and executes trades -- all through the MCP protocol. The server handles authentication automatically, including daily token refresh via TOTP.

Features

14 tools for complete trading control:

Tool Description
kite_login Auto-authenticate with TOTP
get_holdings Portfolio holdings with P&L
get_positions Today's intraday/delivery positions
get_orders Today's order history
get_margins Available funds and margins
get_quote Live market quotes
get_ohlc Open, high, low, close data
get_historical_data Historical candle data (minute to daily)
get_instruments Search tradeable instruments across NSE, BSE, NFO, MCX
place_order Place buy/sell orders (market, limit, stop-loss)
modify_order Modify pending orders
cancel_order Cancel pending orders
get_gtt_triggers View Good Till Triggered orders
place_gtt Place GTT single or OCO (stoploss + target) triggers

Key capabilities:

  • Fully automated login -- TOTP generated on the fly, no manual intervention
  • Auto-retry on stale tokens -- re-authenticates transparently if a token expires mid-session
  • Supports delivery (CNC), intraday (MIS), and F&O (NRML) orders
  • After-market orders (AMO) supported

Quick Start

1. Install

pip install kite-mcp

2. Get your credentials

You need a Kite Connect API app. From your app dashboard, note your API Key and API Secret.

You also need:

  • User ID -- your Zerodha client ID (e.g., AB1234)
  • Password -- your Zerodha login password
  • TOTP Secret (recommended) -- the base32 seed from setting up an external authenticator app for Zerodha 2FA. This enables fully automated login with no manual steps.
How to get your TOTP secret
  1. Log in to console.zerodha.com
  2. Go to My Profile > Security > 2FA Settings
  3. Switch to an external authenticator app (Google Authenticator, Authy, etc.)
  4. When the QR code appears, look for a "Can't scan? Copy this key" link
  5. That key is your TOTP secret -- save it before completing setup
  6. Enter the 6-digit code from your authenticator to finish

3. Configure Claude Desktop

Add this to your Claude Desktop config:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%\Claude\claude_desktop_config.json

{
  "mcpServers": {
    "kite": {
      "command": "kite-mcp",
      "env": {
        "KITE_API_KEY": "your-api-key",
        "KITE_API_SECRET": "your-api-secret",
        "KITE_USER_ID": "your-user-id",
        "KITE_PASSWORD": "your-password",
        "KITE_TOTP_SECRET": "your-totp-secret"
      }
    }
  }
}

Restart Claude Desktop. You're ready to trade.

4. Try it out

Open a new chat in Claude Desktop and try:

  • "Show my portfolio holdings"
  • "What's Tata Motors trading at?"
  • "Buy 10 Infosys at market price"
  • "How much cash do I have available?"
  • "Cancel my last pending order"
  • "Show my top gainers and losers"

Claude understands stock names in plain English -- no need to use trading symbols.

Environment Variables

Variable Required Description
KITE_API_KEY Yes Kite Connect API key
KITE_API_SECRET Yes Kite Connect API secret
KITE_USER_ID Yes Zerodha client ID
KITE_PASSWORD Yes Zerodha login password
KITE_TOTP_SECRET No TOTP base32 seed for auto-login. Without this, you must run kite-mcp-login manually each day.

Manual Login

If you don't have a TOTP secret, you can log in manually each day:

export KITE_API_KEY=your-api-key
export KITE_API_SECRET=your-api-secret
export KITE_USER_ID=your-user-id
export KITE_PASSWORD=your-password
kite-mcp-login

This caches the access token for the rest of the day. The MCP server will use the cached token until it expires.

Use Cases

  • Daily portfolio monitoring -- "Give me a summary of my portfolio with top gainers and losers"
  • Quick trades -- "Buy 50 Reliance" / "Sell all my Yes Bank"
  • Research + action -- "What's the 52-week high of HDFC Bank? Should I add more at current levels?"
  • Risk management -- "Set a stop-loss GTT on my BDL position at 1100"
  • Scheduled reports -- Combine with Claude's scheduled tasks to get a daily portfolio summary at 9am
  • Slack integration -- Pair with Slack MCP to receive portfolio alerts in your Slack channel

Development

git clone https://github.com/amitranjan/kite-mcp.git
cd kite-mcp
python -m venv venv
source venv/bin/activate
pip install -e .

Security

  • Credentials are passed via environment variables -- never stored in code
  • Access tokens are cached locally at ~/.zerodha_kite_token.json and expire daily
  • The server runs locally on your machine -- no data is sent to third-party servers
  • All communication with Zerodha uses HTTPS

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kite_mcp-0.1.0.tar.gz (11.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kite_mcp-0.1.0-py3-none-any.whl (10.2 kB view details)

Uploaded Python 3

File details

Details for the file kite_mcp-0.1.0.tar.gz.

File metadata

  • Download URL: kite_mcp-0.1.0.tar.gz
  • Upload date:
  • Size: 11.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kite_mcp-0.1.0.tar.gz
Algorithm Hash digest
SHA256 edcf2f9b320bb0f829e9d7d46e5efe6c2a8dcde4dc16d9e3ed5bce3c9374fcaf
MD5 442d4bc8b9de33edcca3aa547993a0db
BLAKE2b-256 95f12bdf7fd91208631a7d06383b4e93b03356f07a82c348819bb2f84854adcf

See more details on using hashes here.

File details

Details for the file kite_mcp-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: kite_mcp-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 10.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for kite_mcp-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c62e625deda4b2fbb258c026a51e8f6f2544076e4c39c290340fb0ebcec5f4a5
MD5 a8ca7e6de7cb19415b99e8fafeb3c400
BLAKE2b-256 a9d6a19f953be83fbbd25862b228836c14c0c8d382da061cac24a5ac60ef7622

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page