Zerodha Kite MCP Server provides a Model Context Protocol server that connects to the Zerodha Kite API, enabling trading actions such as buying and selling stocks and retrieving your holdings and positions information. It acts as a bridge between MCP clients like Cursor and the Zerodha trading platform.
https://localhost:3000/api/callback/userauth
)API key
and API secret
provided after app creationOpen the index.ts
file and configure your API credentials:
const apiKey = "YOUR_ACTUAL_API_KEY"; // Replace with your API key
// const apiSecret = "YOUR_ACTUAL_API_SECRET"; // Uncomment for first-time token generation
Follow these steps to generate an authentication token:
Uncomment the getLoginUrl
function in index.ts
:
async function getLoginUrl() {
return kc.getLoginURL();
}
console.log(await getLoginUrl()); // Add this line
Run the script to get a login URL:
ts-node index.ts
Open the URL in your browser, log in with your Zerodha credentials, and authorize the app
After authorization, you'll be redirected to a URL containing a request_token
parameter
Uncomment the getAccessToken
function in index.ts
and ensure apiSecret
is set:
async function getAccessToken(requestToken: string) {
const response = await kc.generateSession(requestToken, apiSecret);
console.log(response.access_token);
}
await getAccessToken("YOUR_REQUEST_TOKEN"); // Add this line with your request token
Run the script again to generate your access token
Update index.ts
with your access token:
const access_token = "YOUR_GENERATED_ACCESS_TOKEN";
For security, remove or comment out the token generation code and the apiSecret
after obtaining your access token
# Install required packages
npm install
# Build the project
npm run build
To integrate the MCP server with Cursor:
{
"mcpServers": {
"trader": {
"command": "node",
"args": ["/path/to/your/Zerodha-MCP/dist/trader.js"]
}
}
}
Make sure to replace the path with the absolute path to the compiled trader.js
file on your system.
trader.add
This simple function adds two numbers.
Parameters:
a
(number): First numberb
(number): Second numberReturns: Sum of the two numbers
trader.sellStock
Places a market sell order for a specified stock.
Parameters:
tradingsymbol
(string): Trading symbol (e.g., "INFY", "RELIANCE")quantity
(number): Number of shares to sellReturns: Confirmation message or error
trader.buyStock
Places a market buy order for a specified stock.
Parameters:
tradingsymbol
(string): Trading symbolquantity
(number): Number of shares to buyReturns: Confirmation message or error
trader.getPositions
Retrieves your current open positions.
Parameters: None Returns: JSON string representing your positions
trader.getHoldings
Retrieves stocks currently in your demat account.
Parameters: None Returns: JSON string representing your holdings
All orders are placed as PRODUCT_CNC
(Cash and Carry, for delivery-based trades) on EXCHANGE_NSE
. The system uses an incremental counter to create unique order tags, which is persisted in a counter.json
file to maintain uniqueness across server restarts.
To add this MCP server to Claude Code, run this command in your terminal:
claude mcp add-json "trader" '{"command":"node","args":["/path/to/your/Zerodha-MCP/dist/trader.js"]}'
See the official Claude Code MCP documentation for more details.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > Tools & Integrations and click "New MCP Server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"trader": {
"command": "node",
"args": [
"/path/to/your/Zerodha-MCP/dist/trader.js"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explicitly ask the agent to use the tool by mentioning the tool name and describing what the function does.
To add this MCP server to Claude Desktop:
1. Find your configuration file:
~/Library/Application Support/Claude/claude_desktop_config.json
%APPDATA%\Claude\claude_desktop_config.json
~/.config/Claude/claude_desktop_config.json
2. Add this to your configuration file:
{
"mcpServers": {
"trader": {
"command": "node",
"args": [
"/path/to/your/Zerodha-MCP/dist/trader.js"
]
}
}
}
3. Restart Claude Desktop for the changes to take effect