delete_alert
Remove trading alerts from your Interactive Brokers account by specifying account and alert IDs to manage notification settings.
Instructions
Delete an alert. Usage: { "accountId": "<id>", "alertId": "<alertId>" }.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| accountId | Yes | ||
| alertId | Yes |
Implementation Reference
- src/tool-handlers.ts:631-659 (handler)The main handler function for the delete_alert tool. Ensures gateway readiness and authentication, calls the IB client to delete the alert, and returns the result as JSON or formatted error.async deleteAlert(input: DeleteAlertInput): 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.deleteAlert(input.accountId, input.alertId); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: this.formatError(error), }, ], }; }
- src/tool-definitions.ts:91-148 (schema)Zod schema definition for delete_alert input validation, including DeleteAlertZodShape and DeleteAlertZodSchema.export const DeleteAlertZodShape = { accountId: z.string(), alertId: z.string() }; // Flex Query Zod Shapes export const GetFlexQueryZodShape = { queryId: z.string(), queryName: z.string().optional(), // Optional friendly name for auto-saving parseXml: z.boolean().optional().default(true) }; export const ListFlexQueriesZodShape = { confirm: z.literal(true) }; export const ForgetFlexQueryZodShape = { queryId: z.string() }; // Full Zod Schemas (for validation if needed) export const AuthenticateZodSchema = z.object(AuthenticateZodShape); export const GetAccountInfoZodSchema = z.object(GetAccountInfoZodShape); export const GetPositionsZodSchema = z.object(GetPositionsZodShape); export const GetMarketDataZodSchema = z.object(GetMarketDataZodShape); export const PlaceOrderZodSchema = z.object(PlaceOrderZodShape).refine( (data) => { if (data.orderType === "LMT" && data.price === undefined) { return false; } if (data.orderType === "STP" && data.stopPrice === undefined) { return false; } return true; }, { message: "LMT orders require price, STP orders require stopPrice", path: ["price", "stopPrice"] } ); export const GetOrderStatusZodSchema = z.object(GetOrderStatusZodShape); export const GetLiveOrdersZodSchema = z.object(GetLiveOrdersZodShape); export const ConfirmOrderZodSchema = z.object(ConfirmOrderZodShape); export const GetAlertsZodSchema = z.object(GetAlertsZodShape); export const CreateAlertZodSchema = z.object(CreateAlertZodShape); export const ActivateAlertZodSchema = z.object(ActivateAlertZodShape); export const DeleteAlertZodSchema = z.object(DeleteAlertZodShape);
- src/tools.ts:134-140 (registration)Registration of the delete_alert tool with the MCP server, linking to the handler and schema.// Register delete_alert tool server.tool( "delete_alert", "Delete an alert. Usage: `{ \"accountId\": \"<id>\", \"alertId\": \"<alertId>\" }`.", DeleteAlertZodShape, async (args) => await handlers.deleteAlert(args) );
- src/ib-client.ts:632-654 (helper)IBClient helper method that performs the actual HTTP DELETE request to the IB Gateway API to delete the specified alert.async deleteAlert(accountId: string, alertId: string): Promise<any> { try { Logger.log(`[ALERT] Deleting alert ${alertId} for account ${accountId}`); const response = await this.client.delete( `/iserver/account/${accountId}/alert/${alertId}` ); Logger.log("[ALERT] Alert deletion response:", response.data); return response.data; } catch (error) { Logger.error("[ALERT] Failed to delete alert:", error); // Check if this is likely an authentication error if (this.isAuthenticationError(error)) { const authError = new Error("Authentication required to delete alerts. Please authenticate with Interactive Brokers first."); (authError as any).isAuthError = true; throw authError; } throw new Error("Failed to delete alert: " + (error as any).message); } }