Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/code-quality.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ jobs:
custom-cache-suffix: $(date -u "+%Y-%m")

- name: Run Linter
run: vendor/bin/parallel-lint -j 10 . --show-deprecated --exclude vendor --exclude .git --checkstyle | cs2pr
run: vendor/bin/parallel-lint -j 10 . --show-deprecated --exclude vendor --exclude .git --exclude third-party --checkstyle | cs2pr

phpcs:
name: PHPCS
Expand Down
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
wp-cli.local.yml
node_modules/
vendor/
src/vendor/
src/composer.json
third-party/
*.zip
*.tar.gz
*.swp
Expand All @@ -11,4 +14,4 @@ composer.lock
phpunit.xml
phpcs.xml
.phpcs.xml
.vscode/
.vscode/
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Tip: for better on support of the latest PHP versions, use the v2.12 nightly bui
To install the latest development version of this package, use the following command instead:

```bash
wp package install swissspidy/ai-command:dev-main
wp package install mcp-wp/ai-command:dev-main
```

Right now, the plugin requires a WordPress site with the [AI Services plugin](https://wordpress.org/plugins/ai-services) installed.
Expand Down Expand Up @@ -165,13 +165,13 @@ For a more thorough introduction, [check out WP-CLI's guide to contributing](htt

Think you’ve found a bug? We’d love for you to help us get it fixed.

Before you create a new issue, you should [search existing issues](https://github.com/swissspidy/ai-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.
Before you create a new issue, you should [search existing issues](https://github.com/mcp-wp/ai-command/issues?q=label%3Abug%20) to see if there’s an existing resolution to it, or if it’s already been fixed in a newer version.

Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/swissspidy/ai-command/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).
Once you’ve done a bit of searching and discovered there isn’t an open or fixed issue for your bug, please [create a new issue](https://github.com/mcp-wp/ai-command/issues/new). Include as much detail as you can, and clear steps to reproduce if possible. For more guidance, [review our bug report documentation](https://make.wordpress.org/cli/handbook/bug-reports/).

### Creating a pull request

Want to contribute a new feature? Please first [open a new issue](https://github.com/swissspidy/ai-command/issues/new) to discuss whether the feature is a good fit for the project.
Want to contribute a new feature? Please first [open a new issue](https://github.com/mcp-wp/ai-command/issues/new) to discuss whether the feature is a good fit for the project.

Once you've decided to commit the time to seeing your pull request through, [please follow our guidelines for creating a pull request](https://make.wordpress.org/cli/handbook/pull-requests/) to make sure it's a pleasant experience. See "[Setting up](https://make.wordpress.org/cli/handbook/pull-requests/#setting-up)" for details specific to working on this package locally.

Expand Down
10 changes: 6 additions & 4 deletions ai-command.php
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
<?php

namespace WP_CLI\AiCommand;
namespace McpWp\AiCommand;

use WP_CLI;

if ( ! class_exists( '\WP_CLI' ) ) {
return;
}

$ai_command_autoloader = __DIR__ . '/vendor/autoload.php';
if ( file_exists( __DIR__ . '/third-party/vendor/autoload.php' ) ) {
require_once __DIR__ . '/third-party/vendor/autoload.php';
}

if ( file_exists( $ai_command_autoloader ) ) {
require_once $ai_command_autoloader;
if ( file_exists( __DIR__ . '/src/vendor/autoload.php' ) ) {
require_once __DIR__ . '/src/vendor/autoload.php';
}

WP_CLI::add_command( 'ai', AiCommand::class );
Expand Down
54 changes: 45 additions & 9 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
{
"name": "swissspidy/ai-command",
"name": "mcp-wp/ai-command",
"type": "wp-cli-package",
"description": "",
"homepage": "https://github.com/swissspidy/ai-command",
"homepage": "https://github.com/mcp-wp/ai-command",
"license": "MIT",
"authors": [],
"require": {
"php": "^8.2",
"felixarntz/ai-services": "dev-main",
"logiscape/mcp-sdk-php": "^1.0",
"mcaskill/composer-exclude-files": "^4.0",
"mcp-wp/mcp-server": "dev-main",
"wp-cli/wp-cli": "^2.11"
},
"require-dev": {
"roave/security-advisories": "dev-latest",
"wp-cli/wp-cli-tests": "^v4.3.9"
"humbug/php-scoper": "^0.18.17",
"roave/security-advisories": "dev-latest",
"wp-cli/wp-cli-tests": "^v4.3.9"
},
"repositories": [
{
"type": "vcs",
"url": "https://github.com/mcp-wp/mcp-server",
"no-api": true
},
{
"type": "vcs",
"url": "https://github.com/felixarntz/ai-services",
"no-api": true
}
],
"config": {
"process-timeout": 7200,
"sort-packages": true,
"allow-plugins": {
"composer/installers": true,
"dealerdirect/phpcodesniffer-composer-installer": true,
"mcaskill/composer-exclude-files": true,
"php-http/discovery": true
}
},
Expand All @@ -32,12 +50,15 @@
"mcp server list",
"mcp server add",
"mcp server remove"
]
],
"exclude-from-files": [
],
"installer-disable": true
},
"autoload": {
"psr-4": {
"WP_CLI\\AiCommand\\": "src/",
"WP_CLI\\AiCommand\\MCP\\": "src/MCP"
"McpWp\\AiCommand\\": "src/",
"McpWp\\AiCommand\\MCP\\": "src/MCP"
},
"files": [
"ai-command.php"
Expand All @@ -46,6 +67,12 @@
"minimum-stability": "dev",
"prefer-stable": true,
"scripts": {
"post-install-cmd": [
"@prefix-dependencies"
],
"post-update-cmd": [
"@prefix-dependencies"
],
"behat": "run-behat-tests",
"behat-rerun": "rerun-behat-tests",
"lint": "run-linter-tests",
Expand All @@ -58,9 +85,18 @@
"@phpcs",
"@phpunit",
"@behat"
]
],
"prefix-dependencies": [
"php-scoper add-prefix --output-dir=./third-party --force --quiet",
"echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > ./third-party/composer.json",
"@composer dump-autoload --working-dir ./third-party --no-dev --classmap-authoritative",
"sed -i'.bak' -e 's/Composer\\\\/AiCommand_Composer\\\\/' third-party/vendor/composer/*.php && rm -rf third-party/vendor/composer/*.php.bak",
"echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > ./src/composer.json",
"@composer dump-autoload --working-dir ./src --no-dev --classmap-authoritative",
"sed -i'.bak' -e 's/Composer\\\\/AiCommand_Composer\\\\/' src/vendor/composer/*.php && rm -rf src/vendor/composer/*.php.bak"
]
},
"support": {
"issues": "https://github.com/swissspidy/ai-command/issues"
"issues": "https://github.com/mcp-wp/ai-command/issues"
}
}
4 changes: 2 additions & 2 deletions docs/reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ $server->register_resource(
List resources

```PHP
$server = new WP_CLI\AiCommand\MCP\Server();
$server = new McpWp\AiCommand\MCP\Server();
$resources = $server->list_resources();

echo json_encode( $resources, JSON_PRETTY_PRINT );
Expand All @@ -147,7 +147,7 @@ echo json_encode( $resources, JSON_PRETTY_PRINT );
Read resource

```PHP
$server = new WP_CLI\AiCommand\MCP\Server();
$server = new McpWp\AiCommand\MCP\Server();
$resource_data = $server->read_resource( 'file://./products.json' );

echo json_encode( $resource_data, JSON_PRETTY_PRINT );
Expand Down
9 changes: 8 additions & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,12 @@
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
<properties>
<property name="prefixes" type="array">
<element value="WP_CLI\AiCommand"/><!-- Namespaces. -->
<element value="McpWp\AiCommand"/><!-- Namespaces. -->
<element value="ai_command"/><!-- Global variables and such. -->
</property>
</properties>

<exclude-pattern>scoper.inc.php</exclude-pattern>
</rule>

<rule ref="WordPress.NamingConventions.ValidVariableName">
Expand All @@ -58,4 +60,9 @@
</property>
</properties>
</rule>

<!-- Third-party or auto-generated code -->
<exclude-pattern>*/third-party/*</exclude-pattern>
<exclude-pattern>*/vendor/*</exclude-pattern>
<exclude-pattern>*/includes/vendor/*</exclude-pattern>
</ruleset>
17 changes: 17 additions & 0 deletions scoper.inc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

use Symfony\Component\Finder\Finder;

return [
'prefix' => 'McpWp\AiCommand_Dependencies',
'finders' => [
Finder::create()
->files()
->in( 'vendor/logiscape/mcp-sdk-php/src' ),
Finder::create()
->files()
->in( 'vendor/mcp-wp/mcp-server/src/MCP' ),
],
'exclude-namespaces' => [ 'Psr' ],
'exclude-classes' => [ 'WP_Community_Events' ],
];
2 changes: 1 addition & 1 deletion src/AI/AiClient.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace WP_CLI\AiCommand\AI;
namespace McpWp\AiCommand\AI;

use Exception;
use Felix_Arntz\AI_Services\Services\API\Enums\AI_Capability;
Expand Down
19 changes: 8 additions & 11 deletions src/AiCommand.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?php

namespace WP_CLI\AiCommand;
namespace McpWp\AiCommand;

use Mcp\Client\ClientSession;
use Mcp\Client\Transport\StdioServerParameters;
use WP_CLI\AiCommand\AI\AiClient;
use WP_CLI\AiCommand\MCP\Client;
use WP_CLI\AiCommand\Utils\CliLogger;
use WP_CLI\AiCommand\Utils\McpConfig;
use McpWp\AiCommand\AI\AiClient;
use McpWp\AiCommand\MCP\Client;
use McpWp\AiCommand\Utils\CliLogger;
use McpWp\AiCommand\Utils\McpConfig;
use McpWp\AiCommand_Dependencies\McpWp\MCP\Servers\WordPress\WordPress;
use WP_CLI\Utils;
use WP_CLI_Command;

Expand Down Expand Up @@ -50,9 +50,6 @@ public function __invoke( $args, $assoc_args ) {
$with_wordpress = null === Utils\get_flag_value( $assoc_args, 'skip-wordpress' );
if ( $with_wordpress ) {
\WP_CLI::get_runner()->load_wordpress();
} else {
// TODO: Implement.
\WP_CLI::error( 'Not implemented yet' );
}

$sessions = $this->get_sessions( $with_wordpress );
Expand Down Expand Up @@ -131,13 +128,13 @@ public function get_sessions( bool $with_wordpress ): array {
$sessions = [];

// The WP-CLI MCP server is always available.
$sessions[] = ( new MCP\Client( new CliLogger() ) )->connect(
$sessions[] = ( new Client( new CliLogger() ) )->connect(
MCP\Servers\WP_CLI\WP_CLI::class
);

if ( $with_wordpress ) {
$sessions[] = ( new Client( new CliLogger() ) )->connect(
MCP\Servers\WordPress\WordPress::class
WordPress::class
);
}

Expand Down
23 changes: 11 additions & 12 deletions src/MCP/Client.php
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
<?php

namespace WP_CLI\AiCommand\MCP;
namespace McpWp\AiCommand\MCP;

use Mcp\Client\Client as McpCLient;
use Mcp\Client\ClientSession;
use Mcp\Client\Transport\StdioServerParameters;
use McpWp\AiCommand_Dependencies\Mcp\Client\Client as McpCLient;
use McpWp\AiCommand_Dependencies\Mcp\Client\ClientSession;
use McpWp\AiCommand_Dependencies\McpWp\MCP\Server;
use Psr\Log\LoggerInterface;
use Psr\Log\NullLogger;


class Client extends McpCLient {
private ?ClientSession $session = null;

private LoggerInterface $logger;

Expand Down Expand Up @@ -38,6 +36,7 @@ public function connect(
?array $env = null,
?float $read_timeout = null
): ClientSession {
$session = null;
if ( class_exists( $command_or_url ) ) {
/**
* @var Server $server
Expand All @@ -51,15 +50,15 @@ public function connect(

[$read_stream, $write_stream] = $transport->connect();

$this->session = new InMemorySession(
$session = new InMemorySession(
$read_stream,
$write_stream,
$this->logger
);

$this->session->initialize();
$session->initialize();

return $this->session;
return $session;
}

// phpcs:ignore WordPress.WP.AlternativeFunctions.parse_url_parse_url
Expand All @@ -82,17 +81,17 @@ public function connect(
[$read_stream, $write_stream] = $transport->connect();

// Initialize the client session with the obtained streams
$this->session = new InMemorySession(
$session = new InMemorySession(
$read_stream,
$write_stream,
$this->logger
);

// Initialize the session (e.g., perform handshake if necessary)
$this->session->initialize();
$session->initialize();
$this->logger->info( 'Session initialized successfully' );

return $this->session;
return $session;
}

return parent::connect( $command_or_url, $args, $env, $read_timeout );
Expand Down
Loading