Zerodha Kite MCP server

Enables natural language interaction with Zerodha Kite trading platform for executing stock orders, retrieving portfolio information, and managing market transactions
Back to servers
Setup instructions
Provider
Yaseen
Release date
May 21, 2025
Stats
1 star

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.

Prerequisites

  • Node.js and npm/yarn installed on your system
  • Zerodha Kite Developer Account with API access

Installation

Create a Kite API App

  1. Visit https://developers.kite.trade/create to create a new Kite app
  2. You can use any redirection URL (e.g., https://localhost:3000/api/callback/userauth)
  3. Save the API key and API secret provided after app creation

Configure API Keys

Open 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

Generate an Access Token

Follow these steps to generate an authentication token:

  1. Uncomment the getLoginUrl function in index.ts:

    async function getLoginUrl() {
        return kc.getLoginURL();
    }
    console.log(await getLoginUrl()); // Add this line
    
  2. Run the script to get a login URL:

    ts-node index.ts
    
  3. Open the URL in your browser, log in with your Zerodha credentials, and authorize the app

  4. After authorization, you'll be redirected to a URL containing a request_token parameter

  5. 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
    
  6. Run the script again to generate your access token

  7. Update index.ts with your access token:

    const access_token = "YOUR_GENERATED_ACCESS_TOKEN";
    
  8. For security, remove or comment out the token generation code and the apiSecret after obtaining your access token

Install Dependencies and Build

# Install required packages
npm install

# Build the project
npm run build

Setting Up with Cursor

To integrate the MCP server with Cursor:

  1. Open Cursor settings (Cmd/Ctrl + ,)
  2. Navigate to Extensions > MCP
  3. Click on "Edit in settings.json" for "Model Context Protocol: Servers"
  4. Add the following configuration:
{
  "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.

Available Trading Functions

Adding Numbers (Test Function)

trader.add

This simple function adds two numbers.

Parameters:

  • a (number): First number
  • b (number): Second number

Returns: Sum of the two numbers

Selling Stocks

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 sell

Returns: Confirmation message or error

Buying Stocks

trader.buyStock

Places a market buy order for a specified stock.

Parameters:

  • tradingsymbol (string): Trading symbol
  • quantity (number): Number of shares to buy

Returns: Confirmation message or error

Fetching Positions

trader.getPositions

Retrieves your current open positions.

Parameters: None Returns: JSON string representing your positions

Fetching Holdings

trader.getHoldings

Retrieves stocks currently in your demat account.

Parameters: None Returns: JSON string representing your holdings

Technical Details

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.

How to install this MCP server

For Claude Code

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.

For Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

For Claude Desktop

To add this MCP server to Claude Desktop:

1. Find your configuration file:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
  • Linux: ~/.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

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later