Skip to main content
Glama
code-rabi

Interactive Brokers MCP Server

by code-rabi

create_alert

Set up automated trading alerts to monitor specific market conditions and receive notifications when criteria are met.

Instructions

Create a new trading alert. Usage: { "accountId": "<id>", "alertRequest": { "alertName": "Price Alert", "conditions": [{ "conidex": "265598", "type": "price", "operator": ">", "triggerMethod": "last", "value": "150" }] } }.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
accountIdYes
alertRequestYes

Implementation Reference

  • The primary handler function for the 'create_alert' MCP tool. Ensures gateway readiness and authentication (if headless mode), calls IBClient.createAlert, formats the result as ToolHandlerResult, and handles errors.
    async createAlert(input: CreateAlertInput): Promise<ToolHandlerResult> {
      try {
        // Ensure Gateway is ready
        await this.ensureGatewayReady();
        
        // Ensure authentication in headless mode
        if (this.context.config.IB_HEADLESS_MODE) {
          await this.ensureAuth();
        }
        
        const result = await this.context.ibClient.createAlert(input.accountId, input.alertRequest);
        return {
          content: [
            {
              type: "text",
              text: JSON.stringify(result, null, 2),
            },
          ],
        };
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: this.formatError(error),
            },
          ],
        };
      }
  • Zod input schema shape (CreateAlertZodShape) defining validation rules for the create_alert tool parameters, including accountId and detailed alertRequest structure.
    export const CreateAlertZodShape = {
      accountId: z.string(),
      alertRequest: z.object({
        orderId: z.number().optional(),
        alertName: z.string(),
        alertMessage: z.string().optional(),
        alertRepeatable: z.number().optional(),
        expireTime: z.string().optional(),
        outsideRth: z.number().optional(),
        iTWSOrdersOnly: z.number().optional(),
        showPopup: z.number().optional(),
        toolId: z.number().optional(),
        playAudio: z.string().optional(),
        emailNotification: z.string().optional(),
        sendMessage: z.number().optional(),
        tif: z.string().optional(),
        logicBind: z.string().optional(),
        conditions: z.array(z.object({
          conidex: z.string(),
          type: z.string(),
          operator: z.string(),
          triggerMethod: z.string(),
          value: z.string(),
          logicBind: z.string().optional(),
          timeZone: z.string().optional()
        }))
      })
    };
  • src/tools.ts:118-123 (registration)
    MCP server tool registration for 'create_alert', specifying name, description, input schema, and handler function reference.
    // Register create_alert tool
    server.tool(
      "create_alert",
      "Create a new trading alert. Usage: `{ \"accountId\": \"<id>\", \"alertRequest\": { \"alertName\": \"Price Alert\", \"conditions\": [{ \"conidex\": \"265598\", \"type\": \"price\", \"operator\": \">\", \"triggerMethod\": \"last\", \"value\": \"150\" }] } }`.",
      CreateAlertZodShape,
      async (args) => await handlers.createAlert(args)
  • IBClient helper method that performs the actual HTTP POST request to the IB Gateway API endpoint /iserver/account/{accountId}/alert to create the alert, with logging and authentication error handling.
    async createAlert(accountId: string, alertRequest: any): Promise<any> {
      try {
        Logger.log(`[ALERT] Creating alert for account ${accountId}:`, alertRequest);
        
        const response = await this.client.post(
          `/iserver/account/${accountId}/alert`,
          alertRequest
        );
    
        Logger.log("[ALERT] Alert creation response:", response.data);
        return response.data;
      } catch (error) {
        Logger.error("[ALERT] Failed to create alert:", error);
        
        // Check if this is likely an authentication error
        if (this.isAuthenticationError(error)) {
          const authError = new Error("Authentication required to create alerts. Please authenticate with Interactive Brokers first.");
          (authError as any).isAuthError = true;
          throw authError;
        }
        
        throw new Error("Failed to create alert: " + (error as any).message);
      }
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states 'Create a new trading alert' which implies a write/mutation operation, but doesn't disclose behavioral traits like permissions needed, whether it's idempotent, rate limits, error conditions, or what happens on success/failure. The example shows a request format but doesn't explain the tool's behavior beyond the basic action.

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

Conciseness3/5

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

The description is appropriately concise with two sentences: one stating the purpose and one showing an example. However, the example is quite long and could be summarized or explained rather than showing a full JSON blob. The structure is front-loaded with the purpose, but the example dominates the description.

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 complexity (2 parameters with nested objects, 0% schema coverage, no annotations, no output schema), the description is incomplete. It shows a basic example but doesn't explain the full parameter semantics, behavioral traits, error handling, or return values. For a mutation tool with rich parameters, this leaves significant gaps for an AI agent.

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 provides an example with 'accountId' and 'alertRequest' containing 'alertName' and 'conditions', which adds some meaning beyond the bare schema. However, it doesn't explain the other 13+ properties in alertRequest or their purposes, leaving most parameters undocumented. The example is helpful but incomplete.

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 'Create a new trading alert' which specifies the verb (create) and resource (trading alert). It distinguishes from siblings like 'delete_alert' and 'get_alerts' by indicating creation rather than deletion or retrieval. However, it doesn't explicitly differentiate from 'activate_alert' which might be a related but different operation.

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 doesn't mention when to create alerts versus using other trading tools like 'place_order' or 'get_alerts', nor does it specify prerequisites (e.g., whether authentication is required first). The example shows usage but doesn't explain context.

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/code-rabi/interactive-brokers-mcp'

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