zerodha-trade-mcp

sriejan/zerodha-trade-mcp

3.2

If you are the rightful owner of zerodha-trade-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server that enables AI models to interact with the Zerodha trading platform, providing tools for executing trades, viewing portfolios, and managing positions through a standardized interface.

Tools
  1. Get Profile

    Retrieves the user's profile information from Zerodha.

  2. Buy Stock

    Places a buy order for the specified stock and quantity.

  3. Sell Stock

    Places a sell order for the specified stock and quantity.

  4. Show Portfolio

    Displays current holdings and their values.

  5. Show Positions

    Shows all open positions with P&L information.

Zerodha Trading MCP

A Model Context Protocol (MCP) server that enables AI models to interact with the Zerodha trading platform. This project provides a set of tools for executing trades, viewing portfolio, and managing positions on Zerodha through a standardized interface.

Features

  • šŸ” Secure authentication with Zerodha API
  • šŸ“Š View portfolio holdings
  • šŸ“ˆ Check open positions
  • šŸ’¹ Place buy/sell orders
  • šŸ‘¤ Access user profile information
  • šŸ¤– NEW: Automated paper trading with Background Agents
  • šŸ“± NEW: Smart auto-trigger system for continuous monitoring

Prerequisites

  • Node.js (v14 or higher)
  • Zerodha Trading Account
  • API credentials from Zerodha
  • Git repository initialized

Installation

  1. Clone the repository:
git clone https://github.com/shubhamprajapati7748/zerodha-trade-mcp.git
cd zerodha-trade-mcp
  1. Install dependencies:
npm install
  1. Create a .env file in the root directory with your Zerodha credentials:
KITE_API_KEY=your_api_key
KITE_SECRET_KEY=your_secret_key
REQUEST_TOKEN=your_request_token
ACCESS_TOKEN=your_access_token

Automated Trading Setup

Background Agents (Recommended)

  1. Initialize Git repository (required):

    git init
    git config user.name "Your Name"
    git config user.email "your.email@example.com"
    git add .
    git commit -m "Initial commit"
    
  2. Configure environment (.cursor/environment.json already created):

    • Auto-trading monitor
    • Market data stream
    • Continuous portfolio updates
  3. Start Background Agent:

    • Press Ctrl+E in Cursor IDE
    • Submit prompt: "Monitor my ₹1 lakh paper trading portfolio continuously, execute light-risk scalping trades, analyze market data every 30 seconds, and provide updates until market close"

Smart Auto-Trigger System

node smart_auto_trigger.cjs
  • Copies trading commands to clipboard every 45 seconds
  • Audio and visual alerts
  • Windows notifications
  • Just paste (Ctrl+V) in Cursor chat

Browser-Based Monitor

Open auto_chat_trigger.html in your browser:

  • 30-second interval reminders
  • Auto-clipboard functionality
  • Market hours detection
  • Audio alerts

Claude Desktop MCP Configuration

To use this MCP server with Claude Desktop, you need to configure the mcp server details. Here's how to set it up:

  1. Open claude_desktop_config.json in your project root
  2. Add the following configuration:
{
  "mcpServers": {
    "tradeStocks": {
      "command": "/opt/homebrew/bin/bun",
      "args": [
        "/path/to/your/index.ts"
      ], 
      "env": {
        "KITE_API_KEY": "your_api_key",
        "KITE_SECRET_KEY": "your_secret_key",
        "REQUEST_TOKEN": "your_request_token",
        "ACCESS_TOKEN": "your_access_token"
      }
    }
  }
}

Make sure to:

  • Update the path to your index.ts file
  • Replace the environment variables with your actual Zerodha credentials

Paper Trading Strategy

Light Risk Scalping Approach

  • Starting Capital: ₹1,00,000 (paper money)
  • Risk per Trade: Maximum 0.5%
  • Target: 0.5-1% quick profits
  • Strategy: High-frequency monitoring with tight stops
  • Focus: Quality stocks (ICICI, TCS, ITC, etc.)

Current Positions Example

šŸ’° Cash: ₹1,240
šŸ“Š ICICI BANK: 700 shares @ ₹1,426.8 (+₹700 profit)
šŸŽÆ Target: ₹1,435 | Stop: ₹1,420

Usage

The MCP server provides the following tools:

Get Profile

get-profile

Retrieves the user's profile information from Zerodha.

Buy Stock

buy-stock {stock: string, quantity: number}

Places a buy order for the specified stock and quantity.

Sell Stock

sell-stock {stock: string, quantity: number}

Places a sell order for the specified stock and quantity.

Show Portfolio

show-portfolio

Displays current holdings and their values.

Show Positions

show-positions

Shows all open positions with P&L information.

Files Structure

ā”œā”€ā”€ index.ts                 # Main MCP server
ā”œā”€ā”€ trade.ts                 # Trading functions
ā”œā”€ā”€ auto-trader.js           # Standalone auto-trader
ā”œā”€ā”€ simple_auto_trader.py    # Python auto-trader
ā”œā”€ā”€ smart_auto_trigger.cjs   # Smart reminder system
ā”œā”€ā”€ auto_chat_trigger.html   # Browser-based monitor
ā”œā”€ā”€ .cursor/
│   └── environment.json     # Background Agent config
ā”œā”€ā”€ cursor-mcp-config.json   # MCP configuration
└── README.md               # This file

Security

  • All trading credentials are stored securely in environment variables
  • Paper trading mode recommended for testing
  • Real money trading requires careful risk management
  • Background Agents run in isolated environments

Troubleshooting

Git Repository Required

git init
git config user.name "Your Name"
git config user.email "your.email@example.com"

ES Module Errors

Use .cjs extension for CommonJS modules or update package.json type setting.

MCP Connection Issues

Check cursor-mcp-config.json configuration and restart Cursor IDE.

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Disclaimer

This software is for educational and testing purposes only. Trading involves risk of financial loss. The authors are not responsible for any financial losses incurred through the use of this software. Always test with paper trading before using real money.

Support

For issues and questions:

  • Create an issue on GitHub
  • Check the troubleshooting section
  • Review the MCP documentation

Happy Trading! šŸ“ˆšŸ’¹