‘Create Term’,
‘description’ => ‘Creates a new taxonomy term (e.g., a category or tag).’,
‘category’ => ‘master’,
‘input_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘name’ => [ ‘type’ => ‘string’, ‘description’ => ‘The name of the term.’ ],
‘taxonomy’ => [ ‘type’ => ‘string’, ‘description’ => ‘The taxonomy to which the term is added (e.g., “category”, “post_tag”).’ ],
‘slug’ => [ ‘type’ => ‘string’, ‘description’ => ‘The slug for the term.’ ],
‘description’ => [ ‘type’ => ‘string’, ‘description’ => ‘A description for the term.’ ],
‘parent’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the parent term, if any.’ ],
],
‘required’ => [ ‘name’, ‘taxonomy’ ],
],
‘output_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘term_id’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the created term.’ ],
],
],
‘execute_callback’ => [ $this, ‘create_term’ ],
‘permission_callback’ => function() { return current_user_can( ‘manage_categories’ ); },
‘meta’ => [ ‘mcp’ => [ ‘public’ => true, ‘type’ => ‘tool’ ] ],
] );
wp_register_ability( ‘master/update-term’, [
‘label’ => ‘Update Term’,
‘description’ => ‘Updates an existing taxonomy term.’,
‘category’ => ‘master’,
‘input_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘term_id’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the term to update.’ ],
‘taxonomy’ => [ ‘type’ => ‘string’, ‘description’ => ‘The taxonomy of the term.’ ],
‘name’ => [ ‘type’ => ‘string’, ‘description’ => ‘The new name for the term.’ ],
‘slug’ => [ ‘type’ => ‘string’, ‘description’ => ‘The new slug for the term.’ ],
‘description’ => [ ‘type’ => ‘string’, ‘description’ => ‘The new description for the term.’ ],
‘parent’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The new parent term ID.’ ],
],
‘required’ => [ ‘term_id’, ‘taxonomy’ ],
],
‘output_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘success’ => [ ‘type’ => ‘boolean’, ‘description’ => ‘Whether the update was successful.’ ],
],
],
‘execute_callback’ => [ $this, ‘update_term’ ],
‘permission_callback’ => function() { return current_user_can( ‘manage_categories’ ); },
‘meta’ => [ ‘mcp’ => [ ‘public’ => true, ‘type’ => ‘tool’ ] ],
] );
wp_register_ability( ‘master/delete-term’, [
‘label’ => ‘Delete Term’,
‘description’ => ‘Deletes a taxonomy term.’,
‘category’ => ‘master’,
‘input_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘term_id’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the term to delete.’ ],
‘taxonomy’ => [ ‘type’ => ‘string’, ‘description’ => ‘The taxonomy of the term.’ ],
],
‘required’ => [ ‘term_id’, ‘taxonomy’ ],
],
‘output_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘success’ => [ ‘type’ => ‘boolean’, ‘description’ => ‘Whether the deletion was successful.’ ],
],
],
‘execute_callback’ => [ $this, ‘delete_term’ ],
‘permission_callback’ => function() { return current_user_can( ‘manage_categories’ ); },
‘meta’ => [ ‘mcp’ => [ ‘public’ => true, ‘type’ => ‘tool’ ] ],
] );
wp_register_ability( ‘master/list-terms’, [
‘label’ => ‘List Terms’,
‘description’ => ‘Retrieves a list of taxonomy terms.’,
‘category’ => ‘master’,
‘input_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘taxonomy’ => [ ‘type’ => ‘string’, ‘description’ => ‘The taxonomy to retrieve terms from.’ ],
‘number’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The maximum number of terms to return.’, ‘default’ => 10 ],
‘hide_empty’ => [ ‘type’ => ‘boolean’, ‘description’ => ‘Whether to hide terms with no posts.’, ‘default’ => false ],
],
‘required’ => [ ‘taxonomy’ ],
],
‘output_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘terms’ => [ ‘type’ => ‘array’, ‘description’ => ‘Array of term objects.’, ‘items’ => [ ‘type’ => ‘object’ ] ],
],
],
‘execute_callback’ => [ $this, ‘list_terms’ ],
‘permission_callback’ => function() { return current_user_can( ‘manage_categories’ ); },
‘meta’ => [ ‘mcp’ => [ ‘public’ => true, ‘type’ => ‘tool’ ], ‘annotations’ => [ ‘readOnlyHint’ => true ] ],
] );
wp_register_ability( ‘master/assign-term’, [
‘label’ => ‘Assign Term’,
‘description’ => ‘Assigns a taxonomy term to a post.’,
‘category’ => ‘master’,
‘input_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘post_id’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the post.’ ],
‘term_id’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the term to assign.’ ],
‘taxonomy’ => [ ‘type’ => ‘string’, ‘description’ => ‘The taxonomy of the term.’ ],
‘append’ => [ ‘type’ => ‘boolean’, ‘description’ => ‘Whether to append the term or overwrite existing terms.’, ‘default’ => true ],
],
‘required’ => [ ‘post_id’, ‘term_id’, ‘taxonomy’ ],
],
‘output_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘success’ => [ ‘type’ => ‘boolean’, ‘description’ => ‘Whether the assignment was successful.’ ],
],
],
‘execute_callback’ => [ $this, ‘assign_term’ ],
‘permission_callback’ => function( $request ) { return current_user_can( ‘edit_post’, $request[‘post_id’] ); },
‘meta’ => [ ‘mcp’ => [ ‘public’ => true, ‘type’ => ‘tool’ ] ],
] );
wp_register_ability( ‘master/remove-term’, [
‘label’ => ‘Remove Term’,
‘description’ => ‘Removes a taxonomy term from a post.’,
‘category’ => ‘master’,
‘input_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘post_id’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the post.’ ],
‘term_id’ => [ ‘type’ => ‘integer’, ‘description’ => ‘The ID of the term to remove.’ ],
‘taxonomy’ => [ ‘type’ => ‘string’, ‘description’ => ‘The taxonomy of the term.’ ],
],
‘required’ => [ ‘post_id’, ‘term_id’, ‘taxonomy’ ],
],
‘output_schema’ => [
‘type’ => ‘object’,
‘properties’ => [
‘success’ => [ ‘type’ => ‘boolean’, ‘description’ => ‘Whether the removal was successful.’ ],
],
],
‘execute_callback’ => [ $this, ‘remove_term’ ],
‘permission_callback’ => function( $request ) { return current_user_can( ‘edit_post’, $request[‘post_id’] ); },
‘meta’ => [ ‘mcp’ => [ ‘public’ => true, ‘type’ => ‘tool’ ] ],
] );
}
public function create_term( $request ) {
$args = [
‘slug’ => $request[‘slug’] ?? null,
‘description’ => $request[‘description’] ?? null,
‘parent’ => $request[‘parent’] ?? 0,
];
$term = wp_insert_term( $request[‘name’], $request[‘taxonomy’], $args );
if ( is_wp_error( $term ) ) {
return $term;
}
return [ ‘term_id’ => $term[‘term_id’] ];
}
public function update_term( $request ) {
$args = [];
if ( isset( $request[‘name’] ) ) $args[‘name’] = $request[‘name’];
if ( isset( $request[‘slug’] ) ) $args[‘slug’] = $request[‘slug’];
if ( isset( $request[‘description’] ) ) $args[‘description’] = $request[‘description’];
if ( isset( $request[‘parent’] ) ) $args[‘parent’] = $request[‘parent’];
$result = wp_update_term( $request[‘term_id’], $request[‘taxonomy’], $args );
if ( is_wp_error( $result ) ) {
return $result;
}
return [ ‘success’ => true ];
}
public function delete_term( $request ) {
$result = wp_delete_term( $request[‘term_id’], $request[‘taxonomy’] );
if ( is_wp_error( $result ) || ! $result ) {
return new WP_Error( ‘delete_failed’, ‘Failed to delete term.’ );
}
return [ ‘success’ => true ];
}
public function list_terms( $request ) {
$args = [
‘taxonomy’ => $request[‘taxonomy’],
‘number’ => $request[‘number’] ?? 10,
‘hide_empty’ => $request[‘hide_empty’] ?? false,
];
$terms = get_terms( $args );
if ( is_wp_error( $terms ) ) {
return $terms;
}
return [ ‘terms’ => $terms ];
}
public function assign_term( $request ) {
$result = wp_set_post_terms( $request[‘post_id’], [ $request[‘term_id’] ], $request[‘taxonomy’], $request[‘append’] ?? true );
if ( is_wp_error( $result ) ) {
return $result;
}
return [ ‘success’ => true ];
}
public function remove_term( $request ) {
$result = wp_remove_object_terms( $request[‘post_id’], $request[‘term_id’], $request[‘taxonomy’] );
if ( is_wp_error( $result ) || ! $result ) {
return new WP_Error( ‘remove_failed’, ‘Failed to remove term.’ );
}
return [ ‘success’ => true ];
}
}