Assignment
Let’s see if we can organize the e-commerce server that we created in Chapter 3. Here’s the code for reference. Create a tools directory – use Pydantic and a low-level API.
# server.py
from mcp.server.fastmcp import FastMCP
import uuid
# Create an MCP server
mcp = FastMCP("Demo")
class Customer:
def __init__(self,id: int, name: str, email: str):
self.id = id
self.name = name
self.email = email
class Category:
def __init__(self, name: str, description: str):
self.id = uuid.uuid4()
self.name = name
self.description = description
class Product:
def __init__(self, name: str, price: float, description: str):
self.name = name
self.price = price
self.description = description
class CartItem:
def __init__(self, cart_id: int, product_id: int, quantity: int):
if cart_id != 0:
self.cart_id = cart_id
else:
self.cart_id =...