Skip to main content
Glama
yogendhra9

Zerodha Trading Bot

by yogendhra9

Sell-Stock

Execute market sell orders for stocks on Zerodha by specifying stock name and quantity to liquidate positions.

Instructions

This tool sells a stock in the zerodha trading platform for the given quantity and stock name at the current market price for the given user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
stockYes
qtyYes

Implementation Reference

  • index.js:82-95 (registration)
    MCP tool registration for 'Sell-Stock', including name, description, Zod input schema, and inline handler function that initializes trading client and calls placeOrder for SELL.
    server.tool(
      "Sell-Stock",
      "This tool sells a stock in the zerodha trading platform for the given quantity and stock name at the current market price for the given user",
      { stock: z.string(), qty: z.number() },
      async ({ stock, qty }) => {
        try {
          const trading = await initializeTrading();
          const response = await trading.placeOrder(stock, qty, "SELL");
          return { content: [{ type: "text", text: String(response) }] };
        } catch (error) {
          return { content: [{ type: "text", text: `Error: ${error.message}` }] };
        }
      }
    );
  • index.js:86-94 (handler)
    The core handler function executed when Sell-Stock tool is called, handling input params, initializing ZerodhaTrading, placing SELL order, and returning response or error.
    async ({ stock, qty }) => {
      try {
        const trading = await initializeTrading();
        const response = await trading.placeOrder(stock, qty, "SELL");
        return { content: [{ type: "text", text: String(response) }] };
      } catch (error) {
        return { content: [{ type: "text", text: `Error: ${error.message}` }] };
      }
    }
  • Input validation schema using Zod for stock name (string) and quantity (number).
    { stock: z.string(), qty: z.number() },
  • Helper method in ZerodhaTrading class that performs the actual order placement via KiteConnect API, used by Sell-Stock handler for SELL transactions.
    async placeOrder(tradingsymbol, quantity, type) {
      if (!tradingsymbol || !quantity || !type) {
        throw new Error(
          "Please provide all required parameters: tradingsymbol, quantity, and type"
        );
      }
    
      try {
        const response = await this.kc.placeOrder("regular", {
          exchange: "NSE",
          tradingsymbol: tradingsymbol,
          transaction_type: type,
          quantity: quantity,
          product: "CNC",
          order_type: "MARKET",
        });
        return response;
      } catch (err) {
        if (err.error_type === "InputException") {
          throw new Error(
            `Invalid trading symbol or order parameters: ${err.message}`
          );
        }
        throw err;
      }
  • Utility function to initialize ZerodhaTrading instance with a valid access token from TokenManager, called by Sell-Stock handler.
    async function initializeTrading() {
      try {
        const accessToken = await tokenManager.getValidToken();
        return new ZerodhaTrading(apiKey, accessToken);
      } catch (error) {
        console.error("Error initializing trading:", error.message);
        throw error;
      }
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden. It discloses the action is a sell transaction at market price, but doesn't mention critical behavioral aspects like authentication requirements, transaction costs, settlement time, risk warnings, or what happens on execution failure. For a financial transaction tool with zero annotation coverage, this leaves significant gaps.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, reasonably efficient sentence that packs key information: action, platform, parameters, pricing mechanism, and user context. While dense, it avoids unnecessary words and front-loads the core purpose.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a financial transaction tool with no annotations, no output schema, and 0% schema description coverage, the description is incomplete. It lacks information about return values, error conditions, side effects, authentication needs, and platform-specific constraints that would be essential for safe and correct usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It mentions 'stock name' and 'quantity' but doesn't provide format details (e.g., stock symbol format, quantity constraints like minimum lots), validation rules, or examples. The description adds basic meaning but insufficient detail for reliable parameter understanding.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('sells a stock'), target resource ('in the zerodha trading platform'), and scope ('for the given user'). It distinguishes from sibling tools like 'Buy-Stock' by specifying the opposite trading action, and from 'Show-Portfolio' by being an execution rather than query tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage context ('sells a stock... at the current market price') but doesn't explicitly state when to use this versus alternatives like 'Buy-Stock' or prerequisites. It mentions the platform (Zerodha) and user context, but lacks explicit guidance on timing, conditions, or exclusions.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/yogendhra9/ZerodhaMCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server