|
| 1 | +// `mcp add porkbun` should be enough — but the catalog must never be able to |
| 2 | +// override a command the user actually typed, and it must never quietly bake an |
| 3 | +// API key into five engines' config files. |
| 4 | +import assert from "node:assert/strict"; |
| 5 | +import test from "node:test"; |
| 6 | + |
| 7 | +import { MCP_CATALOG, catalogList, catalogNames, resolveCatalog } from "../src/mcp-catalog.mjs"; |
| 8 | +import { parseMcp } from "../src/integrations.mjs"; |
| 9 | + |
| 10 | +test("porkbun resolves to the official npx invocation", () => { |
| 11 | + const e = resolveCatalog("porkbun"); |
| 12 | + assert.equal(e.key, "porkbun"); |
| 13 | + assert.equal(e.target, "npx"); |
| 14 | + assert.deepEqual(e.args, ["-y", "@porkbunllc/mcp-server"]); |
| 15 | + assert.deepEqual(e.env, ["PORKBUN_API_KEY", "PORKBUN_SECRET_API_KEY"]); |
| 16 | +}); |
| 17 | + |
| 18 | +test("catalog lookup is case-insensitive and ignores Object.prototype", () => { |
| 19 | + assert.equal(resolveCatalog("PORKBUN").key, "porkbun"); |
| 20 | + assert.equal(resolveCatalog(" porkbun ").key, "porkbun"); |
| 21 | + // A plain object literal: these are truthy but are not servers, and would |
| 22 | + // otherwise be handed downstream with no target. |
| 23 | + assert.equal(resolveCatalog("constructor"), null); |
| 24 | + assert.equal(resolveCatalog("__proto__"), null); |
| 25 | + assert.equal(resolveCatalog("toString"), null); |
| 26 | + assert.equal(resolveCatalog(""), null); |
| 27 | + assert.equal(resolveCatalog(undefined), null); |
| 28 | +}); |
| 29 | + |
| 30 | +test("resolveCatalog copies args so a caller cannot mutate the catalog", () => { |
| 31 | + const first = resolveCatalog("porkbun"); |
| 32 | + first.args.push("--rogue"); |
| 33 | + assert.deepEqual(resolveCatalog("porkbun").args, ["-y", "@porkbunllc/mcp-server"]); |
| 34 | + assert.deepEqual(MCP_CATALOG.porkbun.args, ["-y", "@porkbunllc/mcp-server"]); |
| 35 | +}); |
| 36 | + |
| 37 | +test("`mcp add porkbun` expands to the full spec", () => { |
| 38 | + const { spec, catalog, error } = parseMcp(["add", "porkbun"]); |
| 39 | + assert.equal(error, undefined); |
| 40 | + assert.equal(spec.name, "porkbun"); |
| 41 | + assert.equal(spec.target, "npx"); |
| 42 | + assert.deepEqual(spec.args, ["-y", "@porkbunllc/mcp-server"]); |
| 43 | + assert.equal(catalog.key, "porkbun"); |
| 44 | +}); |
| 45 | + |
| 46 | +test("an explicit command always beats the catalog", () => { |
| 47 | + // Someone running a fork or a local build must get exactly what they typed. |
| 48 | + const { spec } = parseMcp(["add", "porkbun", "--", "node", "./my-fork.js"]); |
| 49 | + assert.equal(spec.name, "porkbun"); |
| 50 | + assert.equal(spec.target, "node"); |
| 51 | + assert.deepEqual(spec.args, ["./my-fork.js"]); |
| 52 | +}); |
| 53 | + |
| 54 | +test("an unknown bare name still errors rather than guessing", () => { |
| 55 | + const { error } = parseMcp(["add", "not-a-known-server"]); |
| 56 | + assert.match(error, /missing server URL or command/); |
| 57 | +}); |
| 58 | + |
| 59 | +test("catalog expansion does not disturb ordinary registrations", () => { |
| 60 | + const { spec, catalog } = parseMcp(["add", "sentry", "https://mcp.sentry.dev/mcp"]); |
| 61 | + assert.equal(spec.name, "sentry"); |
| 62 | + assert.equal(spec.target, "https://mcp.sentry.dev/mcp"); |
| 63 | + assert.equal(catalog, undefined, "a normal add is not a catalog hit"); |
| 64 | +}); |
| 65 | + |
| 66 | +test("credentials are never written into the spec", () => { |
| 67 | + // The env the server *needs* is documented on the catalog entry; the spec |
| 68 | + // that gets registered with each engine must stay empty of it. |
| 69 | + const { spec, catalog } = parseMcp(["add", "porkbun"]); |
| 70 | + assert.deepEqual(spec.env, [], "an API key must not be baked into engine config"); |
| 71 | + assert.ok(catalog.env.includes("PORKBUN_API_KEY")); |
| 72 | +}); |
| 73 | + |
| 74 | +test("`mcp catalog` is its own verb, and unknown verbs mention it", () => { |
| 75 | + assert.deepEqual(parseMcp(["catalog"]), { showCatalog: true }); |
| 76 | + assert.match(parseMcp(["bogus"]).error, /install, add, catalog, or list/); |
| 77 | +}); |
| 78 | + |
| 79 | +test("the catalog listing names every entry", () => { |
| 80 | + const listing = catalogList(); |
| 81 | + for (const name of catalogNames()) assert.match(listing, new RegExp(name)); |
| 82 | + assert.match(listing, /Porkbun/); |
| 83 | +}); |
0 commit comments