Skip to main content
Glama

MCP Code Expert System

by tomsiwik
javascript_example.js1.41 kB
/** * A simple shopping cart implementation for demonstration purposes */ function ShoppingCart() { this.items = []; this.total = 0; } ShoppingCart.prototype.addItem = function (item) { if (!item.id || !item.name || item.price === undefined) { console.log("Invalid item"); return false; } this.items.push(item); this.calculateTotal(); return true; }; ShoppingCart.prototype.removeItem = function (itemId) { var initialLength = this.items.length; this.items = this.items.filter(function (item) { return item.id !== itemId; }); if (this.items.length === initialLength) { console.log("Item not found: " + itemId); return false; } this.calculateTotal(); return true; }; ShoppingCart.prototype.calculateTotal = function () { var total = 0; for (var i = 0; i < this.items.length; i++) { total += this.items[i].price; } this.total = total; }; ShoppingCart.prototype.checkout = function () { if (this.items.length === 0) { console.log("Cannot checkout an empty cart"); return false; } // Process payment console.log("Processing payment for: $" + this.total); // Clear cart this.items = []; this.total = 0; return true; }; // Example usage var cart = new ShoppingCart(); cart.addItem({ id: 1, name: "Product 1", price: 10.99 }); cart.addItem({ id: 2, name: "Product 2", price: 5.99 }); cart.removeItem(1); cart.checkout();

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/tomsiwik/mcp-experts'

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