π Zerodha Trading Agent (MCP x Bun.js)
LocalAbout π 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
- 01Place buy and sell orders
- 02Authenticate with Kite Connect
- 03Refresh access tokens periodically
- 04Run the MCP server with Bun.js
Use cases
- 01Place stock orders from a Claude agent
- 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.
We havenβt collected a package or remote endpoint for this server. Follow the instructions in the project README.
Tools
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)
- Go to Kite Developer Console
- Click Create New App
- Fill in:
- App Name: (Any meaningful name)
- Redirect URL: (Paste your
https://xyz.ngrok.ioURL) - Postback URL: (Same or another ngrok HTTPS URL)
- Products: Kite Connect
- Exchange: NSE, BSE, etc.
- After creation, you will get API Key and API Secret
- Update
tokenStore.jsonaccordingly
π 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)
- MCP Agent requests
buyStock(symbol, quantity)orsellStock(symbol, quantity) - Agent server uses Kite Connect API to place orders
- Access token refreshed every day automatically
- (Upcoming) Background service watches prices to auto-trigger GTT-like orders
- (Upcoming) News + Chart analysis predict stock trend
β¨ Credits
Comments
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.