Zerodha_MCP_Server

karthikrajask/Zerodha_MCP_Server

3.1

If you are the rightful owner of Zerodha_MCP_Server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to dayong@mcphub.com.

This is a Model Context Protocol (MCP) server in TypeScript that provides trading tools using the Zerodha Kite Connect JavaScript SDK.

Tools
5
Resources
0
Prompts
0

Trading MCP Server (Kite Connect)

This is a Model Context Protocol (MCP) server in TypeScript that exposes trading tools using the official Zerodha Kite Connect JavaScript SDK. It enables programmatic trading, order management, and portfolio access via MCP tools.

Features

  • Trading Tools: Authenticate, place orders, fetch orders, and view holdings using Kite Connect.
  • Connect to Agent Builder: Integrate with the MCP Agent Builder for testing and debugging.
  • Debug with MCP Inspector: Use MCP Inspector to interactively test and debug all trading tools.

Getting Started

Prerequisites:

  • Node.js
  • Zerodha Kite Connect API key and secret

Setup:

  1. Clone this repository and install dependencies:
    npm install
    npm run build
    
  2. Copy .env.example to .env and fill in your Kite API credentials:
    KITE_API_KEY=your_api_key_here
    KITE_API_SECRET=your_api_secret_here
    KITE_REDIRECT_URI=http://localhost:3456/kite/callback
    
  3. Start the MCP server:
    npm run dev:http   # HTTP transport (for Inspector)
    npm run dev:stdio  # STDIO transport (for Agent Builder)
    

What's Included

Folder / FileContents
.vscodeVSCode debug configs
.aitkAI Toolkit configs
srcSource code for the trading MCP server
.env.exampleExample environment variable file

Debugging and Testing

You can debug and test the server using:

  • Agent Builder: Connects via STDIO for local tool testing.
  • MCP Inspector: Connects via HTTP for interactive tool calls and debugging.

All debugging modes support breakpoints in your tool implementation code.

MCP Tools (Kite Connect)

The following tools are registered and available via MCP:

  • kite_get_login_url: Returns a login URL for user authentication. Input: optional redirect_uri.
  • kite_generate_session: Exchanges a request_token for an access token and session details. Input: request_token.
  • kite_get_orders: Fetches all user orders. Input: access_token.
  • kite_place_order: Places a new order. Inputs: access_token, exchange, tradingsymbol, transaction_type, quantity, optional order_type, product, price.
  • kite_get_holdings: Fetches user holdings. Input: access_token.

Example Flow

  1. Call kite_get_login_url and open the returned URL in your browser. After login, Zerodha redirects to your redirect_uri with a request_token.
  2. Call kite_generate_session with the request_token to get an access_token.
  3. Use the access_token in kite_get_orders, kite_place_order, and kite_get_holdings.

Security Note: Treat access tokens as secrets. For production, store tokens securely and never expose them in logs or client-side code.

Customization

You can change ports and parameters in .vscode/tasks.json, src/index.ts, .aitk/mcp.json, and .inspector.json as needed.

Feedback

If you have feedback or suggestions, please open an issue on the AI Toolkit GitHub repository