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

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

Local
github.com/mvk24199Finance0Updated 79w ago

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

A Bun.js MCP server that lets Claude agents place buy and sell orders through Zerodha Kite Connect. It handles Kite authentication and periodically refreshes access tokens.

Key features

  1. 01Place buy and sell orders
  2. 02Authenticate with Kite Connect
  3. 03Refresh access tokens periodically
  4. 04Run the MCP server with Bun.js

Use cases

  1. 01Place stock orders from a Claude agent
  2. 02Refresh Kite access tokens during server operation

MCP support

The MCP server exposes trading functions to Claude agents, which can request stock purchases and sales. It uses Kite Connect to submit orders.

Configuration

Local server config is the same for every client. Copy it into your client’s MCP config file.

No install method listed yet

We haven’t collected a package or remote endpoint for this server. Follow the instructions in the project README.

Repository

Tools

No tool list yet

Local servers expose tools only once running on your machine, and the maintainer has not provided a tool list.

Details

From the project README

πŸš€ 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


Comments

Markdown supported

New to MCP?

From what the protocol is to installing your first server, these answers cover most first questions.

An open protocol that defines how AI applications connect to external tools and data in a uniform way. Clients talk to the model; MCP servers provide tools, resources and prompt templates. They exchange standard messages, so one server can be reused by many clients.