Skip to main content
Glama

verify_l402_payment

Validate L402 token payment confirmation to grant resource access after receiving macaroon and preimage from payer.

Instructions

Verify an L402 token (macaroon + preimage) to confirm payment was made. Use this after receiving an L402 token from a payer to validate they paid before granting access to the resource. Requires LIGHTNING_ENABLE_API_KEY with an Agentic Commerce subscription.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
macaroonYesBase64-encoded macaroon from the L402 token
preimageYesHex-encoded preimage (proof of payment)

Implementation Reference

  • The handler function that executes the `verify_l402_payment` tool logic.
    async def verify_l402_payment(
        macaroon: str,
        preimage: str,
        api_client: "LightningEnableApiClient | None" = None,
    ) -> str:
        """
        Verify an L402 token (macaroon + preimage) to confirm payment was made.
    
        Use this after receiving an L402 token from a payer to validate they paid
        before granting access to the resource.
    
        Args:
            macaroon: Base64-encoded macaroon from the L402 token
            preimage: Hex-encoded preimage (proof of payment)
            api_client: Lightning Enable API client instance
    
        Returns:
            JSON with verification result or error message
        """
        # Input validation
        if not macaroon or not macaroon.strip():
            return json.dumps({
                "success": False,
                "error": "Macaroon is required. This is the base64-encoded macaroon from the L402 token."
            })
    
        if not preimage or not preimage.strip():
            return json.dumps({
                "success": False,
                "error": "Preimage is required. This is the hex-encoded proof of payment from the L402 token."
            })
    
        if api_client is None:
            return json.dumps({
                "success": False,
                "error": "Lightning Enable API service not available"
            })
    
        if not api_client.is_configured:
            return json.dumps({
                "success": False,
                "error": "Lightning Enable API key not configured. "
                         "Set LIGHTNING_ENABLE_API_KEY environment variable or add 'lightningEnableApiKey' to ~/.lightning-enable/config.json. "
                         "Requires an Agentic Commerce subscription at https://lightningenable.com."
            })
    
        try:
            result = await api_client.verify_token(macaroon.strip(), preimage.strip())
    
            if not result.get("success"):
                return json.dumps({
                    "success": False,
                    "error": result.get("error", "Unknown error verifying token")
                })
    
            if result.get("valid"):
                return json.dumps({
                    "success": True,
                    "valid": True,
                    "resource": result.get("resource"),
                    "message": "Payment verified. The payer has paid — you can now grant access to the resource."
                })
            else:
                return json.dumps({
                    "success": True,
                    "valid": False,
                    "message": "Payment verification failed. The token is invalid or the invoice has not been paid. Do NOT grant access."
                })
    
        except Exception as e:
            logger.exception("Error verifying L402 payment")
            return json.dumps({
                "success": False,
                "error": sanitize_error(str(e))
            })
  • Registration of the `verify_l402_payment` tool within the MCP server.
    Tool(
        name="verify_l402_payment",
        description=(
            "Verify an L402 token (macaroon + preimage) to confirm payment was made. "
            "Use this after receiving an L402 token from a payer to validate they paid "
            "before granting access to the resource. "
            "Requires LIGHTNING_ENABLE_API_KEY with an Agentic Commerce subscription."
        ),
        inputSchema={
            "type": "object",
            "properties": {
                "macaroon": {
                    "type": "string",
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes the tool's function (verification), context (post-payment validation), and prerequisites (API key requirement), though it lacks details on rate limits, error handling, or response format.

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 front-loaded with the core purpose, followed by usage context and prerequisites in two efficient sentences. Every sentence adds value without redundancy, making it appropriately concise and well-structured.

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

Completeness4/5

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

Given the tool's moderate complexity (verification with prerequisites), no annotations, and no output schema, the description is largely complete—covering purpose, usage, and requirements. However, it lacks details on return values or error cases, which would enhance completeness.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents both parameters ('macaroon' and 'preimage') with their formats. The description adds no additional parameter semantics beyond what the schema provides, meeting the baseline for high coverage.

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

Purpose5/5

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

The description clearly states the tool's purpose with specific verbs ('verify', 'confirm') and resources ('L402 token', 'payment'), distinguishing it from siblings like 'check_invoice_status' or 'confirm_payment' by focusing on token validation rather than payment tracking or confirmation.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It explicitly states when to use this tool ('after receiving an L402 token from a payer to validate they paid before granting access to the resource') and provides context on prerequisites ('Requires LIGHTNING_ENABLE_API_KEY with an Agentic Commerce subscription'), clearly differentiating it from alternatives like 'access_l402_resource'.

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/refined-element/lightning-enable-mcp'

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