Skip to main content
Glama
hi5d
by hi5d

process_payment

Process simulated payment transactions for AMC movie bookings using booking ID, payment method, and amount to generate confirmation receipts.

Instructions

Handles simulated payment transaction.

Args: booking_id: Booking ID from book_seats payment_method: Payment method (e.g., "card", "cash") amount: Payment amount in USD

Returns: JSON string with payment confirmation and receipt

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
booking_idYes
payment_methodYes
amountYes

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Core handler logic for the process_payment tool in FastMCP implementation. Validates booking, simulates payment, updates booking status to confirmed, and returns confirmation details.
    def _process_payment(booking_id: str, payment_method: str, amount: float) -> str:
        """Internal implementation of process_payment"""
        if not booking_id or booking_id not in bookings:
            return json.dumps({"error": "Invalid booking ID"})
        
        booking = bookings[booking_id]
        
        if booking.status != "pending":
            return json.dumps({"error": f"Booking status is {booking.status}, expected pending"})
        
        if abs(amount - booking.total_price) > 0.01:
            return json.dumps({"error": f"Amount mismatch. Expected ${booking.total_price:.2f}, got ${amount:.2f}"})
        
        # Simulate payment processing (always succeeds in mock)
        payment_id = str(uuid.uuid4())
        receipt_url = f"https://amc.com/receipts/{payment_id}"
        
        payment = Payment(
            payment_id=payment_id,
            booking_id=booking_id,
            amount=amount,
            payment_method=payment_method,
            status="success",
            receipt_url=receipt_url
        )
        
        payments[payment_id] = payment
        
        # Update booking status
        booking.status = "confirmed"
        
        showtime = showtimes[booking.showtime_id]
        theater = theaters.get(showtime.theater_id)
        movie = movies.get(showtime.movie_id)
        
        result = {
            "payment_id": payment_id,
            "payment_status": "success",
            "booking_id": booking_id,
            "receipt_url": receipt_url,
            "confirmation": {
                "movie": movie.title if movie else "Unknown",
                "theater": theater.name if theater else "Unknown Theater",
                "date": showtime.date,
                "time": showtime.time,
                "seats": booking.seats,
                "total_paid": amount
            }
        }
        
        return json.dumps(result, indent=2)
  • FastMCP tool registration for process_payment using @mcp.tool() decorator, which defines the entry point and delegates to internal handler.
    @mcp.tool()
    def process_payment(booking_id: str, payment_method: str, amount: float) -> str:
        """
        Handles simulated payment transaction.
        
        Args:
            booking_id: Booking ID from book_seats
            payment_method: Payment method (e.g., "card", "cash")
            amount: Payment amount in USD
        
        Returns:
            JSON string with payment confirmation and receipt
        """
        return _process_payment(booking_id, payment_method, amount)
  • Registration of process_payment tool in list_tools() handler, including name, description, and explicit input schema.
    Tool(
        name="process_payment",
        description="Handles simulated payment transaction",
        inputSchema={
            "type": "object",
            "properties": {
                "booking_id": {"type": "string", "description": "Booking ID"},
                "payment_method": {"type": "string", "description": "Payment method (card, cash, etc.)"},
                "amount": {"type": "number", "description": "Payment amount"}
            },
            "required": ["booking_id", "payment_method", "amount"]
        }
    )
  • Input schema definition for process_payment tool, specifying parameters, types, descriptions, and required fields.
        inputSchema={
            "type": "object",
            "properties": {
                "booking_id": {"type": "string", "description": "Booking ID"},
                "payment_method": {"type": "string", "description": "Payment method (card, cash, etc.)"},
                "amount": {"type": "number", "description": "Payment amount"}
            },
            "required": ["booking_id", "payment_method", "amount"]
        }
    )
  • Core handler logic for process_payment in standard MCP server implementation. Extracts args, validates, processes payment, and returns CallToolResult.
    async def _process_payment(self, args: Dict[str, Any]) -> CallToolResult:
        """Process payment for a booking"""
        booking_id = args.get("booking_id")
        payment_method = args.get("payment_method")
        amount = args.get("amount")
        
        if not booking_id or booking_id not in self.bookings:
            return CallToolResult(
                content=[TextContent(type="text", text=json.dumps({"error": "Invalid booking ID"}))]
            )
        
        booking = self.bookings[booking_id]
        
        if booking.status != "pending":
            return CallToolResult(
                content=[TextContent(type="text", text=json.dumps({"error": f"Booking status is {booking.status}, expected pending"}))]
            )
        
        if abs(amount - booking.total_price) > 0.01:  # Allow for small rounding differences
            return CallToolResult(
                content=[TextContent(type="text", text=json.dumps({"error": f"Amount mismatch. Expected ${booking.total_price:.2f}, got ${amount:.2f}"}))]
            )
        
        # Simulate payment processing (always succeeds in mock)
        payment_id = str(uuid.uuid4())
        receipt_url = f"https://amc.com/receipts/{payment_id}"
        
        payment = Payment(
            payment_id=payment_id,
            booking_id=booking_id,
            amount=amount,
            payment_method=payment_method,
            status="success",
            receipt_url=receipt_url
        )
        
        self.payments[payment_id] = payment
        
        # Update booking status
        booking.status = "confirmed"
        
        showtime = self.showtimes[booking.showtime_id]
        theater = self.theaters.get(showtime.theater_id)
        movie = self.movies.get(showtime.movie_id)
        
        result = {
            "payment_id": payment_id,
            "payment_status": "success",
            "booking_id": booking_id,
            "receipt_url": receipt_url,
            "confirmation": {
                "movie": movie.title if movie else "Unknown",
                "theater": theater.name if theater else "Unknown Theater", 
                "date": showtime.date,
                "time": showtime.time,
                "seats": booking.seats,
                "total_paid": amount
            }
        }
        
        return CallToolResult(
            content=[TextContent(type="text", text=json.dumps(result, indent=2))]
        )
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states this is a 'simulated' transaction, which is useful context about it being non-production. However, it doesn't disclose critical behavioral traits like whether this is idempotent, what happens on failure, authentication requirements, or rate limits for a payment operation.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured with a clear purpose statement followed by organized Arg and Return sections. Every sentence earns its place by providing essential information without redundancy. The formatting with clear section headers enhances readability.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (payment transaction with 3 parameters), no annotations, but with an output schema (implied by Returns section), the description is moderately complete. It covers parameters well and mentions returns, but lacks behavioral context about simulation details, error handling, or integration with the booking system that would be helpful for an agent.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage, the description must fully compensate. It provides clear semantic meaning for all 3 parameters: booking_id links to another tool, payment_method gives examples, and amount specifies currency. This adds substantial value beyond the bare schema, though it doesn't specify format constraints like amount precision or payment_method validation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool 'handles simulated payment transaction', which is a specific verb+resource combination. It distinguishes itself from sibling tools like book_seats and get_showtimes by focusing on payment processing rather than booking or information retrieval. However, it doesn't explicitly contrast with potential payment alternatives (none exist in the sibling list).

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 usage context through the 'booking_id' parameter reference to 'book_seats', suggesting this should be used after booking. However, it doesn't provide explicit when-to-use guidance, alternatives, or exclusions. No mention of prerequisites like booking confirmation or payment method availability is made.

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

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