Skip to main content
Glama

verify_webhook

Validate webhook requests from Replicate using HMAC-SHA256 to ensure authenticity and prevent unauthorized access to your system.

Instructions

Verify that a webhook request came from Replicate using HMAC-SHA256.

Args: payload: The webhook payload to verify signature: The signature from the X-Replicate-Signature header secret: The webhook signing secret from get_webhook_secret Returns: True if signature is valid, False otherwise

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
payloadYes
signatureYes
secretYes

Implementation Reference

  • Core handler function for the 'verify_webhook' tool. Computes the expected HMAC-SHA256 signature from the serialized payload and secret, then compares it securely to the provided signature.
    @mcp.tool() def verify_webhook(payload: WebhookPayload, signature: str, secret: str) -> bool: """Verify that a webhook request came from Replicate using HMAC-SHA256. Args: payload: The webhook payload to verify signature: The signature from the X-Replicate-Signature header secret: The webhook signing secret from get_webhook_secret Returns: True if signature is valid, False otherwise """ if not signature or not secret: return False # Convert payload to canonical JSON string payload_str = json.dumps(payload.model_dump(), sort_keys=True) # Calculate expected signature expected = hmac.new(secret.encode(), payload_str.encode(), hashlib.sha256).hexdigest() # Compare signatures using constant-time comparison return hmac.compare_digest(signature, expected)
  • Pydantic model defining the structure of the 'payload' input parameter for verify_webhook tool.
    class WebhookPayload(BaseModel): """The full payload of a webhook request.""" event: WebhookEvent prediction: Dict[str, Any] = Field(..., description="Full prediction object at time of event")
  • The @mcp.tool() decorator registers the verify_webhook function with the FastMCP server using the default name based on the function name.
    @mcp.tool()

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/gerred/mcp-server-replicate'

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