Skip to main content
Glama
hi5d
by hi5d

book_seats

Reserve seats for AMC movie showtimes by providing showtime ID, seat numbers, and user ID to confirm bookings.

Instructions

Reserves selected seats for the user.

Args: showtime_id: Showtime ID (e.g., "st001") seats: List of seat numbers (e.g., ["A5", "A6"]) user_id: User identifier

Returns: JSON string with booking confirmation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
showtime_idYes
seatsYes
user_idYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary handler for the book_seats tool in the standard MCP server. Validates input, checks seat availability by cross-referencing seats data and existing confirmed bookings, computes total price, creates a pending Booking object, stores it, and returns detailed JSON response.
    async def _book_seats(self, args: Dict[str, Any]) -> CallToolResult:
        """Book seats for a showtime"""
        showtime_id = args.get("showtime_id")
        seats = args.get("seats", [])
        user_id = args.get("user_id")
        
        if not showtime_id or showtime_id not in self.showtimes:
            return CallToolResult(
                content=[TextContent(type="text", text=json.dumps({"error": "Invalid showtime ID"}))]
            )
        
        if not seats or not user_id:
            return CallToolResult(
                content=[TextContent(type="text", text=json.dumps({"error": "Seats and user_id are required"}))]
            )
        
        # Check seat availability
        unavailable_seats = []
        total_price = 0.0
        
        showtime_seats = self.seats_data.get(showtime_id, [])
        seat_lookup = {s["seat_number"]: s for s in showtime_seats}
        
        for seat_num in seats:
            # Check if seat exists
            if seat_num not in seat_lookup:
                unavailable_seats.append(f"{seat_num} (doesn't exist)")
                continue
            
            # Check if already booked
            is_booked = any(
                seat_num in booking.seats and booking.status == "confirmed"
                for booking in self.bookings.values()
                if booking.showtime_id == showtime_id
            )
            
            if is_booked:
                unavailable_seats.append(f"{seat_num} (already booked)")
            else:
                seat_price = seat_lookup[seat_num].get("price", 15.00)
                total_price += seat_price
        
        if unavailable_seats:
            return CallToolResult(
                content=[TextContent(type="text", text=json.dumps({"error": f"Unavailable seats: {', '.join(unavailable_seats)}"}))]
            )
        
        # Create booking
        booking_id = str(uuid.uuid4())
        booking = Booking(
            booking_id=booking_id,
            showtime_id=showtime_id,
            seats=seats,
            user_id=user_id,
            status="pending",
            total_price=total_price,
            created_at=datetime.now().isoformat()
        )
        
        self.bookings[booking_id] = booking
        
        showtime = self.showtimes[showtime_id]
        theater = self.theaters.get(showtime.theater_id)
        movie = self.movies.get(showtime.movie_id)
        
        result = {
            "booking_id": booking_id,
            "status": "pending",
            "movie": movie.title if movie else "Unknown",
            "theater": theater.name if theater else "Unknown Theater",
            "date": showtime.date,
            "time": showtime.time,
            "seats": seats,
            "total_price": total_price
        }
        
        return CallToolResult(
            content=[TextContent(type="text", text=json.dumps(result, indent=2))]
        )
  • Tool registration in the list_tools handler, defining name, description, and input schema for book_seats.
    Tool(
        name="book_seats",
        description="Reserves selected seats for the user",
        inputSchema={
            "type": "object",
            "properties": {
                "showtime_id": {"type": "string", "description": "Showtime ID"},
                "seats": {"type": "array", "items": {"type": "string"}, "description": "List of seat numbers (e.g., ['A5', 'A6'])"},
                "user_id": {"type": "string", "description": "User identifier"}
            },
            "required": ["showtime_id", "seats", "user_id"]
        }
    ),
  • Core handler logic for book_seats in the FastMCP server implementation. Identical logic to the standard server: input validation, seat availability check, booking creation.
    def _book_seats(showtime_id: str, seats: List[str], user_id: str) -> str:
        """Internal implementation of book_seats"""
        if not showtime_id or showtime_id not in showtimes:
            return json.dumps({"error": "Invalid showtime ID"})
        
        if not seats or not user_id:
            return json.dumps({"error": "Seats and user_id are required"})
        
        # Check seat availability
        unavailable_seats = []
        total_price = 0.0
        
        showtime_seats = seats_data.get(showtime_id, [])
        seat_lookup = {s["seat_number"]: s for s in showtime_seats}
        
        for seat_num in seats:
            # Check if seat exists
            if seat_num not in seat_lookup:
                unavailable_seats.append(f"{seat_num} (doesn't exist)")
                continue
            
            # Check if already booked
            is_booked = any(
                seat_num in booking.seats and booking.status == "confirmed"
                for booking in bookings.values()
                if booking.showtime_id == showtime_id
            )
            
            if is_booked:
                unavailable_seats.append(f"{seat_num} (already booked)")
            else:
                seat_price = seat_lookup[seat_num].get("price", 15.00)
                total_price += seat_price
        
        if unavailable_seats:
            return json.dumps({"error": f"Unavailable seats: {', '.join(unavailable_seats)}"})
        
        # Create booking
        booking_id = str(uuid.uuid4())
        booking = Booking(
            booking_id=booking_id,
            showtime_id=showtime_id,
            seats=seats,
            user_id=user_id,
            status="pending",
            total_price=total_price,
            created_at=datetime.now().isoformat()
        )
        
        bookings[booking_id] = booking
        
        showtime = showtimes[showtime_id]
        theater = theaters.get(showtime.theater_id)
        movie = movies.get(showtime.movie_id)
        
        result = {
            "booking_id": booking_id,
            "status": "pending",
            "movie": movie.title if movie else "Unknown",
            "theater": theater.name if theater else "Unknown Theater",
            "date": showtime.date,
            "time": showtime.time,
            "seats": seats,
            "total_price": total_price
        }
        
        return json.dumps(result, indent=2)
  • FastMCP tool registration and wrapper handler for book_seats, which delegates to the internal _book_seats implementation.
    def book_seats(showtime_id: str, seats: List[str], user_id: str) -> str:
        """
        Reserves selected seats for the user.
        
        Args:
            showtime_id: Showtime ID (e.g., "st001")
            seats: List of seat numbers (e.g., ["A5", "A6"])
            user_id: User identifier
        
        Returns:
            JSON string with booking confirmation
        """
        return _book_seats(showtime_id, seats, user_id)

Tool Definition Quality

Score is being calculated. Check back soon.

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/hi5d/amc-mcp'

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