MCPcopy Index your code
hub / github.com/modelcontextprotocol/python-sdk / secure_payment

Function secure_payment

examples/snippets/servers/elicitation.py:54–74  ·  view source on GitHub ↗

Process a secure payment requiring URL confirmation. This demonstrates URL mode elicitation using ctx.elicit_url() for operations that require out-of-band user interaction.

(amount: float, ctx: Context)

Source from the content-addressed store, hash-verified

52
53@mcp.tool()
54async def secure_payment(amount: float, ctx: Context) -> str:
55 """Process a secure payment requiring URL confirmation.
56
57 This demonstrates URL mode elicitation using ctx.elicit_url() for
58 operations that require out-of-band user interaction.
59 """
60 elicitation_id = str(uuid.uuid4())
61
62 result = await ctx.elicit_url(
63 message=f"Please confirm payment of ${amount:.2f}",
64 url=f"https://payments.example.com/confirm?amount={amount}&id={elicitation_id}",
65 elicitation_id=elicitation_id,
66 )
67
68 if result.action == "accept":
69 # In a real app, the payment confirmation would happen out-of-band
70 # and you'd verify the payment status from your backend
71 return f"Payment of ${amount:.2f} initiated - check your browser to complete"
72 elif result.action == "decline":
73 return "Payment declined by user"
74 return "Payment cancelled"
75
76
77@mcp.tool()

Callers

nothing calls this directly

Calls 1

elicit_urlMethod · 0.45

Tested by

no test coverage detected