Skip to content

Practical patterns, starters & CLI tools for loop engineering with AI coding agents. Design systems that prompt and orchestrate agents (inspired by Addy Osmani and Boris Cherny). Includes loop-audit, loop-init, loop-cost.

fix(mcp): normalize sibling dependencies in release tarballs (#666)

Chanhyo Jung1180d3c864cc
diff --git a/.github/workflows/release-loop-mcp-server.yml b/.github/workflows/release-loop-mcp-server.yml
index c2cfc56..3f342eb 100644
--- a/.github/workflows/release-loop-mcp-server.yml
+++ b/.github/workflows/release-loop-mcp-server.yml
@@ -66,7 +66,12 @@ jobs:
- name: Publish to npm
if: steps.check.outputs.skip != 'true'
working-directory: tools/mcp-server
- run: npm publish --access public --provenance
+ run: |
+ # Publishing a tarball does not run prepublishOnly; keep its test gate.
+ npm run prepublishOnly
+ mkdir -p "$RUNNER_TEMP/loop-mcp-server"
+ npm run pack:publish -- --pack-destination "$RUNNER_TEMP/loop-mcp-server"
+ npm publish "$RUNNER_TEMP/loop-mcp-server/"*.tgz --access public --provenance
env:
# OIDC trusted publishing — do not set NODE_AUTH_TOKEN (it overrides OIDC)
- NPM_CONFIG_PROVENANCE: "true"
\ No newline at end of file
+ NPM_CONFIG_PROVENANCE: "true"
diff --git a/tools/mcp-server/package.json b/tools/mcp-server/package.json
index 320312f..d88f7ff 100644
--- a/tools/mcp-server/package.json
+++ b/tools/mcp-server/package.json
@@ -12,7 +12,8 @@
],
"scripts": {
"build": "tsc",
- "test": "npm run build && node --test test/server.test.mjs",
+ "test": "npm run build && node --test test/*.test.mjs",
+ "pack:publish": "node scripts/pack-for-publish.mjs",
"prepublishOnly": "npm test",
"start": "node dist/index.js"
},
diff --git a/tools/mcp-server/scripts/pack-for-publish.mjs b/tools/mcp-server/scripts/pack-for-publish.mjs
new file mode 100644
index 0000000..1494277
--- /dev/null
+++ b/tools/mcp-server/scripts/pack-for-publish.mjs
@@ -0,0 +1,20 @@
+import { readFileSync, writeFileSync } from 'node:fs';
+import { spawnSync } from 'node:child_process';
+
+const original = readFileSync('package.json', 'utf8');
+const manifest = JSON.parse(original);
+Object.assign(manifest.dependencies, {
+ '@cobusgreyling/loop-audit': '^1.9.0',
+ '@cobusgreyling/loop-context': '^1.5.0',
+ '@cobusgreyling/loop-cost': '^1.2.0',
+ '@cobusgreyling/loop-gate': '^1.0.0',
+});
+
+try {
+ writeFileSync('package.json', JSON.stringify(manifest, null, 2) + '\n');
+ const result = spawnSync('npm', ['pack', '--json', ...process.argv.slice(2)], { stdio: 'inherit' });
+ if (result.error) throw result.error;
+ process.exitCode = result.status ?? 1;
+} finally {
+ writeFileSync('package.json', original);
+}
diff --git a/tools/mcp-server/test/publish.test.mjs b/tools/mcp-server/test/publish.test.mjs
new file mode 100644
index 0000000..4f109c5
--- /dev/null
+++ b/tools/mcp-server/test/publish.test.mjs
@@ -0,0 +1,58 @@
+import { test } from 'node:test';
+import assert from 'node:assert/strict';
+import { cp, mkdtemp, mkdir, readFile, rm } from 'node:fs/promises';
+import { tmpdir } from 'node:os';
+import { basename, join } from 'node:path';
+import { fileURLToPath } from 'node:url';
+import { spawnSync } from 'node:child_process';
+
+const packageRoot = fileURLToPath(new URL('../', import.meta.url));
+
+async function fixture(t) {
+ const directory = await mkdtemp(join(tmpdir(), 'mcp-publish-'));
+ t.after(() => rm(directory, { recursive: true, force: true }));
+ const cwd = join(directory, 'package');
+ await cp(packageRoot, cwd, {
+ recursive: true,
+ filter: source => !['node_modules', 'test'].includes(basename(source)) && !source.endsWith('.tgz'),
+ });
+ const destination = join(directory, 'artifacts');
+ await mkdir(destination);
+ const original = await readFile(join(cwd, 'package.json'), 'utf8');
+ return { cwd, destination, original };
+}
+
+function pack(cwd, destination) {
+ return spawnSync('npm', ['run', '--silent', 'pack:publish', '--', '--pack-destination', destination], {
+ cwd, encoding: 'utf8', timeout: 30_000,
+ });
+}
+
+test('publication tarball uses public sibling versions and preserves the development manifest', async t => {
+ const { cwd, destination, original } = await fixture(t);
+ const result = pack(cwd, destination);
+ assert.equal(result.status, 0, result.stderr);
+ const [artifact] = JSON.parse(result.stdout);
+ const unpacked = spawnSync('tar', ['-xOf', join(destination, artifact.filename), 'package/package.json'], {
+ encoding: 'utf8', timeout: 10_000,
+ });
+ assert.equal(unpacked.status, 0, unpacked.stderr);
+ const expected = JSON.parse(original);
+ Object.assign(expected.dependencies, {
+ '@cobusgreyling/loop-audit': '^1.9.0',
+ '@cobusgreyling/loop-context': '^1.5.0',
+ '@cobusgreyling/loop-cost': '^1.2.0',
+ '@cobusgreyling/loop-gate': '^1.0.0',
+ });
+ assert.deepEqual(JSON.parse(unpacked.stdout), expected);
+ assert.ok(artifact.files.some(file => file.path === 'dist/index.js'));
+ assert.equal(await readFile(join(cwd, 'package.json'), 'utf8'), original);
+});
+
+test('a failed pack reports failure and restores the development manifest', async t => {
+ const { cwd, destination, original } = await fixture(t);
+ const result = pack(cwd, join(destination, 'missing'));
+ assert.notEqual(result.status, 0);
+ assert.match(result.stdout + result.stderr, /ENOENT/);
+ assert.equal(await readFile(join(cwd, 'package.json'), 'utf8'), original);
+});