Skip to content

Instantly share code, notes, and snippets.

View annacmc's full-sized avatar

Anna McPhee annacmc

View GitHub Profile
@annacmc
annacmc / mcp-adapter-initialization.php
Created November 27, 2025 03:15
MCP Adapter Initialization
<?php
//One line to expose all abilities via MCP
private function init_mcp_adapter(): void {
if ( class_exists( \WP\MCP\Core\McpAdapter::class ) ) {
\WP\MCP\Core\McpAdapter::instance();
}
}
@annacmc
annacmc / Custom-Ability-Category.php
Last active November 27, 2025 03:10
Custom Ability Category
<?php
// Extending the Abilities API with a content category
public function register_ability_category(): void {
wp_register_ability_category(
'content',
array(
'label' => __( 'Content', 'ai-content-strategist' ),
'description' => __( 'Abilities for content analysis, auditing, and strategy.', 'ai-content-strategist' ),
@annacmc
annacmc / graceful-degradation.php
Last active November 27, 2025 03:12
Graceful Degradation
<?php
// Plugin works partially even without Jetpack
public static function is_jetpack_connected(): bool {
if ( ! class_exists( 'Automattic\Jetpack\Connection\Manager' ) ) {
return false;
}
$connection_manager = new \Automattic\Jetpack\Connection\Manager();
@annacmc
annacmc / draft-timestamps-handling.php
Last active November 27, 2025 03:12
Edge Case - Draft Timestamps
<?php
// Draft posts have zeroed GMT dates until published
private function get_post_timestamp( \WP_Post $post, string $type = 'date' ): int {
$gmt_field = 'modified' === $type ? 'post_modified_gmt' : 'post_date_gmt';
$local_field = 'modified' === $type ? 'post_modified' : 'post_date';
// Check if GMT date is valid (not zeroed).
$gmt_date = $post->$gmt_field;
@annacmc
annacmc / enrich-wp-data.php
Last active November 27, 2025 03:13
Enriching Stats with WordPress Data
<?php
// Combining Jetpack views with WordPress post metadata
private function process_top_posts( array $top_posts_data, int $limit ): array {
$result = array();
// The data structure varies based on the Jetpack Stats response.
$posts = $top_posts_data['summary']['postviews'] ?? $top_posts_data['posts'] ?? array();
@annacmc
annacmc / execute-callback.php
Last active November 27, 2025 03:13
Execute Callback
<?php
// Fetching data from Jetpack Stats and enriching with WordPress
public function execute_get_top_posts( array $input ): array|\WP_Error {
// Verify Jetpack is connected.
if ( ! Plugin::is_jetpack_connected() || ! Plugin::is_stats_available() ) {
return Plugin::get_jetpack_not_connected_error();
}
@annacmc
annacmc / self-documenting-api.php
Last active November 27, 2025 03:13
JSON Schema - Self-Documenting API
<?php
// AI reads this to understand how to call your ability
'input_schema' => array(
'type' => 'object',
'additionalProperties' => false,
'properties' => array(
'days' => array(
'type' => 'integer',
@annacmc
annacmc / register-abililty.php
Last active November 27, 2025 03:14
Ability Registration Pattern
<?php
// example of registering an ability
wp_register_ability(
'content-strategist/get-top-posts',
array(
'label' => __( 'Get Top Posts', 'ai-content-strategist' ),
'description' => __( 'Returns the site\'s top performing posts by views. Useful for understanding what content resonates with your audience.', 'ai-content-strategist' ),
'category' => 'content',
@annacmc
annacmc / mcp-metadata-annotations.php
Last active November 27, 2025 03:14
MCP Metadata Annotations (The "Magic")
<?php
// Why AI can discover and understand your abilities
'meta' => array(
'annotations' => array(
'readonly' => true,
'destructive' => false,
'idempotent' => true,
),