Kite MCP Server

repository·master·Indexed 43 days ago

https://github.com/zerodha/kite-mcp-server

A Model Context Protocol (MCP) server providing AI assistants with secure, standardized access to the Kite Connect trading API for managing portfolios, viewing market data, and executing trades. Supports hosted usage via mcp.kite.trade or self-hosting in sse, stdio, http, and hybrid modes.

Tokens
2.7K
Snippets
12
Records
18
Agent score
56%

What's inside Kite MCP Server

  1. Self-host the Kite MCP Server

    master

    To run the server locally with your own Kite Connect API credentials, follow these steps:

    1. Prerequisites: Ensure you have Go 1.21 or later installed.
    2. Clone the repository:
      git clone https://github.com/zerodha/kite-mcp-server
      cd kite-mcp-server
    3. Configure environment variables: Create a .env file in the root directory with your credentials:
      KITE_API_KEY=your_api_key
      KITE_API_SECRET=your_api_secret
      APP_MODE=http
      APP_PORT=8080
      APP_HOST=localhost
      PUBLIC_BASE_URL=http://localhost:8080
      Alternatively, use just init-env to initialize the config.
    4. Run the server:
      # Build and run
      go build -o kite-mcp-server
      ./kite-mcp-server
      
      # Or run directly
      go run main.go
  2. Configure Claude Desktop with Self-Hosted Modes

    master

    Depending on how you run the server locally, choose one of the following configurations for claude_desktop_config.json:

    HTTP Mode

    Use this for the /mcp endpoint. Requires --allow-http flag.

    {
      "mcpServers": {
        "kite": {
          "command": "npx",
          "args": ["mcp-remote", "http://localhost:8080/mcp", "--allow-http"],
          "env": {
            "APP_MODE": "http",
            "KITE_API_KEY": "your_api_key",
            "KITE_API_SECRET": "your_api_secret"
          }
        }
      }
    }

    SSE Mode

    Use this for the /sse endpoint. Requires --allow-http flag.

    {
      "mcpServers": {
        "kite": {
          "command": "npx",
          "args": ["mcp-remote", "http://localhost:8080/sse", "--allow-http"],
          "env": {
            "APP_MODE": "sse",
            "KITE_API_KEY": "your_api_key",
            "KITE_API_SECRET": "your_api_secret"
          }
        }
      }
    }

    stdio Mode

    Requires building the binary first. You must use the absolute path to the binary.

    {
      "mcpServers": {
        "kite": {
          "command": "/full/path/to/your/kite-mcp-server",
          "env": {
            "APP_MODE": "stdio",
            "KITE_API_KEY": "your_api_key",
            "KITE_API_SECRET": "your_api_secret"
          }
        }
      }
    }
  3. Configure Claude Desktop with Hosted Mode

    master

    To use the hosted Kite MCP server with Claude Desktop, add the following configuration to your claude_desktop_config.json file. This uses mcp-remote to bridge the connection.

    {
      "mcpServers": {
        "kite": {
          "command": "npx",
          "args": ["mcp-remote", "https://mcp.kite.trade/mcp"]
        }
      }
    }
  4. Use the Hosted Kite MCP Server (Recommended)

    master

    The easiest way to use Kite MCP is via the hosted version at mcp.kite.trade. This requires no installation or local API keys. You can connect your AI client directly to the hosted endpoints.

    Quick Setup: Add https://mcp.kite.trade/mcp to your MCP client configuration.

    https://mcp.kite.trade/mcp
  5. Configure Kite MCP Server modes

    master

    The server's behavior is determined by the APP_MODE environment variable. The available modes are:

    • sse: Server-Sent Events mode. Provides endpoints for SSE-based MCP communication.
    • stdio: Standard IO mode. Typically used for local CLI-based MCP integrations.
    • http: Streamable HTTP mode. Provides a single /mcp endpoint for streamable HTTP MCP communication.
    • hybrid: Combined mode. Enables both SSE and MCP endpoints on the same server.

    Defaults:

    • APP_MODE: http (via DefaultAppMode)
    • APP_PORT: 8080 (via DefaultPort)
    • APP_HOST: localhost (via DefaultHost)
  6. Initialize and run the Kite MCP Server

    master

    To use the Kite MCP Server in a Go application, use the app package to create a new application instance, load its configuration, and start the server. The server can run in several modes depending on your integration needs (SSE, StdIO, HTTP, or Hybrid).

    1. Call NewApp(logger) with a *slog.Logger to initialize the application.
    2. Call LoadConfig() to validate environment variables.
    3. Call RunServer() to start the lifecycle management and the chosen server mode.
    package main
    
    import (
    	"log/slog"
    	"github.com/zerodha/kite-mcp-server/app"
    )
    
    func main() {
    	logger := slog.Default()
    	appInstance := app.NewApp(logger)
    
    	if err := appInstance.LoadConfig(); err != nil {
    		panic(err)
    	}
    
    	if err := appInstance.RunServer(); err != nil {
    		panic(err)
    	}
    }
  7. Create a read-only instance using EXCLUDED_TOOLS

    master

    To prevent an AI agent from performing destructive actions (like placing or canceling orders), you can exclude specific tools by setting the EXCLUDED_TOOLS environment variable with a comma-separated list of tool names.

    Example for a read-only setup:

    EXCLUDED_TOOLS=place_order,modify_order,cancel_order
  8. Configure logging via LOG_LEVEL

    master

    The Kite MCP Server uses structured logging via slog. You can control the verbosity of the logs by setting the LOG_LEVEL environment variable. The server logs to os.Stderr.

    # Example: Set log level to debug
    export LOG_LEVEL=debug
  9. Configure the App Config via environment variables

    master

    The app.Config struct is populated from the following environment variables:

    VariableDescription
    KITE_API_KEYYour Kite API Key (Required)
    KITE_API_SECRETYour Kite API Secret (Required)
    APP_MODEServer mode (sse, stdio, http, hybrid)
    APP_PORTPort to listen on
    APP_HOSTHost to listen on
    PUBLIC_BASE_URLThe public-facing URL of the server
    EXCLUDED_TOOLSComma-separated list of tools to exclude from MCP registration
    ADMIN_ENDPOINT_SECRET_PATHPath used to secure the admin/metrics endpoint
  10. Reference: Available Kite MCP Tools

    master

    The server provides the following tools for AI agents to interact with the Kite Connect API:

    ### Setup & Authentication
    - `login` - Login to Kite API and generate authorization link
    
    ### Market Data
    - `get_quotes` - Get real-time market quotes
    - `get_ltp` - Get last traded price
    - `get_ohlc` - Get OHLC data
    - `get_historical_data` - Historical price data
    - `search_instruments` - Search trading instruments
    
    ### Portfolio & Account
    - `get_profile` - User profile information
    - `get_margins` - Account margins
    - `get_holdings` - Portfolio holdings
    - `get_positions` - Current positions
    - `get_mf_holdings` - Mutual fund holdings
    
    ### Orders & Trading
    - `place_order` - Place new orders
    - `modify_order` - Modify existing orders
    - `cancel_order` - Cancel orders
    - `get_orders` - List all orders
    - `get_trades` - Trading history
    - `get_order_history` - Order execution history
    - `get_order_trades` - Get trades for a specific order
    
    ### GTT Orders
    - `get_gtts` - List GTT orders
    - `place_gtt_order` - Create GTT orders
    - `modify_gtt_order` - Modify GTT orders
    - `delete_gtt_order` - Delete GTT orders
  11. Reference: Kite MCP Server Environment Variables

    master

    Use these environment variables to configure the self-hosted server behavior.

    | Environment Variable | Default | Description |
    | -------------------- | ------- | ----------- |
    | `KITE_API_KEY` | Required | Your Kite Connect API key |
    | `KITE_API_SECRET` | Required | Your Kite Connect API secret |
    | `APP_MODE` | `http` | Server mode: `stdio`, `http`, `sse`, or `hybrid` |
    | `APP_PORT` | `8080` | Server port (HTTP/SSE/hybrid modes) |
    | `APP_HOST` | `localhost` | Server host / bind address (HTTP/SSE/hybrid modes) |
    | `PUBLIC_BASE_URL` | derived | Public base URL used for browser-facing auth links |
    | `EXCLUDED_TOOLS` | _(empty)_ | Comma-separated list of tools to exclude from registration |