|
| 1 | +/** |
| 2 | + * Guard for the registry-format launch argument. |
| 3 | + * |
| 4 | + * The MCP registry entry (and the website's `/.well-known/mcp.json` discovery manifest) tell a |
| 5 | + * launcher how to start the server: the npm package, the stdio transport, and |
| 6 | + * `packageArguments`. Without the fixed `mcp` positional argument, a client that honors the |
| 7 | + * manifest runs `agent-device` with no subcommand — the bare CLI — instead of the stdio MCP |
| 8 | + * server (`src/bin.ts` only starts the server for the `mcp` subcommand). |
| 9 | + * |
| 10 | + * `check:mcp-metadata` compares the file against a regeneration, which proves the corrected file |
| 11 | + * is self-consistent; this test owns the invariant directly against the checked-in file and fails |
| 12 | + * in both directions — a missing argument and a wrong one. |
| 13 | + */ |
| 14 | +import assert from 'node:assert/strict'; |
| 15 | +import { readFile } from 'node:fs/promises'; |
| 16 | +import { join } from 'node:path'; |
| 17 | +import { test } from 'vitest'; |
| 18 | + |
| 19 | +const ROOT = join(import.meta.dirname, '..', '..'); |
| 20 | + |
| 21 | +const EXPECTED_MCP_PACKAGE_ARGUMENTS = [{ type: 'positional', value: 'mcp' }]; |
| 22 | + |
| 23 | +type ServerPackage = { |
| 24 | + registryType?: string; |
| 25 | + identifier?: string; |
| 26 | + transport?: { type?: string }; |
| 27 | + packageArguments?: unknown; |
| 28 | +}; |
| 29 | + |
| 30 | +test('the published registry entry starts the MCP server, not the bare CLI', async () => { |
| 31 | + const pkg = JSON.parse(await readFile(join(ROOT, 'package.json'), 'utf8')) as { |
| 32 | + name: string; |
| 33 | + }; |
| 34 | + const server = JSON.parse(await readFile(join(ROOT, 'server.json'), 'utf8')) as { |
| 35 | + packages?: ServerPackage[]; |
| 36 | + }; |
| 37 | + |
| 38 | + const entry = (server.packages ?? []).find((candidate) => candidate.identifier === pkg.name); |
| 39 | + assert.ok(entry, `server.json must describe the ${pkg.name} npm package`); |
| 40 | + assert.equal(entry.registryType, 'npm'); |
| 41 | + assert.deepEqual(entry.transport, { type: 'stdio' }); |
| 42 | + |
| 43 | + assert.deepEqual( |
| 44 | + entry.packageArguments, |
| 45 | + EXPECTED_MCP_PACKAGE_ARGUMENTS, |
| 46 | + 'registry-format launchers must start the stdio MCP server; without the fixed mcp subcommand they run the bare CLI', |
| 47 | + ); |
| 48 | +}); |
0 commit comments