Skip to content

Commit 37572bd

Browse files
authored
Import code from mcp-server / de-duplication (#51)
* Import mcp-server repo with php-scoper * exclude folder
1 parent feed34e commit 37572bd

29 files changed

+140
-1201
lines changed

.github/workflows/code-quality.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ jobs:
5353
custom-cache-suffix: $(date -u "+%Y-%m")
5454

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

5858
phpcs:
5959
name: PHPCS

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
wp-cli.local.yml
33
node_modules/
44
vendor/
5+
src/vendor/
6+
src/composer.json
7+
third-party/
58
*.zip
69
*.tar.gz
710
*.swp
@@ -11,4 +14,4 @@ composer.lock
1114
phpunit.xml
1215
phpcs.xml
1316
.phpcs.xml
14-
.vscode/
17+
.vscode/

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Tip: for better on support of the latest PHP versions, use the v2.12 nightly bui
3333
To install the latest development version of this package, use the following command instead:
3434

3535
```bash
36-
wp package install swissspidy/ai-command:dev-main
36+
wp package install mcp-wp/ai-command:dev-main
3737
```
3838

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

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

168-
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.
168+
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.
169169

170-
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/).
170+
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/).
171171

172172
### Creating a pull request
173173

174-
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.
174+
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.
175175

176176
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.
177177

ai-command.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
11
<?php
22

3-
namespace WP_CLI\AiCommand;
3+
namespace McpWp\AiCommand;
44

55
use WP_CLI;
66

77
if ( ! class_exists( '\WP_CLI' ) ) {
88
return;
99
}
1010

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

13-
if ( file_exists( $ai_command_autoloader ) ) {
14-
require_once $ai_command_autoloader;
15+
if ( file_exists( __DIR__ . '/src/vendor/autoload.php' ) ) {
16+
require_once __DIR__ . '/src/vendor/autoload.php';
1517
}
1618

1719
WP_CLI::add_command( 'ai', AiCommand::class );

composer.json

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,42 @@
11
{
2-
"name": "swissspidy/ai-command",
2+
"name": "mcp-wp/ai-command",
33
"type": "wp-cli-package",
44
"description": "",
5-
"homepage": "https://github.com/swissspidy/ai-command",
5+
"homepage": "https://github.com/mcp-wp/ai-command",
66
"license": "MIT",
77
"authors": [],
88
"require": {
99
"php": "^8.2",
10+
"felixarntz/ai-services": "dev-main",
1011
"logiscape/mcp-sdk-php": "^1.0",
12+
"mcaskill/composer-exclude-files": "^4.0",
13+
"mcp-wp/mcp-server": "dev-main",
1114
"wp-cli/wp-cli": "^2.11"
1215
},
1316
"require-dev": {
14-
"roave/security-advisories": "dev-latest",
15-
"wp-cli/wp-cli-tests": "^v4.3.9"
17+
"humbug/php-scoper": "^0.18.17",
18+
"roave/security-advisories": "dev-latest",
19+
"wp-cli/wp-cli-tests": "^v4.3.9"
1620
},
21+
"repositories": [
22+
{
23+
"type": "vcs",
24+
"url": "https://github.com/mcp-wp/mcp-server",
25+
"no-api": true
26+
},
27+
{
28+
"type": "vcs",
29+
"url": "https://github.com/felixarntz/ai-services",
30+
"no-api": true
31+
}
32+
],
1733
"config": {
1834
"process-timeout": 7200,
1935
"sort-packages": true,
2036
"allow-plugins": {
37+
"composer/installers": true,
2138
"dealerdirect/phpcodesniffer-composer-installer": true,
39+
"mcaskill/composer-exclude-files": true,
2240
"php-http/discovery": true
2341
}
2442
},
@@ -32,12 +50,15 @@
3250
"mcp server list",
3351
"mcp server add",
3452
"mcp server remove"
35-
]
53+
],
54+
"exclude-from-files": [
55+
],
56+
"installer-disable": true
3657
},
3758
"autoload": {
3859
"psr-4": {
39-
"WP_CLI\\AiCommand\\": "src/",
40-
"WP_CLI\\AiCommand\\MCP\\": "src/MCP"
60+
"McpWp\\AiCommand\\": "src/",
61+
"McpWp\\AiCommand\\MCP\\": "src/MCP"
4162
},
4263
"files": [
4364
"ai-command.php"
@@ -46,6 +67,12 @@
4667
"minimum-stability": "dev",
4768
"prefer-stable": true,
4869
"scripts": {
70+
"post-install-cmd": [
71+
"@prefix-dependencies"
72+
],
73+
"post-update-cmd": [
74+
"@prefix-dependencies"
75+
],
4976
"behat": "run-behat-tests",
5077
"behat-rerun": "rerun-behat-tests",
5178
"lint": "run-linter-tests",
@@ -58,9 +85,18 @@
5885
"@phpcs",
5986
"@phpunit",
6087
"@behat"
61-
]
88+
],
89+
"prefix-dependencies": [
90+
"php-scoper add-prefix --output-dir=./third-party --force --quiet",
91+
"echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > ./third-party/composer.json",
92+
"@composer dump-autoload --working-dir ./third-party --no-dev --classmap-authoritative",
93+
"sed -i'.bak' -e 's/Composer\\\\/AiCommand_Composer\\\\/' third-party/vendor/composer/*.php && rm -rf third-party/vendor/composer/*.php.bak",
94+
"echo '{ \"autoload\": { \"classmap\": [\"\"] } }' > ./src/composer.json",
95+
"@composer dump-autoload --working-dir ./src --no-dev --classmap-authoritative",
96+
"sed -i'.bak' -e 's/Composer\\\\/AiCommand_Composer\\\\/' src/vendor/composer/*.php && rm -rf src/vendor/composer/*.php.bak"
97+
]
6298
},
6399
"support": {
64-
"issues": "https://github.com/swissspidy/ai-command/issues"
100+
"issues": "https://github.com/mcp-wp/ai-command/issues"
65101
}
66102
}

docs/reference.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ $server->register_resource(
138138
List resources
139139

140140
```PHP
141-
$server = new WP_CLI\AiCommand\MCP\Server();
141+
$server = new McpWp\AiCommand\MCP\Server();
142142
$resources = $server->list_resources();
143143

144144
echo json_encode( $resources, JSON_PRETTY_PRINT );
@@ -147,7 +147,7 @@ echo json_encode( $resources, JSON_PRETTY_PRINT );
147147
Read resource
148148

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

153153
echo json_encode( $resource_data, JSON_PRETTY_PRINT );

phpcs.xml.dist

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,12 @@
4545
<rule ref="WordPress.NamingConventions.PrefixAllGlobals">
4646
<properties>
4747
<property name="prefixes" type="array">
48-
<element value="WP_CLI\AiCommand"/><!-- Namespaces. -->
48+
<element value="McpWp\AiCommand"/><!-- Namespaces. -->
4949
<element value="ai_command"/><!-- Global variables and such. -->
5050
</property>
5151
</properties>
52+
53+
<exclude-pattern>scoper.inc.php</exclude-pattern>
5254
</rule>
5355

5456
<rule ref="WordPress.NamingConventions.ValidVariableName">
@@ -58,4 +60,9 @@
5860
</property>
5961
</properties>
6062
</rule>
63+
64+
<!-- Third-party or auto-generated code -->
65+
<exclude-pattern>*/third-party/*</exclude-pattern>
66+
<exclude-pattern>*/vendor/*</exclude-pattern>
67+
<exclude-pattern>*/includes/vendor/*</exclude-pattern>
6168
</ruleset>

scoper.inc.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
use Symfony\Component\Finder\Finder;
4+
5+
return [
6+
'prefix' => 'McpWp\AiCommand_Dependencies',
7+
'finders' => [
8+
Finder::create()
9+
->files()
10+
->in( 'vendor/logiscape/mcp-sdk-php/src' ),
11+
Finder::create()
12+
->files()
13+
->in( 'vendor/mcp-wp/mcp-server/src/MCP' ),
14+
],
15+
'exclude-namespaces' => [ 'Psr' ],
16+
'exclude-classes' => [ 'WP_Community_Events' ],
17+
];

src/AI/AiClient.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?php
22

3-
namespace WP_CLI\AiCommand\AI;
3+
namespace McpWp\AiCommand\AI;
44

55
use Exception;
66
use Felix_Arntz\AI_Services\Services\API\Enums\AI_Capability;

src/AiCommand.php

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<?php
22

3-
namespace WP_CLI\AiCommand;
3+
namespace McpWp\AiCommand;
44

55
use Mcp\Client\ClientSession;
6-
use Mcp\Client\Transport\StdioServerParameters;
7-
use WP_CLI\AiCommand\AI\AiClient;
8-
use WP_CLI\AiCommand\MCP\Client;
9-
use WP_CLI\AiCommand\Utils\CliLogger;
10-
use WP_CLI\AiCommand\Utils\McpConfig;
6+
use McpWp\AiCommand\AI\AiClient;
7+
use McpWp\AiCommand\MCP\Client;
8+
use McpWp\AiCommand\Utils\CliLogger;
9+
use McpWp\AiCommand\Utils\McpConfig;
10+
use McpWp\AiCommand_Dependencies\McpWp\MCP\Servers\WordPress\WordPress;
1111
use WP_CLI\Utils;
1212
use WP_CLI_Command;
1313

@@ -50,9 +50,6 @@ public function __invoke( $args, $assoc_args ) {
5050
$with_wordpress = null === Utils\get_flag_value( $assoc_args, 'skip-wordpress' );
5151
if ( $with_wordpress ) {
5252
\WP_CLI::get_runner()->load_wordpress();
53-
} else {
54-
// TODO: Implement.
55-
\WP_CLI::error( 'Not implemented yet' );
5653
}
5754

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

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

138135
if ( $with_wordpress ) {
139136
$sessions[] = ( new Client( new CliLogger() ) )->connect(
140-
MCP\Servers\WordPress\WordPress::class
137+
WordPress::class
141138
);
142139
}
143140

0 commit comments

Comments
 (0)