πŸš€ Zerodha Trading Agent (MCP x Bun.js)

by mvk24199

189 downloads
Not rated
GitHub

About

This is an intelligent stock trading agent built with Bun.js, the Zerodha Kite Connect API, and Claude MCP Server Integration. It allows users to place trades, auto-buy or sell stocks based on triggers, and (on the roadmap) predict stock trends using historical data and live…

Details

Author
mvk24199
Downloads
189
Categories
Finance

- Place buy and sell orders automatically via MCP Agent
- Authenticate securely using Kite Connect
- Auto-refresh access tokens periodically
- Built with Bun.js for superfast runtime
- Fully compatible with Claude Toolchain / MCP Agents
- Smart GTT‑like watchlist and stock prediction (coming soon)

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name πŸš€ Zerodha Trading Agent (MCP x Bun.js)
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

Install dependencies with bun install, then configure your Kite Connect API key, secret, and access token in tokenStore.json. Optionally run bun login.ts to generate an access token. Start the server with bun index.ts; it runs on http://localhost:3000. For HTTPS (required by Kite Connect), tunnel with ngrok. Finally, add the MCP server configuration to your Claude toolchain, pointing to the Bun binary and index.ts.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "\ud83d\ude80 zerodha trading agent (mcp x bun.js)": {
            "zerodha-trade": {
                "command": "bun",
                "args": [
                    "login.ts"
                ]
            }
        }
    }
}

McpServers

{
    "zerodha-trade": {
        "command": "bun",
        "args": [
            "login.ts"
        ]
    }
}

πŸš€ Zerodha Trading Agent (MCP x Bun.js)

This is an intelligent Stock Trading Agent built using:
- Bun.js (fast JavaScript runtime)
- Zerodha Kite Connect API
- Claude MCP Server Integration

The agent allows you to place trades, auto-buy/sell stocks based on triggers, and (future roadmap) predict stock trends using historical data and live news.

---

πŸ“‹ Features

- πŸ”₯ Place Buy and Sell orders automatically via MCP Agent
- πŸ›‘οΈ Authenticate securely using Kite Connect
- πŸ”„ Auto-refresh access tokens periodically
- 🎯 (Coming Soon) Smart GTT-like Watchlist based buying/selling
- 🧠 (Coming Soon) Stock Future Prediction using charts and news analysis
- ⚑ Built with Bun.js for superfast runtime
- 🎯 Fully compatible with Claude Toolchain / MCP Agents

---

πŸ“‚ Project Structure

zerodha-trade/
β”œβ”€β”€ index.ts          # MCP Server setup, defines trading tools
β”œβ”€β”€ trade.ts          # Trading logic: place order, generate session
β”œβ”€β”€ refreshToken.ts   # Refreshes access token using request_token
β”œβ”€β”€ login.ts          # (One time) Generate new access token
β”œβ”€β”€ tokenStore.json   # Stores API key, secret, access token
β”œβ”€β”€ watchlist.json    # (Coming soon) GTT trigger rules
β”œβ”€β”€ README.md         # Project documentation

---

βš™οΈ Setup Instructions

1. Install Dependencies

bun install

_(Make sure you have Bun.js installed:)_

curl -fsSL https://bun.sh/install | bash

---

2. Configure API Credentials

Update tokenStore.json with:

{
  "apiKey": "YOUR_KITE_API_KEY",
  "apiSecret": "YOUR_KITE_API_SECRET",
  "accessToken": "YOUR_ACCESS_TOKEN"
}

If you don't have accessToken yet, run:

bun login.ts

to generate one manually.

---

3. Running the Agent Server

bun index.ts

βœ… This will:
- Auto-refresh your access token every 24 hours
- Expose trading functions to Claude Agent via MCP Server
- Run a server on http://localhost:3000

---

4. Using HTTPS Locally (via ngrok)

Since Kite Connect requires an HTTPS URL, you can use ngrok to tunnel your local server securely.

brew install ngrok   # Install ngrok (if not already installed)
ngrok http 3000      # Expose port 3000 via HTTPS

After running, you will get a public HTTPS URL like https://abc1234.ngrok.io. Use this URL as your Redirect URL when creating your Kite Connect App.

---

5. Creating Kite Connect App (to get API Key/Secret)

1. Go to Kite Developer Console
2. Click Create New App
3. Fill in:
- App Name: (Any meaningful name)
- Redirect URL: (Paste your https://xyz.ngrok.io URL)
- Postback URL: (Same or another ngrok HTTPS URL)
- Products: Kite Connect
- Exchange: NSE, BSE, etc.
4. After creation, you will get API Key and API Secret
5. Update tokenStore.json accordingly

---

πŸš€ MCP Server Configuration Example

{
  "mcpServers": {
    "zerodha-trade": {
      "command": "/Users/vamsi/.bun/bin/bun",
      "args": [
        "--directory",
        "/Users/vamsi/Projects/zerodha-trade",
        "index.ts"
      ]
    }
  }
}

---

πŸ› οΈ Future Enhancements (Roadmap)

- πŸ”” Smart GTT Trigger system: Buy/sell when price crosses target
- πŸ“ˆ Stock Future Prediction Agent (using historical price + live news)
- πŸ“Š Auto SIP Bot for ETFs like Nifty50
- πŸ“¬ Telegram/Slack Alerts on successful order execution
- πŸ“‰ Stop Loss Automation on Portfolio Holdings

---

πŸ€– How It Works (High Level)

1. MCP Agent requests buyStock(symbol, quantity) or sellStock(symbol, quantity)
2. Agent server uses Kite Connect API to place orders
3. Access token refreshed every day automatically
4. (Upcoming) Background service watches prices to auto-trigger GTT-like orders
5. (Upcoming) News + Chart analysis predict stock trend

---

✨ Credits

- Zerodha Kite Connect API
- Bun.js
- Claude Model Context Protocol
- Zerodha Developer Community

---

No reviews yet β€” be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.