Skip to main content
Glama
baskcart

W3Ship MCP Server

by baskcart

add_item

Add products to a shopping cart using public key identification. Specify cart ID and item details to manage your order.

Instructions

Add an item to an existing shopping cart. Uses W3SHIP_PUBLIC_KEY as cartId if not provided.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cartIdYesPublic key ID of the cart. Optional if W3SHIP_PUBLIC_KEY is set.
itemYes

Implementation Reference

  • The handler logic for the 'add_item' tool. It retrieves the cart from valkeyService, adds the item to the cart's item list, and saves the updated cart back.
    case 'add_item': {
        const cartId = (args?.cartId as string) || CONFIGURED_KEY;
        if (!cartId) {
            return { content: [{ type: 'text', text: 'Error: No cart ID. Set W3SHIP_PUBLIC_KEY or provide a cartId.' }], isError: true };
        }
        const itemArg = args?.item as any;
        const cart = await valkeyService.getCart(cartId);
        if (!cart) {
            return { content: [{ type: 'text', text: `Error: Cart not found: ${cartId}` }], isError: true };
        }
        const cartItem = { id: Math.random().toString(36).substring(7), ...itemArg };
        cart.cartItem = cart.cartItem || [];
        cart.cartItem.push(cartItem);
        await valkeyService.saveCart(cart);
        return { content: [{ type: 'text', text: `Item added successfully to cart ${cartId}` }] };
    }
  • The input schema definition for the 'add_item' tool, defining the required cartId and item structure.
        name: 'add_item',
        description: 'Add an item to an existing shopping cart. Uses W3SHIP_PUBLIC_KEY as cartId if not provided.',
        inputSchema: {
            type: 'object',
            properties: {
                cartId: { type: 'string', description: 'Public key ID of the cart. Optional if W3SHIP_PUBLIC_KEY is set.' },
                item: {
                    type: 'object',
                    properties: {
                        productOffering: {
                            type: 'object',
                            properties: {
                                id: { type: 'string' },
                                name: { type: 'string' },
                            },
                            required: ['id'],
                        },
                        quantity: {
                            type: 'object',
                            properties: {
                                amount: { type: 'number' },
                            },
                            required: ['amount'],
                        },
                    },
                    required: ['productOffering'],
                },
            },
            required: ['cartId', 'item'],
        },
    },

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/baskcart/w3ship-mcp-server'

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