About Zerodha Kite Connect MCP Server
A Cloudflare Worker MCP server for accessing Zerodha Kite Connect trading and portfolio functions. It is for Zerodha account users and exposes authentication, holdings, positions, GTT orders, and historical market data to MCP clients.
Key features
- 01Zerodha authentication and session handling
- 02Retrieve holdings and positions
- 03Retrieve GTT orders
- 04Fetch historical candle data
- 05Cloudflare KV token storage
Use cases
- 01Checking Zerodha holdings and positions
- 02Retrieving GTT orders through an MCP client
- 03Fetching historical data for an instrument
MCP support
Exposes Zerodha Kite Connect authentication, portfolio, order, and historical-data methods as MCP-compatible responses for Claude Desktop and other MCP clients.
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 READMEZerodha Kite Connect MCP Server
This is a Cloudflare Worker that serves as an MCP (Model Context Protocol) server for interacting with the Zerodha Kite Connect API. It provides a comprehensive interface for trading and portfolio management through Zerodha.
Features
- Zerodha authentication and session management
- Portfolio management (holdings, positions)
- GTT (Good Till Triggered) orders
- Historical data retrieval
- MCP-compatible responses for seamless integration with Claude Desktop and other MCP clients
Setup
Prerequisites
- Zerodha Kite Connect API credentials (API Key and Secret)
- Cloudflare account
Deployment
-
Clone this repository
-
Install dependencies:
npm install -
Create your configuration file:
cp wrangler.jsonc.example wrangler.jsonc -
Configure your Zerodha API credentials in the
wrangler.jsoncfile:- Update the
ZERODHA_API_KEYandZERODHA_API_SECRETvalues - Note: This file is gitignored to prevent committing sensitive information
- Update the
-
Create a KV namespace in Cloudflare:
wrangler kv:namespace create ZERODHA_KV -
Update the
wrangler.jsoncfile with the KV namespace ID -
Add Node.js compatibility for crypto module:
{ "compatibility_date": "2023-05-18", "compatibility_flags": ["nodejs_compat"], ... } -
Deploy the worker:
npx wrangler deploy
Available Methods
Authentication
getLoginUrl()- Generates a Zerodha login URL using the configured API keyhandleRedirect(requestToken)- Processes the request token after successful loginrdhandle(requestToken)- Alternative endpoint for handling authentication redirects
Portfolio Management
getHoldings()- Retrieves a list of equity holdings from ZerodhagetPositions()- Retrieves current day and net positions
Orders
getGTTOrders()- Retrieves Good Till Triggered orders
Market Data
getHistoricalData(instrumentToken, interval, from, to, continuous, oi)- Retrieves historical candle data for a given instrument
Usage
With Claude Desktop or other MCP clients
Once deployed, you can add the worker as an MCP server in Claude Desktop:
- Go to Settings > MCP Servers
- Add a new server with your worker URL (e.g.,
https://zerodha-mcp.your-subdomain.workers.dev) - Claude will automatically discover the available methods
With JavaScript
// Example of using the MCP worker in JavaScript
const loginUrl = await zerodhaWorker.getLoginUrl();
console.log('Please login at:', loginUrl);
// Authentication flow
window.location.href = loginUrl;
// After redirect back with request_token in URL...
const urlParams = new URLSearchParams(window.location.search);
const requestToken = urlParams.get('request_token');
// Get holdings after authentication
const holdingsResponse = await zerodhaWorker.getHoldings();
const holdings = JSON.parse(holdingsResponse.content[0].text);
console.log('Your holdings:', holdings);
// Get historical data
const historicalData = await zerodhaWorker.getHistoricalData(
'5633', // instrument_token (NSE:INFY)
'minute', // interval
'2023-01-01 09:15:00', // from
'2023-01-01 09:30:00', // to
false, // continuous
false // oi
);
console.log('Historical data:', JSON.parse(historicalData.content[0].text));
Extending Functionality
To add more Zerodha API functionality:
- Add new methods to the
ZerodhaWorkerclass insrc/index.js - Implement the desired Zerodha API calls using the Kite Connect API
- Format responses according to the MCP specification (using the content array format)
- Update the docs.json file to document the new methods
- Deploy the updated worker
Response Format
All methods return responses in the MCP-compatible format:
{
"content": [
{
"type": "text",
"text": "{ ... data as JSON string ... }"
}
]
}
Authentication Flow
- User visits the login URL generated by
getLoginUrl() - After successful login, Zerodha redirects to the callback URL with a request token
- The
/callbackor/rdhandleendpoint processes the request token - The access token is obtained and stored in the KV namespace
- Subsequent API calls use the stored access token
Security
- API keys and secrets are stored securely in Cloudflare environment variables
- Access tokens are stored in Cloudflare KV namespace
- The wrangler.jsonc file containing credentials is gitignored to prevent accidental exposure
- Only essential endpoints are exposed, minimizing attack surface
Development
To run the worker locally:
npx wrangler dev
To test the worker:
npx wrangler dev --test
API Documentation
For more information about the Zerodha Kite Connect API, refer to the official documentation:
- Kite Connect API Documentation
- Kite Connect API - Authentication
- Kite Connect API - Portfolio
- Kite Connect API - GTT Orders
- Kite Connect API - Historical Data
MCP Documentation
For more information about the Model Context Protocol (MCP), refer to:
License
MIT
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.