Sponsored by Deepsite.site

Zerodha Kite Connect MCP Server

Created By
manucr6198 months ago
This is a Cloudflare Worker that serves as an MCP (Model Context Protocol) server for interacting with the Zerodha Kite Connect API.
Content

Zerodha 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

  1. Clone this repository

  2. Install dependencies:

    npm install
    
  3. Create your configuration file:

    cp wrangler.jsonc.example wrangler.jsonc
    
  4. Configure your Zerodha API credentials in the wrangler.jsonc file:

    • Update the ZERODHA_API_KEY and ZERODHA_API_SECRET values
    • Note: This file is gitignored to prevent committing sensitive information
  5. Create a KV namespace in Cloudflare:

    wrangler kv:namespace create ZERODHA_KV
    
  6. Update the wrangler.jsonc file with the KV namespace ID

  7. Add Node.js compatibility for crypto module:

    {
      "compatibility_date": "2023-05-18",
      "compatibility_flags": ["nodejs_compat"],
      ...
    }
    
  8. Deploy the worker:

    npx wrangler deploy
    

Available Methods

Authentication

  • getLoginUrl() - Generates a Zerodha login URL using the configured API key
  • handleRedirect(requestToken) - Processes the request token after successful login
  • rdhandle(requestToken) - Alternative endpoint for handling authentication redirects

Portfolio Management

  • getHoldings() - Retrieves a list of equity holdings from Zerodha
  • getPositions() - 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:

  1. Go to Settings > MCP Servers
  2. Add a new server with your worker URL (e.g., https://zerodha-mcp.your-subdomain.workers.dev)
  3. 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:

  1. Add new methods to the ZerodhaWorker class in src/index.js
  2. Implement the desired Zerodha API calls using the Kite Connect API
  3. Format responses according to the MCP specification (using the content array format)
  4. Update the docs.json file to document the new methods
  5. 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

  1. User visits the login URL generated by getLoginUrl()
  2. After successful login, Zerodha redirects to the callback URL with a request token
  3. The /callback or /rdhandle endpoint processes the request token
  4. The access token is obtained and stored in the KV namespace
  5. 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:

MCP Documentation

For more information about the Model Context Protocol (MCP), refer to:

License

MIT

Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
WindsurfThe new purpose-built IDE to harness magic
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
Serper MCP ServerA Serper MCP Server
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Amap Maps高德地图官方 MCP Server
DeepChatYour AI Partner on Desktop
Playwright McpPlaywright MCP server
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
ChatWiseThe second fastest AI chatbot™
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
CursorThe AI Code Editor