Skip to main content
Glama
europarcel
by europarcel

Cancel Order

cancelOrder

Cancel an existing order by providing the order ID and selecting a refund channel (wallet or card).

Instructions

Cancel an existing order. Parameters: order_id (required - accepts numbers like 6505 and strings like '6505'), refund_channel ('wallet' or 'card', required)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
order_idYesThe order ID to cancel
refund_channelYesWhere to process the refund: 'wallet' or 'card'

Implementation Reference

  • The main tool handler that registers the 'cancelOrder' tool with the MCP server, defines input schema (order_id, refund_channel), validates parameters, calls the API client, and formats the response.
    export function registerCancelOrderTool(server: McpServer): void {
      // Create API client instance
    
      // Register cancelOrder tool
      server.registerTool(
        "cancelOrder",
        {
          title: "Cancel Order",
          description:
            "Cancel an existing order. Parameters: order_id (required - accepts numbers like 6505 and strings like '6505'), refund_channel ('wallet' or 'card', required)",
          inputSchema: {
            order_id: z
              .union([z.string(), z.number()])
              .describe("The order ID to cancel"),
            refund_channel: z
              .enum(["wallet", "card"])
              .describe("Where to process the refund: 'wallet' or 'card'"),
          },
        },
        async (args: any) => {
          // Get API key from async context
          const apiKey = apiKeyStorage.getStore();
    
          if (!apiKey) {
            return {
              content: [
                {
                  type: "text",
                  text: "Error: X-API-KEY header is required",
                },
              ],
            };
          }
    
          // Create API client with customer's API key
          const client = new EuroparcelApiClient(apiKey);
    
          try {
            if (!args.order_id) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: order_id parameter is required",
                  },
                ],
              };
            }
    
            const orderId = Number(args.order_id);
            if (!Number.isInteger(orderId) || orderId <= 0) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: order_id must be a positive integer",
                  },
                ],
              };
            }
    
            if (
              !args.refund_channel ||
              !["wallet", "card"].includes(args.refund_channel)
            ) {
              return {
                content: [
                  {
                    type: "text",
                    text: "Error: refund_channel parameter is required and must be 'wallet' or 'card'",
                  },
                ],
              };
            }
    
            logger.info("Cancelling order", {
              order_id: orderId,
              refund_channel: args.refund_channel,
            });
    
            const result = await client.cancelOrder(orderId, args.refund_channel);
    
            logger.info("Order cancellation result", result);
    
            let formattedResponse = result.success ? "✅ " : "❌ ";
            formattedResponse += result.message + "\n\n";
    
            if (result.success) {
              formattedResponse += `Order #${result.order_id} has been cancelled.\n`;
              if (result.status) {
                formattedResponse += `Status: ${result.status}\n`;
              }
              formattedResponse += `Refund will be processed to: ${args.refund_channel}\n`;
    
              if (result.details) {
                formattedResponse += "\nAdditional Details:\n";
                Object.entries(result.details).forEach(([key, value]) => {
                  formattedResponse += `   ${key}: ${value}\n`;
                });
              }
            }
    
            return {
              content: [
                {
                  type: "text",
                  text: formattedResponse,
                },
              ],
            };
          } catch (error: any) {
            logger.error("Failed to cancel order", error);
    
            return {
              content: [
                {
                  type: "text",
                  text: `Error cancelling order: ${error.message || "Unknown error"}`,
                },
              ],
            };
          }
        },
      );
  • TypeScript interface defining the shape of the API response for cancelOrder.
    export interface CancelOrderResponse {
      success: boolean;
      order_id: number;
      status?: string;
      message: string;
      details?: any;
    }
  • API client helper method that sends a DELETE request to /orders/{orderId} with a refund_channel query parameter to cancel an order.
    async cancelOrder(
      orderId: number,
      refundChannel: "wallet" | "card",
    ): Promise<CancelOrderResponse> {
      const response = await this.client.delete<CancelOrderResponse>(
        `/orders/${orderId}`,
        {
          params: {
            refund_channel: refundChannel,
          },
        },
      );
      return response.data;
    }
  • Registration point where cancelOrder tool is imported, registered alongside other order tools, and re-exported.
    import { registerCancelOrderTool } from "./cancelOrder.js";
    import { registerTrackAwbsByCarrierTool } from "./trackAwbsByCarrier.js";
    import { registerGenerateLabelLinkTool } from "./generateLabelLink.js";
    import { registerTrackOrdersByIdsTool } from "./trackOrdersByIds.js";
    import { registerPricingTools } from "./getPricing.js";
    import { registerCreateOrderTool } from "./createOrder.js";
    import { logger } from "../../utils/logger.js";
    
    export function registerOrderTools(server: McpServer): void {
      logger.info("Registering order tools...");
    
      // Register all order-related tools
      registerGetOrdersTool(server);
      registerGetOrderByIdTool(server);
      registerCancelOrderTool(server);
      registerTrackAwbsByCarrierTool(server);
      registerGenerateLabelLinkTool(server);
      registerTrackOrdersByIdsTool(server);
      registerCreateOrderTool(server);
    
      // Register pricing tools as well since they're order-related
      registerPricingTools(server);
    
      logger.info("All order tools registered successfully");
    }
    
    // Export individual registration functions if needed
    export { registerGetOrdersTool } from "./getOrders.js";
    export { registerCreateOrderTool } from "./createOrder.js";
    export { registerGetOrderByIdTool } from "./getOrderById.js";
    export { registerCancelOrderTool } from "./cancelOrder.js";
  • Zod input schema for the cancelOrder tool defining order_id (string|number) and refund_channel ('wallet'|'card').
    inputSchema: {
      order_id: z
        .union([z.string(), z.number()])
        .describe("The order ID to cancel"),
      refund_channel: z
        .enum(["wallet", "card"])
        .describe("Where to process the refund: 'wallet' or 'card'"),
    },
Behavior2/5

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

No annotations are provided, so the description must disclose behavioral traits. It only states the action and parameters, omitting effects like whether the order is refunded, if it's reversible, or confirmation behavior.

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 brief (one sentence plus parameter note) and front-loaded. It trades off some detail for conciseness, but remains efficient.

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?

Missing output schema and annotations. The description does not indicate return values, success/failure signals, or side effects, leaving the agent underinformed for a mutation tool.

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?

Schema coverage is 100%, so the description adds minimal value beyond confirming type flexibility (e.g., order_id accepts numbers and strings). It repeats schema info without deeper semantics.

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 action ('Cancel an existing order'), using a specific verb and resource. It distinguishes from sibling tools like createOrder or getOrderById.

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 when to use (to cancel an order) but provides no explicit guidance on prerequisites, such as order status or when cancellation is allowed. No alternatives mentioned.

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/europarcel/mcp-docker'

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