From 25125af4ad110dd207f66463e5c90e5b736da0b0 Mon Sep 17 00:00:00 2001 From: Artur Kyryliuk Date: Sun, 15 Nov 2026 03:23:36 +0100 Subject: [PATCH 1/5] add(ci): add tools listing reusable from extensions providing the tools --- .github/workflows/extra-integration.yml | 142 ++++++++++++++++++++++++ EXTRA_CI.md | 21 ++++ 2 files changed, 163 insertions(+) create mode 100644 .github/workflows/extra-integration.yml create mode 100644 EXTRA_CI.md diff --git a/.github/workflows/extra-integration.yml b/.github/workflows/extra-integration.yml new file mode 100644 index 0000000..6eff143 --- /dev/null +++ b/.github/workflows/extra-integration.yml @@ -0,0 +1,142 @@ +name: Extra MCP integration + +on: + workflow_call: + inputs: + evo_ref: + type: string + required: false + default: 3.5.x + emcp_ref: + type: string + required: false + default: main + php_version: + type: string + required: false + default: '8.4' + server_handle: + type: string + required: false + default: content + +permissions: + contents: read + +jobs: + integration: + runs-on: ubuntu-latest + steps: + - name: Checkout calling Extra + uses: actions/checkout@v4 + with: + path: extra + + - name: Checkout eMCP + uses: actions/checkout@v4 + with: + repository: evolution-cms/evo-mcp + ref: ${{ inputs.emcp_ref }} + path: emcp + + - name: Set up PHP + uses: shivammathur/setup-php@v2 + with: + php-version: ${{ inputs.php_version }} + extensions: sqlite3, pdo_sqlite, mbstring, xml, curl, gd, zip, intl + tools: composer:v2 + coverage: none + + - name: Download Evolution CMS + env: + EVO_REF: ${{ inputs.evo_ref }} + run: git clone --depth 1 --branch "$EVO_REF" https://github.com/evolution-cms/evolution.git evo + + - name: Install Evolution CMS dependencies + working-directory: evo/core + env: + COMPOSER_ALLOW_SUPERUSER: '1' + run: composer install --no-dev --no-interaction --prefer-dist --no-progress + + - name: Add local Extra and eMCP as Composer path repositories + env: + EXTRA_PATH: ${{ github.workspace }}/extra + EMCP_PATH: ${{ github.workspace }}/emcp + EVO_PATH: ${{ github.workspace }}/evo + run: | + php <<'PHP' + 'evolutioncms/custom', + 'minimum-stability' => 'dev', + 'prefer-stable' => true, + 'repositories' => [ + ['type' => 'path', 'url' => $extraPath, 'options' => ['symlink' => true]], + ['type' => 'path', 'url' => $emcpPath, 'options' => ['symlink' => true]], + ], + 'require' => [ + $package => '*@dev', + 'evolution-cms/emcp' => '*@dev', + ], + 'autoload' => ['psr-4' => new stdClass()], + ]; + $destination = $evoPath . '/core/custom/composer.json'; + if (!is_dir(dirname($destination))) { + mkdir(dirname($destination), 0775, true); + } + file_put_contents($destination, json_encode($custom, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_THROW_ON_ERROR) . "\n"); + file_put_contents(getenv('GITHUB_ENV'), 'EXTRA_PACKAGE=' . $package . "\n", FILE_APPEND); + PHP + + - name: Install Extra and eMCP dependencies + working-directory: evo/core + env: + COMPOSER_ALLOW_SUPERUSER: '1' + COMPOSER_MEMORY_LIMIT: '-1' + run: composer update --no-dev --no-interaction --prefer-dist --no-progress --with-all-dependencies "$EXTRA_PACKAGE" evolution-cms/emcp + + - name: Install test Evolution CMS using SQLite + working-directory: evo/install + run: | + php cli-install.php \ + --typeInstall=1 \ + --databaseType=sqlite \ + --database=evolution \ + --tablePrefix=evo_ \ + --cmsAdmin=admin \ + --cmsAdminEmail=admin@example.com \ + --cmsPassword=IntegrationOnly123 \ + --language=en \ + --removeInstall=y \ + --skipComposer=y < /dev/null + + - name: Register packages and run migrations + working-directory: evo/core + run: | + rm -f storage/cache/env.php + php artisan package:discover + php artisan vendor:publish --provider='EvolutionCMS\eMCP\eMCPServiceProvider' --tag=emcp-config --force --no-interaction + php artisan vendor:publish --provider='EvolutionCMS\eMCP\eMCPServiceProvider' --tag=emcp-mcp-config --force --no-interaction + php artisan migrate --force --no-interaction + + - name: Verify eMCP and Extra installation + working-directory: evo/core + run: | + composer show evolution-cms/emcp + composer show "$EXTRA_PACKAGE" + php artisan emcp:list-servers + + - name: Verify MCP initialize and tools/list + working-directory: evo/core + env: + SERVER_HANDLE: ${{ inputs.server_handle }} + run: php artisan emcp:test --server="$SERVER_HANDLE" diff --git a/EXTRA_CI.md b/EXTRA_CI.md new file mode 100644 index 0000000..5a3f287 --- /dev/null +++ b/EXTRA_CI.md @@ -0,0 +1,21 @@ +# Reusable CI for Evolution CMS Extras + +The workflow `.github/workflows/extra-integration.yml` is reusable from third-party Extra repositories. It checks out the calling repository and eMCP, installs both as local Composer path repositories in a fresh Evolution CMS, runs migrations, and verifies MCP `initialize` and `tools/list` using `emcp:test`. + +Add a job to an Extra repository's GitHub Actions workflow: + +```yaml +jobs: + emcp: + uses: evolution-cms/evo-mcp/.github/workflows/extra-integration.yml@main + with: + evo_ref: 3.5.x + php_version: '8.4' + server_handle: content +``` + +The caller must have a valid root `composer.json` declaring the Extra's Composer package name. The workflow tests the calling commit rather than a published Packagist version. It does not require a Claude Code plugin, and it does not install optional API credentials. + +`emcp:test` verifies MCP protocol behavior for the selected server. A package-specific test asserting that particular tools are present in `tools/list` remains the responsibility of the Extra. This workflow does not assert that every Extra contributes a tool. + +Pin the reusable workflow to a release tag or commit SHA for reproducible CI once a stable version is available. From dca194a58ce62f471289768b6ffeb3401ec18cb2 Mon Sep 17 00:00:00 2001 From: Artur Kyryliuk Date: Sun, 15 Nov 2026 17:51:39 +0100 Subject: [PATCH 2/5] fix(ci): make the reusable Extra workflow install and assert Extra tools - Path repository URLs are written relative to core/custom: Evolution merges core/custom/composer.json through composer-merge-plugin, which prefixes "custom/" to every path URL, so absolute paths never resolved. - emcp:test gains a repeatable --expect-tool and prints every listed tool, and the workflow passes them from a new expected_tools input. - Authenticate Composer with the run token, keep emcp:test failures under tee (pipefail) and write the result to the run summary. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/extra-integration.yml | 51 +++++++++++++++++-- EXTRA_CI.md | 10 +++- README.md | 2 + src/Console/Commands/eMcpTestCommand.php | 31 ++++++++--- .../Unit/eMcpTestCommandRequirementsTest.php | 18 +++++++ 5 files changed, 100 insertions(+), 12 deletions(-) diff --git a/.github/workflows/extra-integration.yml b/.github/workflows/extra-integration.yml index 6eff143..cdd794f 100644 --- a/.github/workflows/extra-integration.yml +++ b/.github/workflows/extra-integration.yml @@ -19,6 +19,11 @@ on: type: string required: false default: content + expected_tools: + description: Tool names (space or newline separated) the Extra contributes; each must be listed by tools/list + type: string + required: false + default: '' permissions: contents: read @@ -47,6 +52,13 @@ jobs: tools: composer:v2 coverage: none + # A CMS build pulls a few hundred dist archives from api.github.com, which + # rate-limits anonymous callers; the run's own token lifts that. + - name: Authenticate Composer against GitHub + env: + GH_TOKEN: ${{ github.token }} + run: composer config --global --auth github-oauth.github.com "$GH_TOKEN" + - name: Download Evolution CMS env: EVO_REF: ${{ inputs.evo_ref }} @@ -75,13 +87,25 @@ jobs: fwrite(STDERR, "Extra composer.json must define a valid package name\n"); exit(1); } + // Evo merges core/custom/composer.json via composer-merge-plugin, which prefixes + // "custom/" to every path repository URL, so URLs must be relative to core/custom. + $customDir = $evoPath . '/core/custom'; + $relative = static function (string $target) use ($customDir): string { + $from = explode('/', trim($customDir, '/')); + $to = explode('/', trim(realpath($target), '/')); + while ($from !== [] && $to !== [] && $from[0] === $to[0]) { + array_shift($from); + array_shift($to); + } + return str_repeat('../', count($from)) . implode('/', $to); + }; $custom = [ 'name' => 'evolutioncms/custom', 'minimum-stability' => 'dev', 'prefer-stable' => true, 'repositories' => [ - ['type' => 'path', 'url' => $extraPath, 'options' => ['symlink' => true]], - ['type' => 'path', 'url' => $emcpPath, 'options' => ['symlink' => true]], + ['type' => 'path', 'url' => $relative($extraPath), 'options' => ['symlink' => true]], + ['type' => 'path', 'url' => $relative($emcpPath), 'options' => ['symlink' => true]], ], 'require' => [ $package => '*@dev', @@ -139,4 +163,25 @@ jobs: working-directory: evo/core env: SERVER_HANDLE: ${{ inputs.server_handle }} - run: php artisan emcp:test --server="$SERVER_HANDLE" + EXPECTED_TOOLS: ${{ inputs.expected_tools }} + EVO_REF: ${{ inputs.evo_ref }} + EMCP_REF: ${{ inputs.emcp_ref }} + PHP_VERSION: ${{ inputs.php_version }} + # bash with pipefail, so a failing emcp:test is not hidden by tee. + shell: bash + run: | + args=(--server="$SERVER_HANDLE") + for tool in $EXPECTED_TOOLS; do + args+=(--expect-tool="$tool") + done + php artisan emcp:test "${args[@]}" | tee "$RUNNER_TEMP/emcp-test.log" + { + echo "### eMCP integration: $EXTRA_PACKAGE" + echo + echo "- Evolution CMS: \`$EVO_REF\`, eMCP: \`$EMCP_REF\`, PHP $PHP_VERSION" + echo "- Expected tools: ${EXPECTED_TOOLS:-none (protocol checks only)}" + echo + echo '```' + cat "$RUNNER_TEMP/emcp-test.log" + echo '```' + } >> "$GITHUB_STEP_SUMMARY" diff --git a/EXTRA_CI.md b/EXTRA_CI.md index 5a3f287..088d483 100644 --- a/EXTRA_CI.md +++ b/EXTRA_CI.md @@ -12,10 +12,18 @@ jobs: evo_ref: 3.5.x php_version: '8.4' server_handle: content + # Optional: tools your Extra contributes; each must appear in tools/list. + expected_tools: >- + vendor.tool_one + vendor.tool_two ``` +Inputs (all optional): `evo_ref` (Evolution CMS branch or tag, default `3.5.x`), `emcp_ref` (eMCP ref, default `main`), `php_version` (default `8.4`), `server_handle` (default `content`), `expected_tools` (space- or newline-separated tool names, default empty). + +The job, in order: installs Evolution CMS dependencies, installs the Extra and eMCP from the checked-out sources, installs the CMS on SQLite, runs `package:discover`, publishes the eMCP config and runs all migrations, shows both packages and the configured servers, then runs `emcp:test`. The run summary contains the `emcp:test` output, including every tool name `tools/list` returned. + The caller must have a valid root `composer.json` declaring the Extra's Composer package name. The workflow tests the calling commit rather than a published Packagist version. It does not require a Claude Code plugin, and it does not install optional API credentials. -`emcp:test` verifies MCP protocol behavior for the selected server. A package-specific test asserting that particular tools are present in `tools/list` remains the responsibility of the Extra. This workflow does not assert that every Extra contributes a tool. +`emcp:test` verifies MCP `initialize` and `tools/list` for the selected server, and with `expected_tools` it fails when any named tool is missing (`php artisan emcp:test --server=content --expect-tool=vendor.tool_one`). It does not call the tools: invoking them needs a manager identity and data the Extra must set up, so `tools/call` coverage remains the Extra's own test suite. Without `expected_tools` the workflow does not assert that the Extra contributes any tool. Pin the reusable workflow to a release tag or commit SHA for reproducible CI once a stable version is available. diff --git a/README.md b/README.md index ce36cc4..1d04c3e 100644 --- a/README.md +++ b/README.md @@ -307,6 +307,8 @@ toolset is package-owned and the registry will reject that external server. `php artisan emcp:test --server=` runs generic `initialize` and `tools/list` checks for third-party servers. When the selected class is the canonical eMCP `ContentServer`, it also verifies the required Evolution toolset. +Add `--expect-tool=` (repeatable) to fail when a tool an Extra contributes +is missing; [EXTRA_CI.md](EXTRA_CI.md) wires this into a reusable workflow. Use `php artisan emcp:list-servers` to see both accepted servers and concrete reasons why configured entries were rejected. diff --git a/src/Console/Commands/eMcpTestCommand.php b/src/Console/Commands/eMcpTestCommand.php index b5eff56..e4d83be 100644 --- a/src/Console/Commands/eMcpTestCommand.php +++ b/src/Console/Commands/eMcpTestCommand.php @@ -20,7 +20,9 @@ */ class eMcpTestCommand extends Command { - protected $signature = 'emcp:test {--server= : Test a specific server handle}'; + protected $signature = 'emcp:test + {--server= : Test a specific server handle} + {--expect-tool=* : Tool name that must be listed by tools/list (repeatable)}'; protected $description = 'Run Gate A smoke checks for initialize/tools:list contract.'; @@ -157,7 +159,10 @@ public function handle(ServerRegistry $registry): int } } - $requiredTools = $this->requiredToolsForServer($serverClass); + sort($toolNames); + $this->line('tools/list returned ' . count($toolNames) . ' tools: ' . implode(', ', $toolNames)); + + $requiredTools = $this->requiredToolsForServer($serverClass, (array)$this->option('expect-tool')); $missingTools = array_values(array_diff($requiredTools, $toolNames)); if ($missingTools !== []) { @@ -174,20 +179,30 @@ public function handle(ServerRegistry $registry): int /** * Return package-owned tools that must be present for a canonical server. * - * Third-party servers intentionally receive an empty requirement list so - * emcp:test remains a protocol smoke test for arbitrary extensions. + * Third-party servers intentionally receive no built-in requirements so + * emcp:test remains a protocol smoke test for arbitrary extensions; an + * Extra names its own tools through --expect-tool. * + * @param array $expected * @return array * * @since 1.1.0 */ - private function requiredToolsForServer(string $serverClass): array + private function requiredToolsForServer(string $serverClass, array $expected = []): array { + $extra = []; + foreach ($expected as $name) { + $name = is_string($name) ? trim($name) : ''; + if ($name !== '') { + $extra[] = $name; + } + } + if ($serverClass !== ContentServer::class) { - return []; + return array_values(array_unique($extra)); } - return [ + return array_values(array_unique(array_merge([ 'evo.content.search', 'evo.content.get', 'evo.content.root_tree', @@ -197,7 +212,7 @@ private function requiredToolsForServer(string $serverClass): array 'evo.content.siblings', 'evo.model.list', 'evo.model.get', - ]; + ], $extra))); } /** diff --git a/tests/Unit/eMcpTestCommandRequirementsTest.php b/tests/Unit/eMcpTestCommandRequirementsTest.php index f6f4caa..efaa8a6 100644 --- a/tests/Unit/eMcpTestCommandRequirementsTest.php +++ b/tests/Unit/eMcpTestCommandRequirementsTest.php @@ -52,5 +52,23 @@ function assertRequirement(bool $condition, string $message): void 'Third-party servers must only receive generic initialize/tools:list checks' ); + /** @var array $expectedExtension */ + $expectedExtension = $method->invoke($command, 'Vendor\Project\PingServer', ['amount.mounts', ' ', 'amount.mounts', 7]); + assertRequirement( + $expectedExtension === ['amount.mounts'], + 'Third-party servers must require exactly the tools named by --expect-tool' + ); + + /** @var array $expectedCore */ + $expectedCore = $method->invoke($command, ContentServer::class, ['amount.mounts', 'evo.content.get']); + assertRequirement( + in_array('amount.mounts', $expectedCore, true) && in_array('evo.content.search', $expectedCore, true), + 'ContentServer must require both its own toolset and the tools named by --expect-tool' + ); + assertRequirement( + count($expectedCore) === count(array_unique($expectedCore)), + 'Required tools must not repeat' + ); + echo "eMCP test command requirement checks passed.\n"; } From 7f634b52da14c55e467defef14bad559f3f52c79 Mon Sep 17 00:00:00 2001 From: Artur Kyryliuk Date: Sun, 15 Nov 2026 17:55:59 +0100 Subject: [PATCH 3/5] fix(ci): list tools as a manager in the reusable Extra workflow emcp:test ran without a manager, so tools/list hid every tool that requires a permission - all of aMount's thirteen tools in the first real caller run. emcp:test gains --user (id or username), run through ManagerIdentity::runAs like an API token owner, and the workflow lists as the throwaway install's administrator by default (run_as input). Co-Authored-By: Claude Opus 5.5 --- .github/workflows/extra-integration.yml | 10 +++++ EXTRA_CI.md | 4 +- src/Console/Commands/eMcpTestCommand.php | 45 ++++++++++++++++++- .../Unit/eMcpTestCommandRequirementsTest.php | 7 +++ 4 files changed, 63 insertions(+), 3 deletions(-) diff --git a/.github/workflows/extra-integration.yml b/.github/workflows/extra-integration.yml index cdd794f..d934886 100644 --- a/.github/workflows/extra-integration.yml +++ b/.github/workflows/extra-integration.yml @@ -19,6 +19,11 @@ on: type: string required: false default: content + run_as: + description: Manager (username or id) tools/list is evaluated as; empty lists anonymously, which hides tools that require a permission + type: string + required: false + default: admin expected_tools: description: Tool names (space or newline separated) the Extra contributes; each must be listed by tools/list type: string @@ -164,6 +169,7 @@ jobs: env: SERVER_HANDLE: ${{ inputs.server_handle }} EXPECTED_TOOLS: ${{ inputs.expected_tools }} + RUN_AS: ${{ inputs.run_as }} EVO_REF: ${{ inputs.evo_ref }} EMCP_REF: ${{ inputs.emcp_ref }} PHP_VERSION: ${{ inputs.php_version }} @@ -171,6 +177,9 @@ jobs: shell: bash run: | args=(--server="$SERVER_HANDLE") + if [ -n "$RUN_AS" ]; then + args+=(--user="$RUN_AS") + fi for tool in $EXPECTED_TOOLS; do args+=(--expect-tool="$tool") done @@ -179,6 +188,7 @@ jobs: echo "### eMCP integration: $EXTRA_PACKAGE" echo echo "- Evolution CMS: \`$EVO_REF\`, eMCP: \`$EMCP_REF\`, PHP $PHP_VERSION" + echo "- Listed as: ${RUN_AS:-anonymous}" echo "- Expected tools: ${EXPECTED_TOOLS:-none (protocol checks only)}" echo echo '```' diff --git a/EXTRA_CI.md b/EXTRA_CI.md index 088d483..4e7ca7a 100644 --- a/EXTRA_CI.md +++ b/EXTRA_CI.md @@ -18,12 +18,12 @@ jobs: vendor.tool_two ``` -Inputs (all optional): `evo_ref` (Evolution CMS branch or tag, default `3.5.x`), `emcp_ref` (eMCP ref, default `main`), `php_version` (default `8.4`), `server_handle` (default `content`), `expected_tools` (space- or newline-separated tool names, default empty). +Inputs (all optional): `evo_ref` (Evolution CMS branch or tag, default `3.5.x`), `emcp_ref` (eMCP ref, default `main`), `php_version` (default `8.4`), `server_handle` (default `content`), `run_as` (the manager `tools/list` is evaluated as, default `admin` - the administrator of the throwaway install; empty means anonymous, which hides every tool that requires a permission), `expected_tools` (space- or newline-separated tool names, default empty). The job, in order: installs Evolution CMS dependencies, installs the Extra and eMCP from the checked-out sources, installs the CMS on SQLite, runs `package:discover`, publishes the eMCP config and runs all migrations, shows both packages and the configured servers, then runs `emcp:test`. The run summary contains the `emcp:test` output, including every tool name `tools/list` returned. The caller must have a valid root `composer.json` declaring the Extra's Composer package name. The workflow tests the calling commit rather than a published Packagist version. It does not require a Claude Code plugin, and it does not install optional API credentials. -`emcp:test` verifies MCP `initialize` and `tools/list` for the selected server, and with `expected_tools` it fails when any named tool is missing (`php artisan emcp:test --server=content --expect-tool=vendor.tool_one`). It does not call the tools: invoking them needs a manager identity and data the Extra must set up, so `tools/call` coverage remains the Extra's own test suite. Without `expected_tools` the workflow does not assert that the Extra contributes any tool. +`emcp:test` verifies MCP `initialize` and `tools/list` for the selected server, and with `expected_tools` it fails when any named tool is missing (`php artisan emcp:test --server=content --user=admin --expect-tool=vendor.tool_one`). It does not call the tools: invoking them needs a manager identity and data the Extra must set up, so `tools/call` coverage remains the Extra's own test suite. Without `expected_tools` the workflow does not assert that the Extra contributes any tool. Pin the reusable workflow to a release tag or commit SHA for reproducible CI once a stable version is available. diff --git a/src/Console/Commands/eMcpTestCommand.php b/src/Console/Commands/eMcpTestCommand.php index e4d83be..f478b1d 100644 --- a/src/Console/Commands/eMcpTestCommand.php +++ b/src/Console/Commands/eMcpTestCommand.php @@ -6,7 +6,9 @@ use EvolutionCMS\eMCP\Http\Controllers\McpManagerController; use EvolutionCMS\eMCP\Servers\ContentServer; +use EvolutionCMS\eMCP\Services\ManagerIdentity; use EvolutionCMS\eMCP\Services\ServerRegistry; +use EvolutionCMS\Models\User; use Illuminate\Console\Command; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response as HttpResponse; @@ -22,7 +24,8 @@ class eMcpTestCommand extends Command { protected $signature = 'emcp:test {--server= : Test a specific server handle} - {--expect-tool=* : Tool name that must be listed by tools/list (repeatable)}'; + {--expect-tool=* : Tool name that must be listed by tools/list (repeatable)} + {--user= : Manager id or username to list tools as (tools requiring a permission are hidden otherwise)}'; protected $description = 'Run Gate A smoke checks for initialize/tools:list contract.'; @@ -36,6 +39,46 @@ public function handle(ServerRegistry $registry): int { $this->line('Running eMCP Gate A smoke checks...'); + $userOption = trim((string)$this->option('user')); + if ($userOption === '') { + return $this->runChecks($registry); + } + + $user = $this->findUser($userOption); + if ($user === null) { + $this->error("Manager user [{$userOption}] not found."); + return self::FAILURE; + } + + /** @var ManagerIdentity $identity */ + $identity = app()->make(ManagerIdentity::class); + $reason = $identity->refusalReason($user); + if ($reason !== null) { + $this->error("Manager user [{$userOption}] may not act through MCP: {$reason}."); + return self::FAILURE; + } + + $this->line("Acting as manager: {$user->username} (id {$user->getKey()})"); + + return (int)$identity->runAs($user, fn(): int => $this->runChecks($registry)); + } + + /** + * Without a manager, tools/list hides every tool that requires a permission, + * which covers most tools contributed by Extras. + */ + private function findUser(string $idOrName): ?User + { + $query = User::query()->with('attributes'); + + return ctype_digit($idOrName) + ? $query->find((int)$idOrName) + : $query->where('username', $idOrName)->first(); + } + + private function runChecks(ServerRegistry $registry): int + { + $servers = $registry->allEnabled(); if ($servers === []) { $this->error('No valid enabled servers found in config(mcp.servers).'); diff --git a/tests/Unit/eMcpTestCommandRequirementsTest.php b/tests/Unit/eMcpTestCommandRequirementsTest.php index efaa8a6..7727f5e 100644 --- a/tests/Unit/eMcpTestCommandRequirementsTest.php +++ b/tests/Unit/eMcpTestCommandRequirementsTest.php @@ -70,5 +70,12 @@ function assertRequirement(bool $condition, string $message): void 'Required tools must not repeat' ); + // extra-integration.yml passes these options; renaming one breaks every Extra's CI. + $signature = (string)(new ReflectionProperty($command, 'signature'))->getValue($command); + assertRequirement( + str_contains($signature, '{--expect-tool=*') && str_contains($signature, '{--user='), + 'emcp:test must keep the --expect-tool and --user options used by the reusable Extra workflow' + ); + echo "eMCP test command requirement checks passed.\n"; } From 8ba8666c8ad5183f60d49ec09870f260d42f1001 Mon Sep 17 00:00:00 2001 From: Artur Kyryliuk Date: Sun, 15 Nov 2026 18:06:46 +0100 Subject: [PATCH 4/5] fix(emcp:test): follow tools/list pagination Laravel MCP pages tools/list (15 per page), so emcp:test only ever saw the first page: aMount's thirteen tools and eMCP's own evo.write.* tools were never checked. Follow nextCursor (bounded) and assert against every page. Drops the --user option from the previous commit: in CLI Evolution's isLoggedIn() is always true, so listing as a manager changed nothing. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/extra-integration.yml | 10 -- EXTRA_CI.md | 6 +- src/Console/Commands/eMcpTestCommand.php | 167 +++++++++--------- .../Unit/eMcpTestCommandRequirementsTest.php | 16 +- 4 files changed, 99 insertions(+), 100 deletions(-) diff --git a/.github/workflows/extra-integration.yml b/.github/workflows/extra-integration.yml index d934886..cdd794f 100644 --- a/.github/workflows/extra-integration.yml +++ b/.github/workflows/extra-integration.yml @@ -19,11 +19,6 @@ on: type: string required: false default: content - run_as: - description: Manager (username or id) tools/list is evaluated as; empty lists anonymously, which hides tools that require a permission - type: string - required: false - default: admin expected_tools: description: Tool names (space or newline separated) the Extra contributes; each must be listed by tools/list type: string @@ -169,7 +164,6 @@ jobs: env: SERVER_HANDLE: ${{ inputs.server_handle }} EXPECTED_TOOLS: ${{ inputs.expected_tools }} - RUN_AS: ${{ inputs.run_as }} EVO_REF: ${{ inputs.evo_ref }} EMCP_REF: ${{ inputs.emcp_ref }} PHP_VERSION: ${{ inputs.php_version }} @@ -177,9 +171,6 @@ jobs: shell: bash run: | args=(--server="$SERVER_HANDLE") - if [ -n "$RUN_AS" ]; then - args+=(--user="$RUN_AS") - fi for tool in $EXPECTED_TOOLS; do args+=(--expect-tool="$tool") done @@ -188,7 +179,6 @@ jobs: echo "### eMCP integration: $EXTRA_PACKAGE" echo echo "- Evolution CMS: \`$EVO_REF\`, eMCP: \`$EMCP_REF\`, PHP $PHP_VERSION" - echo "- Listed as: ${RUN_AS:-anonymous}" echo "- Expected tools: ${EXPECTED_TOOLS:-none (protocol checks only)}" echo echo '```' diff --git a/EXTRA_CI.md b/EXTRA_CI.md index 4e7ca7a..906786b 100644 --- a/EXTRA_CI.md +++ b/EXTRA_CI.md @@ -18,12 +18,12 @@ jobs: vendor.tool_two ``` -Inputs (all optional): `evo_ref` (Evolution CMS branch or tag, default `3.5.x`), `emcp_ref` (eMCP ref, default `main`), `php_version` (default `8.4`), `server_handle` (default `content`), `run_as` (the manager `tools/list` is evaluated as, default `admin` - the administrator of the throwaway install; empty means anonymous, which hides every tool that requires a permission), `expected_tools` (space- or newline-separated tool names, default empty). +Inputs (all optional): `evo_ref` (Evolution CMS branch or tag, default `3.5.x`), `emcp_ref` (eMCP ref, default `main`), `php_version` (default `8.4`), `server_handle` (default `content`), `expected_tools` (space- or newline-separated tool names, default empty). -The job, in order: installs Evolution CMS dependencies, installs the Extra and eMCP from the checked-out sources, installs the CMS on SQLite, runs `package:discover`, publishes the eMCP config and runs all migrations, shows both packages and the configured servers, then runs `emcp:test`. The run summary contains the `emcp:test` output, including every tool name `tools/list` returned. +The job, in order: installs Evolution CMS dependencies, installs the Extra and eMCP from the checked-out sources, installs the CMS on SQLite, runs `package:discover`, publishes the eMCP config and runs all migrations, shows both packages and the configured servers, then runs `emcp:test`. The run summary contains the `emcp:test` output, including every tool name `tools/list` returned (all pages). The caller must have a valid root `composer.json` declaring the Extra's Composer package name. The workflow tests the calling commit rather than a published Packagist version. It does not require a Claude Code plugin, and it does not install optional API credentials. -`emcp:test` verifies MCP `initialize` and `tools/list` for the selected server, and with `expected_tools` it fails when any named tool is missing (`php artisan emcp:test --server=content --user=admin --expect-tool=vendor.tool_one`). It does not call the tools: invoking them needs a manager identity and data the Extra must set up, so `tools/call` coverage remains the Extra's own test suite. Without `expected_tools` the workflow does not assert that the Extra contributes any tool. +`emcp:test` verifies MCP `initialize` and `tools/list` for the selected server, and with `expected_tools` it fails when any named tool is missing (`php artisan emcp:test --server=content --expect-tool=vendor.tool_one`). It does not call the tools: invoking them needs a manager identity and data the Extra must set up, so `tools/call` coverage remains the Extra's own test suite. Without `expected_tools` the workflow does not assert that the Extra contributes any tool. Pin the reusable workflow to a release tag or commit SHA for reproducible CI once a stable version is available. diff --git a/src/Console/Commands/eMcpTestCommand.php b/src/Console/Commands/eMcpTestCommand.php index f478b1d..859e715 100644 --- a/src/Console/Commands/eMcpTestCommand.php +++ b/src/Console/Commands/eMcpTestCommand.php @@ -6,9 +6,7 @@ use EvolutionCMS\eMCP\Http\Controllers\McpManagerController; use EvolutionCMS\eMCP\Servers\ContentServer; -use EvolutionCMS\eMCP\Services\ManagerIdentity; use EvolutionCMS\eMCP\Services\ServerRegistry; -use EvolutionCMS\Models\User; use Illuminate\Console\Command; use Illuminate\Http\Request; use Symfony\Component\HttpFoundation\Response as HttpResponse; @@ -24,11 +22,13 @@ class eMcpTestCommand extends Command { protected $signature = 'emcp:test {--server= : Test a specific server handle} - {--expect-tool=* : Tool name that must be listed by tools/list (repeatable)} - {--user= : Manager id or username to list tools as (tools requiring a permission are hidden otherwise)}'; + {--expect-tool=* : Tool name that must be listed by tools/list (repeatable)}'; protected $description = 'Run Gate A smoke checks for initialize/tools:list contract.'; + /** Guards against a server that never stops returning nextCursor. */ + private const MAX_TOOL_PAGES = 100; + /** * Execute initialize and tools/list against the selected server handle. * @@ -39,46 +39,6 @@ public function handle(ServerRegistry $registry): int { $this->line('Running eMCP Gate A smoke checks...'); - $userOption = trim((string)$this->option('user')); - if ($userOption === '') { - return $this->runChecks($registry); - } - - $user = $this->findUser($userOption); - if ($user === null) { - $this->error("Manager user [{$userOption}] not found."); - return self::FAILURE; - } - - /** @var ManagerIdentity $identity */ - $identity = app()->make(ManagerIdentity::class); - $reason = $identity->refusalReason($user); - if ($reason !== null) { - $this->error("Manager user [{$userOption}] may not act through MCP: {$reason}."); - return self::FAILURE; - } - - $this->line("Acting as manager: {$user->username} (id {$user->getKey()})"); - - return (int)$identity->runAs($user, fn(): int => $this->runChecks($registry)); - } - - /** - * Without a manager, tools/list hides every tool that requires a permission, - * which covers most tools contributed by Extras. - */ - private function findUser(string $idOrName): ?User - { - $query = User::query()->with('attributes'); - - return ctype_digit($idOrName) - ? $query->find((int)$idOrName) - : $query->where('username', $idOrName)->first(); - } - - private function runChecks(ServerRegistry $registry): int - { - $servers = $registry->allEnabled(); if ($servers === []) { $this->error('No valid enabled servers found in config(mcp.servers).'); @@ -153,54 +113,58 @@ private function runChecks(ServerRegistry $registry): int $this->info('initialize: OK'); - $toolsListPayload = [ - 'jsonrpc' => '2.0', - 'id' => 'tools-1', - 'method' => 'tools/list', - 'params' => (object)[], - ]; - - $toolsList = $this->dispatchJsonRpc($serverHandle, $toolsListPayload, $sessionId); - if (isset($toolsList['error'])) { - $this->error($toolsList['error']); - return self::FAILURE; - } - - $toolsListResponse = $toolsList['response'] ?? null; - if (!$toolsListResponse instanceof HttpResponse) { - $this->error('tools/list returned unexpected response type.'); - return self::FAILURE; - } + // tools/list is paginated (Laravel MCP sends 15 per page), so follow nextCursor. + $toolNames = []; + $cursor = null; + $page = 0; + do { + if (++$page > self::MAX_TOOL_PAGES) { + $this->error('tools/list kept returning nextCursor after ' . self::MAX_TOOL_PAGES . ' pages.'); + return self::FAILURE; + } - if ($toolsListResponse->getStatusCode() !== 200) { - $this->error('tools/list failed with HTTP ' . $toolsListResponse->getStatusCode()); - $this->line((string)$toolsListResponse->getContent()); - return self::FAILURE; - } + $toolsListPayload = [ + 'jsonrpc' => '2.0', + 'id' => 'tools-' . $page, + 'method' => 'tools/list', + 'params' => $cursor === null ? (object)[] : ['cursor' => $cursor], + ]; + + $toolsList = $this->dispatchJsonRpc($serverHandle, $toolsListPayload, $sessionId); + if (isset($toolsList['error'])) { + $this->error($toolsList['error']); + return self::FAILURE; + } - $toolsListJson = $this->decodeJson((string)$toolsListResponse->getContent()); - if ($toolsListJson === null) { - $this->error('tools/list returned invalid JSON payload.'); - return self::FAILURE; - } + $toolsListResponse = $toolsList['response'] ?? null; + if (!$toolsListResponse instanceof HttpResponse) { + $this->error('tools/list returned unexpected response type.'); + return self::FAILURE; + } - if (!isset($toolsListJson['result']['tools']) || !is_array($toolsListJson['result']['tools'])) { - $this->error('tools/list response does not contain result.tools array.'); - $this->line((string)$toolsListResponse->getContent()); - return self::FAILURE; - } + if ($toolsListResponse->getStatusCode() !== 200) { + $this->error('tools/list failed with HTTP ' . $toolsListResponse->getStatusCode()); + $this->line((string)$toolsListResponse->getContent()); + return self::FAILURE; + } - $toolNames = []; - foreach ($toolsListJson['result']['tools'] as $tool) { - if (!is_array($tool)) { - continue; + $toolsListJson = $this->decodeJson((string)$toolsListResponse->getContent()); + if ($toolsListJson === null) { + $this->error('tools/list returned invalid JSON payload.'); + return self::FAILURE; } - $name = trim((string)($tool['name'] ?? '')); - if ($name !== '') { - $toolNames[] = $name; + if (!isset($toolsListJson['result']['tools']) || !is_array($toolsListJson['result']['tools'])) { + $this->error('tools/list response does not contain result.tools array.'); + $this->line((string)$toolsListResponse->getContent()); + return self::FAILURE; } - } + + $toolNames = array_merge($toolNames, self::toolNamesFromPage($toolsListJson['result']['tools'])); + $cursor = self::nextCursor($toolsListJson['result']); + } while ($cursor !== null); + + $toolNames = array_values(array_unique($toolNames)); sort($toolNames); $this->line('tools/list returned ' . count($toolNames) . ' tools: ' . implode(', ', $toolNames)); @@ -219,6 +183,39 @@ private function runChecks(ServerRegistry $registry): int return self::SUCCESS; } + /** + * Tool names of one tools/list page; entries without a name are skipped. + * + * @param array $tools + * @return array + */ + private static function toolNamesFromPage(array $tools): array + { + $names = []; + foreach ($tools as $tool) { + if (!is_array($tool)) { + continue; + } + + $name = trim((string)($tool['name'] ?? '')); + if ($name !== '') { + $names[] = $name; + } + } + + return $names; + } + + /** + * @param array $result + */ + private static function nextCursor(array $result): ?string + { + $cursor = $result['nextCursor'] ?? null; + + return is_string($cursor) && $cursor !== '' ? $cursor : null; + } + /** * Return package-owned tools that must be present for a canonical server. * diff --git a/tests/Unit/eMcpTestCommandRequirementsTest.php b/tests/Unit/eMcpTestCommandRequirementsTest.php index 7727f5e..ef7ddf8 100644 --- a/tests/Unit/eMcpTestCommandRequirementsTest.php +++ b/tests/Unit/eMcpTestCommandRequirementsTest.php @@ -70,11 +70,23 @@ function assertRequirement(bool $condition, string $message): void 'Required tools must not repeat' ); + // tools/list pages: every named tool is kept, the cursor ends the loop when absent or empty. + $names = (new ReflectionMethod($command, 'toolNamesFromPage'))->invoke(null, [ + ['name' => 'amount.mounts'], ['name' => ' '], 'junk', ['title' => 'no name'], ['name' => 'evo.model.get'], + ]); + assertRequirement($names === ['amount.mounts', 'evo.model.get'], 'A page must yield exactly its named tools'); + + $next = new ReflectionMethod($command, 'nextCursor'); + assertRequirement($next->invoke(null, ['nextCursor' => 'abc']) === 'abc', 'nextCursor must be followed'); + assertRequirement($next->invoke(null, ['nextCursor' => '']) === null, 'An empty nextCursor ends the listing'); + assertRequirement($next->invoke(null, ['tools' => []]) === null, 'A missing nextCursor ends the listing'); + assertRequirement($next->invoke(null, ['nextCursor' => 5]) === null, 'A non-string nextCursor ends the listing'); + // extra-integration.yml passes these options; renaming one breaks every Extra's CI. $signature = (string)(new ReflectionProperty($command, 'signature'))->getValue($command); assertRequirement( - str_contains($signature, '{--expect-tool=*') && str_contains($signature, '{--user='), - 'emcp:test must keep the --expect-tool and --user options used by the reusable Extra workflow' + str_contains($signature, '{--expect-tool=*'), + 'emcp:test must keep the --expect-tool option used by the reusable Extra workflow' ); echo "eMCP test command requirement checks passed.\n"; From 896e7484f6670ba44620c38f850211163d11f96a Mon Sep 17 00:00:00 2001 From: Artur Kyryliuk Date: Sun, 15 Nov 2026 18:22:56 +0100 Subject: [PATCH 5/5] fix(ci): install the CMS before the Extra, fail on pending migrations With eMCP and sTask already in vendor, the CLI installer runs their migrations without recording them; the workflow's migrate then stopped at "table evo_s_workers already exists" - and exited 0, so eMCP's and the Extra's migrations silently never ran. Install a clean CMS first, then add the packages, and fail when migrate:status still lists anything Pending. Co-Authored-By: Claude Opus 5.5 --- .github/workflows/extra-integration.yml | 40 +++++++++++++++---------- EXTRA_CI.md | 2 +- 2 files changed, 26 insertions(+), 16 deletions(-) diff --git a/.github/workflows/extra-integration.yml b/.github/workflows/extra-integration.yml index cdd794f..5ba486e 100644 --- a/.github/workflows/extra-integration.yml +++ b/.github/workflows/extra-integration.yml @@ -70,6 +70,24 @@ jobs: COMPOSER_ALLOW_SUPERUSER: '1' run: composer install --no-dev --no-interaction --prefer-dist --no-progress + # A clean CMS first, then the packages, as on a real site: with eMCP (and its sTask) + # already in vendor, the CLI installer runs their migrations without recording them, + # and the later migrate stops at "table already exists". + - name: Install test Evolution CMS using SQLite + working-directory: evo/install + run: | + php cli-install.php \ + --typeInstall=1 \ + --databaseType=sqlite \ + --database=evolution \ + --tablePrefix=evo_ \ + --cmsAdmin=admin \ + --cmsAdminEmail=admin@example.com \ + --cmsPassword=IntegrationOnly123 \ + --language=en \ + --removeInstall=y \ + --skipComposer=y < /dev/null + - name: Add local Extra and eMCP as Composer path repositories env: EXTRA_PATH: ${{ github.workspace }}/extra @@ -128,29 +146,21 @@ jobs: COMPOSER_MEMORY_LIMIT: '-1' run: composer update --no-dev --no-interaction --prefer-dist --no-progress --with-all-dependencies "$EXTRA_PACKAGE" evolution-cms/emcp - - name: Install test Evolution CMS using SQLite - working-directory: evo/install - run: | - php cli-install.php \ - --typeInstall=1 \ - --databaseType=sqlite \ - --database=evolution \ - --tablePrefix=evo_ \ - --cmsAdmin=admin \ - --cmsAdminEmail=admin@example.com \ - --cmsPassword=IntegrationOnly123 \ - --language=en \ - --removeInstall=y \ - --skipComposer=y < /dev/null - - name: Register packages and run migrations working-directory: evo/core + shell: bash run: | rm -f storage/cache/env.php php artisan package:discover php artisan vendor:publish --provider='EvolutionCMS\eMCP\eMCPServiceProvider' --tag=emcp-config --force --no-interaction php artisan vendor:publish --provider='EvolutionCMS\eMCP\eMCPServiceProvider' --tag=emcp-mcp-config --force --no-interaction php artisan migrate --force --no-interaction + # artisan migrate exits 0 even when a migration fails, so check what is left. + php artisan migrate:status --no-interaction | tee "$RUNNER_TEMP/migrate-status.txt" + if grep -q 'Pending' "$RUNNER_TEMP/migrate-status.txt"; then + echo '::error::Migrations are still pending after migrate' + exit 1 + fi - name: Verify eMCP and Extra installation working-directory: evo/core diff --git a/EXTRA_CI.md b/EXTRA_CI.md index 906786b..126e684 100644 --- a/EXTRA_CI.md +++ b/EXTRA_CI.md @@ -20,7 +20,7 @@ jobs: Inputs (all optional): `evo_ref` (Evolution CMS branch or tag, default `3.5.x`), `emcp_ref` (eMCP ref, default `main`), `php_version` (default `8.4`), `server_handle` (default `content`), `expected_tools` (space- or newline-separated tool names, default empty). -The job, in order: installs Evolution CMS dependencies, installs the Extra and eMCP from the checked-out sources, installs the CMS on SQLite, runs `package:discover`, publishes the eMCP config and runs all migrations, shows both packages and the configured servers, then runs `emcp:test`. The run summary contains the `emcp:test` output, including every tool name `tools/list` returned (all pages). +The job, in order: installs a clean Evolution CMS on SQLite, adds the Extra and eMCP from the checked-out sources (as a site owner adding them later would), runs `package:discover`, publishes the eMCP config, runs all migrations and fails if any is still pending (`artisan migrate` itself exits 0 when one fails), shows both packages and the configured servers, then runs `emcp:test`. The run summary contains the `emcp:test` output, including every tool name `tools/list` returned (all pages). The caller must have a valid root `composer.json` declaring the Extra's Composer package name. The workflow tests the calling commit rather than a published Packagist version. It does not require a Claude Code plugin, and it does not install optional API credentials.