Skip to content

Run WP-CLI Commands with AI ​

Easy MCP AI can let your AI client run WP-CLI commands on your WordPress site, written the same way you would type them after wp in a terminal. This guide explains what the WP-CLI tool does, how to switch it on, which commands it refuses, and how approvals and the logs apply to it.

In this article

What the WP-CLI Tool Does ​

The tool is called wp_cli_run. Your AI client sends it one command, such as option get blogname or plugin list --format=csv, and gets back exactly what WP-CLI would print.

  • No terminal or server access is needed. The command runs inside WordPress, as the WordPress user behind the connection. WP-CLI does not have to be installed on your server, and nothing runs in a shell.
  • It follows the official WP-CLI syntax, so the AI client can use the commands it already knows. The AI client can ask the tool itself for help, help <command>, or cli has-command "<command>" to see what is available.
  • It fills the gaps the other tools leave: the object cache, transients, scheduled (cron) events, rewrite rules, roles and capabilities, database maintenance, and language packs.
  • Only administrators can use it. The connected WordPress user needs the manage_options capability.

When a command does something another Easy MCP AI tool already does, the command runs through that tool, as described in Commands That Run Through Other Tools.

Switch the WP-CLI Tool On ​

The WP-CLI tool is switched off on every site until an administrator turns it on.

  1. In WordPress, go to Easy MCP AI > Settings.
  2. Scroll to the Advanced card and find Disabled tools. A checked box means the tool is switched off.
  3. Clear the checkbox next to wp_cli_run.
  4. Click Save changes.
  5. Refresh the tool list in your AI client so it loads the new tool. See Enabled Tools Not Showing in Your AI Client for the steps in each client.

To switch it off again, check its box and save. On sites you manage from code, you can switch it on with wp_cli_run=on in the EASY_MCP_AI_TOOLS constant instead, which also locks the checkbox. See Switch Tools On or Off from wp-config.php.

Switching the tool on for your site does not give it to every connection. Each connection also needs access to it:

  • API tokens: a token with Full access includes it as soon as it is switched on. A Custom token needs wp_cli_run selected. A Read-only token never includes it. See Creating and Managing API Tokens.
  • OAuth connections (such as ChatGPT, Claude, and Claude Code): a connection approved with Full access includes it. With Custom, the WP-CLI commands permission must be ticked on the approval screen; it starts unticked. To add it to an existing connection, connect the client again and approve it with that permission. See Managing OAuth Access.

Commands That Run Through Other Tools ​

Many WP-CLI commands do the same job as an existing Easy MCP AI tool. For example, plugin list uses the plugin list tool, user list uses the user list tool, and post delete uses the delete tools. When a command matches a tool like this, the command runs through that tool, so:

  • That tool must be switched on for your site. If it is off, the command is refused with a message saying the tool is switched off and where an administrator can switch it on.
  • The connection must be allowed to use that tool.
  • Every check that tool makes still applies, and its changes are recorded under that tool's name.

Installing, deleting, and updating plugins, themes, and WordPress itself use six tools that are also switched off by default, each under Disabled tools:

ToolWhat it doesCapability the user needs
wp_install_pluginInstalls a plugin from wordpress.org by its slug, without activating itinstall_plugins
wp_delete_pluginDeletes an inactive plugin's files without running its uninstall routinedelete_plugins
wp_uninstall_pluginRuns a plugin's uninstall routine, which removes its data, then deletes its filesdelete_plugins
wp_install_themeInstalls a theme from wordpress.org by its slug, plus its parent theme if needed, without activating itinstall_themes
wp_delete_themeDeletes an installed theme that is not activedelete_themes
wp_update_coreUpdates WordPress to the latest version, or to a version you nameupdate_core

For example, plugin install hello-dolly needs wp_install_plugin switched on. Your AI client can also call these tools directly, without the WP-CLI tool. With Custom OAuth access, each group has its own permission on the approval screen: Plugin installs and deletions, Theme installs and deletions, and WordPress core update. If DISALLOW_FILE_MODS is set in wp-config.php, every install, delete, and update is refused.

What the WP-CLI Tool Refuses ​

Some commands could expose secrets, run arbitrary code, or cut off the connection itself, so the tool refuses them and says why:

RefusedWhy
eval, eval-file, shellThey run arbitrary PHP code
config commandsThey edit or print wp-config.php, which holds your database password and security keys
db query, db export, db import, db reset, and other commands that run raw SQL or dump, restore, or drop tablesDatabase maintenance such as db size, db check, db optimize, and db repair is allowed
Shell syntax, such as pipes (`), redirects, $variables`, and wildcards
Commands added by other pluginsOnly WP-CLI's own commands are available
Developer and setup commands, such as scaffold, package, server, core download, and core installThey have no place on a running site
Arguments that read a file on your server, such as installing a plugin from a ZIP pathPlugins and themes are installed from wordpress.org by slug

A few settings are never written by the WP-CLI tool, because changing them could break the connection or the site. For example, option update siteurl is refused. The refusal names the command that does the job safely, such as search-replace for a domain change or plugin activate instead of writing active_plugins. The tool also never reads or changes Easy MCP AI's own settings.

A command that asks for confirmation in a terminal ([y/n]) is refused unless it includes --yes. A command that names many items at once is limited, for example to 5 plugins per plugin delete; the message tells the AI client to run it in smaller groups.

Approvals, the Audit Log, and Change History ​

Approvals. When Ask before destructive actions is on in Easy MCP AI > Settings, a command that changes something pauses until you approve it. The AI client shows you a preview of the change, for example an option's old and new value, and a link to approve it. After you approve, ask the AI client to run the same command again. Commands that only read, such as option get or plugin list, never pause.

  • A change the WP-CLI tool makes itself, such as option update or transient delete, always pauses.
  • A command that runs through another tool pauses when that tool would. The plugin, theme, and core tools always pause.

When the switch is off, which is the default, commands run without asking.

Audit log. Every command appears in Easy MCP AI > Activity as a wp_cli_run call, with passwords and keys in the command masked. One command counts as one call toward your rate limit, however many tools it uses. See Using the Easy MCP AI Audit Log.

Change history. What is recorded depends on how the command ran:

  • A command that ran through another tool is recorded under that tool, and can be reviewed like that tool's other changes.
  • A change the WP-CLI tool makes itself, such as option update, is recorded under wp_cli_run. Most of these changes cannot be restored from Change History.
  • Transients, and any change to files (installing or deleting plugins and themes, or updating WordPress), are never recorded.

Each result tells the AI client which of its changes were not recorded. To restore a recorded change, see Restore AI Changes from Change History.

On a Multisite Network ​

On a multisite network, a command runs on the site the AI client is connected to. A --url or --blog argument must name that same site. Network-wide commands, such as site and super-admin commands or network plugin activation, need a super admin with the matching network capability. The six plugin, theme, and core tools also need a super admin on a network.

Try These Prompts ​

Once the tool is switched on, ask your AI client:

  • Flush the object cache and the rewrite rules.
  • Delete expired transients and tell me how many were removed.
  • List the scheduled cron events and flag any that are overdue.
  • Show the size of the database.
Was this helpful?