Skip to content
Closed
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
5 changes: 5 additions & 0 deletions .changeset/filesystem-oldtext-description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@modelcontextprotocol/server-filesystem": patch
---

`edit_file`'s `edits[].oldText` parameter description now states the matching rule the tool applies (exact apart from line endings, else whole lines ignoring leading and trailing whitespace), instead of "must match exactly", which contradicted the tool's own description.
5 changes: 5 additions & 0 deletions .changeset/filesystem-ship-license.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@modelcontextprotocol/server-filesystem": patch
---

Ship the repository's `LICENSE` in the npm package, which `package.json` already pointed at but the tarball left out, and correct the README's license section, which said MIT only, to describe the MIT to Apache-2.0 transition terms in that file.
4 changes: 3 additions & 1 deletion docs/quality-gate.md
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,9 @@ covers: the repo-wide tooling and the guards that keep the gate itself honest.
installed server. It catches what the boot smoke cannot, since the smoke
runs the checkout: a file missing from the tarball, a dependency that only
resolves inside the workspace. It also fails an npm tarball that ships a
test, a test helper or a test runner's config. It needs the network, so it is not a gate
test, a test helper or a test runner's config, and one that leaves out the
license file its `package.json` names (`SEE LICENSE IN LICENSE`; the
packages #5700 has yet to fix are exempt). It needs the network, so it is not a gate
stage. `release.yml` runs it before anything publishes, and the `release`
skill runs it by hand for the release ledger.
- **`npm run format`** rewrites files, so it is something you run, not
Expand Down
45 changes: 43 additions & 2 deletions scripts/pack-and-verify.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ export function parseArgs(argv) {

/**
* What is wrong with an npm tarball's contents, judged from its manifest and
* file list alone: every `bin` target must be in it, and no test or test
* config file may be (#4930). Anything subtler (a module the entry point
* file list alone: every `bin` target must be in it, no test or test config
* file may be (#4930), and a license file the manifest names
* (`"license": "SEE LICENSE IN LICENSE"`) must be in it (#5639), unless the
* package is in `LICENSE_PENDING`. Anything subtler (a module the entry point
* imports, a data file) is found by actually running the installed bin, which
* is the next step.
*
Expand All @@ -124,6 +126,45 @@ export function tarballProblems(manifest, files) {
...files
.filter(isTestFile)
.map((f) => `${f} is a test file, which a package does not ship`),
...licenseProblems(manifest, present),
];
}

/**
* The npm packages that do not ship the license file their manifest names
* yet. The filesystem package published with `"license": "SEE LICENSE IN
* LICENSE"` and no LICENSE in its tarball (#5639); these three still do, and
* #5700 fixes them. The check passes them so that their releases are not
* blocked meanwhile. Remove a package from this list in the change that makes
* it ship the file: the script tests fail on a listed package that already
* does, so the list can only shrink.
*/
export const LICENSE_PENDING = new Set([
"@modelcontextprotocol/server-everything",
"@modelcontextprotocol/server-memory",
"@modelcontextprotocol/server-sequential-thinking",
]);

/**
* The license file a manifest points at, from the `SEE LICENSE IN <file>`
* form of its `license` field, or `null` when it names an SPDX expression or
* nothing.
*
* @param {{ license?: string }} manifest
* @returns {string | null}
*/
export function licenseFile(manifest) {
const match = /^SEE LICENSE IN (.+)$/.exec(manifest.license ?? "");
return match ? match[1].trim() : null;
}

/** The license file the manifest names, when the tarball lacks it. */
function licenseProblems(manifest, present) {
const file = licenseFile(manifest);
if (!file || LICENSE_PENDING.has(manifest.name)) return [];
if (present.has(path.posix.normalize(file))) return [];
return [
`package.json says "${manifest.license}", but ${file} is not in the tarball`,
];
}

Expand Down
96 changes: 95 additions & 1 deletion scripts/pack-and-verify.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,44 @@
// tarball check and where an installed command lives. The rest of the script
// is `npm pack`, `npm install`, `uv build` and a real server boot, which need
// the network and are exercised by running `npm run pack:verify` itself.
// Run via `npm run test:scripts`.
// One test is a guard on the repository as it stands (#5639): each npm
// package's file list, from an offline `npm pack --dry-run`, holds the license
// file its manifest names, with the same text as the root LICENSE. That runs
// in `validate:guards`, so a package that would publish without it fails
// before release rather than at it. Run via `npm run test:scripts`.

import { test } from "node:test";
import assert from "node:assert/strict";
import { spawnSync } from "node:child_process";
import {
existsSync,
mkdirSync,
mkdtempSync,
readFileSync,
rmSync,
writeFileSync,
} from "node:fs";
import { tmpdir } from "node:os";
import path from "node:path";
import { fileURLToPath } from "node:url";
import {
LICENSE_PENDING,
artifactDirProblem,
consumerEnv,
installedLaunch,
isDistribution,
isTestFile,
licenseFile,
main,
parseArgs,
tarballProblems,
} from "./pack-and-verify.mjs";
import { SERVERS } from "./smoke-servers.mjs";

const repoRoot = path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"..",
);

test("parseArgs separates server names from --out", () => {
assert.deepEqual(parseArgs([]), { names: [], out: undefined });
Expand Down Expand Up @@ -88,6 +103,85 @@ test("a test or test-config file in the tarball is named (#4930)", () => {
);
});

test("a license file the manifest names must be in the tarball (#5639)", () => {
const manifest = {
name: "@scope/pkg",
bin: { cmd: "dist/index.js" },
license: "SEE LICENSE IN LICENSE",
};
assert.deepEqual(tarballProblems(manifest, ["dist/index.js", "LICENSE"]), []);
assert.deepEqual(tarballProblems(manifest, ["dist/index.js"]), [
'package.json says "SEE LICENSE IN LICENSE", but LICENSE is not in the tarball',
]);
// An SPDX expression names no file, so there is nothing to look for.
assert.deepEqual(
tarballProblems({ ...manifest, license: "MIT" }, ["dist/index.js"]),
[],
);
// A package still waiting on its fix (#5700) is passed meanwhile.
const [pending] = LICENSE_PENDING;
assert.deepEqual(
tarballProblems({ ...manifest, name: pending }, ["dist/index.js"]),
[],
);
});

test("licenseFile reads the SEE LICENSE IN form, and only that", () => {
assert.equal(licenseFile({ license: "SEE LICENSE IN LICENSE" }), "LICENSE");
assert.equal(
licenseFile({ license: "SEE LICENSE IN docs/LICENSE.txt" }),
"docs/LICENSE.txt",
);
assert.equal(licenseFile({ license: "Apache-2.0" }), null);
assert.equal(licenseFile({}), null);
});

test("each npm package ships the root LICENSE its manifest names, unless pending", () => {
const rootLicense = readFileSync(path.join(repoRoot, "LICENSE"), "utf8");
const npmServers = SERVERS.filter((s) => s.language === "ts");
assert.ok(npmServers.length > 0, "no TypeScript servers found");
const names = new Set();
for (const server of npmServers) {
const pkgDir = path.join(repoRoot, "src", server.name);
const manifest = JSON.parse(
readFileSync(path.join(pkgDir, "package.json"), "utf8"),
);
names.add(manifest.name);
const file = licenseFile(manifest);
assert.ok(file, `${manifest.name}: license is not "SEE LICENSE IN <file>"`);
// What `npm pack` would put in the tarball, read without building it:
// `--ignore-scripts` skips the `prepare` build, and `--dry-run` writes
// nothing. The license file does not depend on the build.
const res = spawnSync(
"npm",
["pack", "--dry-run", "--json", "--ignore-scripts"],
{ cwd: pkgDir, encoding: "utf8", shell: process.platform === "win32" },
);
assert.equal(res.status, 0, `npm pack failed in ${pkgDir}: ${res.stderr}`);
const shipped = JSON.parse(res.stdout)[0].files.some(
(f) => path.posix.normalize(f.path) === path.posix.normalize(file),
);
if (LICENSE_PENDING.has(manifest.name)) {
assert.ok(
!shipped,
`${manifest.name} now ships ${file}: remove it from LICENSE_PENDING`,
);
continue;
}
assert.ok(shipped, `${manifest.name}: ${file} is not in its tarball`);
assert.equal(
readFileSync(path.join(pkgDir, file), "utf8"),
rootLicense,
`src/${server.name}/${file} differs from the root LICENSE: copy it again`,
);
}
for (const pending of LICENSE_PENDING)
assert.ok(
names.has(pending),
`LICENSE_PENDING names ${pending}, which is not a package here`,
);
});

test("isTestFile matches tests, helpers and runner configs, nothing else", () => {
for (const f of [
"dist/__tests__/helpers.js",
Expand Down
Loading