🚀 How to Build an MCP Server for Zerodha – AI-Powered Trading with Claude
Aneh Thakur
. 4 min read
Introduction
The future of trading is here—and it speaks your language.
With Claude, an advanced AI by Anthropic, and Zerodha, India’s leading brokerage, you can now place trades, check your stock portfolio, and run custom strategies—all by simply typing a message.
Thanks to MCP (Model Context Protocol), an emerging standard for connecting LLMs to real-world APIs, we can bridge the gap between natural language and actual trading.
In this guide, you’ll learn how to:✅ Build a working MCP server using Node.js✅ Connect it to Zerodha’s Kite API✅ Enable Claude to run real trade commands
🧠 What is MCP (Model Context Protocol)?
MCP is a protocol that lets large language models (LLMs) like Claude securely and predictably interact with external systems via API-based tools.
Why Use MCP with Zerodha?
🎯 Natural Language Trading: Place orders like “Buy 5 shares of Infosys”.
⚡ Faster Execution: Automate actions like selling top performers.
🧑💻 Zero Coding Needed: End-users don’t need to know how to write scripts.
MCP is already being used with tools like GitHub, Slack, and Kubernetes—and now, we’ll adapt it for stock trading.
🔌 Part 1: Set Up Zerodha API (Kite Connect)
Zerodha offers a developer API called Kite Connect. This API allows programmatic access to your trading account.
✅ Steps to Get Started:
Create a Developer AccountVisit: https://developers.kite.trade
Register your app (e.g., "Trade Assistant")
Note your API Key and API Secret
Authenticate via OAuth
Generate a Request Token by logging in with your Zerodha credentials
Exchange it for an Access Token
Install Zerodha Node.js SDK
Sample Kite Connect Setup
⚙️ Part 2: Build the MCP Server (Node.js)
We’ll now expose trading actions—like buy, sell, and show portfolio—to Claude using MCP tools.
🛠️ Install Required Packages
📄 server.ts (Complete Working Code)
🤖 Part 3: Connect Claude to Your MCP Server
Install Claude (MCP-enabled desktop version)
Enable Developer Mode from settings
Edit Claude’s MCP Config to include your server:
Restart Claude
It will auto-discover tools like buy_stock, sell_stock, and show_portfolio.
✅ Testing: Example Commands for Claude
You can now talk to Claude like this:
💸 "Buy 10 shares of INFY"
📉 "Sell 5 shares of TCS"
📊 "Show my current holdings"
Claude will:
Match the natural language to the MCP tool
Convert it into a valid API call
Execute and return the result 🎉
⚠️ Caveats & Improvements
Limitation | Suggestion |
---|---|
🧾 Stock Symbol Confusion | Use a lookup API or alias map |
🔒 Access Token Expiry | Automate token refresh or store securely |
💹 Real-Time Data | Subscribe to Zerodha’s historical data APIs |
🧠 Custom Strategy | Add logic for auto-buy/sell based on trends |
💡 Future Ideas:
“Buy top gainer of the day” tool
Auto-sell on stop-loss
Mutual Fund support
🎯 Conclusion
You’ve just built a fully functional AI-powered trading assistant using Claude and Zerodha!
Thanks to Model Context Protocol, Claude can:
Place trades using just text
Analyze portfolios
Execute smart strategies in real-time
This architecture can easily be adapted for:
GitHub automation
DevOps (e.g., Kubernetes control)
Data analysis pipelines
CRM integrations
🔗 Resources & Links
More Stories from
Boost Developer Speed with Google Cloud CLI & Claude AI
Accelerate software development with Google Cloud CLI and Claude AI. Automate tasks, deploy faster, and improve workflows using intelligent tools.
India’s Rise in the AI Era: Shaping the Future as a Global Leader
India is becoming a global AI leader through initiatives like IndiaAI, indigenous LLMs like Sarvam AI and BharatGPT, and rapid startup growth. Learn how AI is shaping India’s digital and inclusive future.
AI and Beginner Developers: A Double-Edged Sword in Programming
AI tools are transforming how beginner developers learn to code. Discover the benefits, risks of over-reliance, and best practices to use AI effectively in your programming journey.
Mastering Google AI Mode: A Guide for SEO Professionals in the Age of Answer Engines
Learn how Google AI Mode is changing search. Discover how to adapt your SEO strategy with Answer Engine Optimization (AEO) for AI-powered results.
🚀 OpenAI’s $3 Billion Windsurf Acquisition: What It Really Means
OpenAI's $3 billion Windsurf deal shows that developer tools—not chatbots—are the real future of AI. Here’s what this means for coders, jobs, and the evolving dev landscape.