Registering an Ability

Site Abilities – Registering an Ability

This is an example of how to register an ability with the site-abilities plugin. In this case we want to be able to send emails so we are going to register site/send-email. These are the instructions.

Complete the add ability form with the following information:

Section 1: Basic Information

Step 1 – Ability Name:
site/send-email

Step 2 – Label:
Send Email

Step 3 – Description:
Send an email to specified recipients with a custom subject and message body

Step 4 – Category:

  • Click the dropdown “– Select Category –“
  • Select: site

Section 2: Input Parameters

Click “+ Add Input Parameter” three times to add these parameters:

Parameter 1:

  • Name: recipient_email
  • Type: string
  • Description: Email address to send to notifications to
  • Default Value: (leave blank)
  • Required

Parameter 2:

  • Name: subject
  • Type: string
  • Description: Email subject line
  • Default Value: (leave blank)
  • Required

Parameter 3:

  • Name: message
  • Type: string
  • Description: Email message body (plain text or HTML)
  • Default Value: (leave blank)
  • Required

Section 3: Output Schema

Output Type: Keep as Object (already selected)

Click “+ Add Output Property” twice to add:

Property 1:

  • Name: success
  • Type: boolean
  • Description: Whether the email was sent successfully

Property 2:

  • Name: message
  • Type: string
  • Description: Status message or error details

Section 4: Execute Callback

WordPress Email Function Code
send-email-function.php
// Validate inputs
if ( empty( $input['recipient_email'] ) || empty( $input['subject'] ) || empty( $input['message'] ) ) {
    return array(
        'success' => false,
        'message' => 'Missing required parameters: recipient_email, subject, message'
    );
}

// Validate email format
if ( ! is_email( $input['recipient_email'] ) ) {
    return array(
        'success' => false,
        'message' => 'Invalid email address format'
    );
}

// Send the email
$to = sanitize_email( $input['recipient_email'] );
$subject = sanitize_text_field( $input['subject'] );
$message = wp_kses_post( $input['message'] );
$headers = array( 'Content-Type: text/html; charset=UTF-8' );

$result = wp_mail( $to, $subject, $message, $headers );

// Return result
return array(
    'success' => $result,
    'message' => $result ? 'Email sent successfully to ' . $to : 'Failed to send email'
);

Section 5: Permissions

Who can execute?

  • administrators only

Section 6: Metadata (Behavior Annotations)

Check the appropriate boxes:

☐ Read-only (doesn’t modify data) – LEAVE UNCHECKED

☐ Destructive (may delete/destroy data) – LEAVE UNCHECKED

☐ Idempotent (same result every time) – LEAVE UNCHECKED


Section 7: MCP Adapter

  • Check “Expose via MCP”
  • MCP Type: Keep as Tool


Final Step: Save

Click “Create Ability”

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *