Skip to main content
Glama
yogendhra9

Zerodha Trading Bot

by yogendhra9

Buy-Stock

Execute stock purchases on Zerodha platform by specifying stock symbol and quantity for automated trading operations.

Instructions

This tool buys 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:67-80 (registration)
    Registration of the 'Buy-Stock' MCP tool, including inline Zod input schema and the main handler function that initializes the trading client and delegates to placeOrder.
    server.tool(
      "Buy-Stock",
      "This tool buys 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, "BUY");
          return { content: [{ type: "text", text: String(response) }] };
        } catch (error) {
          return { content: [{ type: "text", text: `Error: ${error.message}` }] };
        }
      }
    );
  • index.js:71-79 (handler)
    The inline handler function for the Buy-Stock tool, which handles input parameters, initializes trading, places the BUY order, and returns response or error.
    async ({ stock, qty }) => {
      try {
        const trading = await initializeTrading();
        const response = await trading.placeOrder(stock, qty, "BUY");
        return { content: [{ type: "text", text: String(response) }] };
      } catch (error) {
        return { content: [{ type: "text", text: `Error: ${error.message}` }] };
      }
    }
  • Zod schema for Buy-Stock tool input: stock (string), qty (number).
    { stock: z.string(), qty: z.number() },
  • Supporting helper: placeOrder method in ZerodhaTrading class that performs the actual market order placement via KiteConnect API.
    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;
      }
  • Supporting helper: initializeTrading function that obtains a valid access token and instantiates the ZerodhaTrading client.
    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?

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states this is a buy operation at market price, implying a financial transaction with real-world consequences, but lacks critical details: it doesn't mention authentication requirements, potential costs/fees, execution risks (e.g., market volatility), confirmation mechanisms, or error handling. For a high-stakes tool with zero annotation coverage, this is a significant gap.

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, efficient sentence that front-loads the core action ('buys a stock') and includes essential context (platform, parameters). There's no wasted verbiage, but it could be slightly more structured (e.g., separating purpose from parameter roles) for optimal clarity.

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?

Given the tool's complexity (financial transaction with real-world impact), lack of annotations, no output schema, and low schema coverage, the description is incomplete. It omits critical context: expected output (e.g., order confirmation, trade ID), error cases, dependencies (e.g., user session), and behavioral nuances like rate limits or idempotency. The agent lacks sufficient information to use this tool safely and effectively.

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

Parameters3/5

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

The schema description coverage is 0%, so the description must compensate. It adds meaning by explaining that 'stock' refers to the stock name and 'qty' is the quantity to buy, and implies these are required for the transaction. However, it doesn't specify format details (e.g., stock symbol conventions, integer vs. decimal quantities) or constraints (e.g., minimum order size). The description provides basic semantics but leaves key details ambiguous.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'buys a stock in the zerodha trading platform for the given quantity and stock name at the current market price for the given user'. It specifies the verb ('buys'), resource ('stock'), platform ('zerodha trading platform'), and key parameters. However, it doesn't explicitly differentiate from its sibling 'Sell-Stock' beyond the obvious verb difference, which keeps it from a perfect score.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It mentions no prerequisites (e.g., user authentication, market hours), no exclusions (e.g., when not to buy), and doesn't reference sibling tools like 'Sell-Stock' or 'Show-Portfolio' for context. The agent must infer usage solely from the purpose statement.

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