Skip to content

YC (S26) | Open Computer History | Continuously record your company computer work, map your workflows, help you find work worth automating, and power your agents' context

test(evals): verify MCP package transport dispatch

Louis Beaumontd86a02341023
diff --git a/evals/coding-agent/README.md b/evals/coding-agent/README.md
index 7fa9dc4cf..98c13d544 100644
--- a/evals/coding-agent/README.md
+++ b/evals/coding-agent/README.md
@@ -1877,3 +1877,11 @@ This does not execute the packaged engine, TTY password handling, online HTTP
routes, migration/daemon integration, crash recovery or production recordings.
Current daemon and hybrid-storage refusal policies are separate contracts, not
historical online-lock-success expectations. No model trial or isolation claim.
+
+The `app-mcp-package-http-dispatch` case compiles historical package sources and
+launches their declared bins. Seven public outcomes cover HTTP dispatch, flag
+ordering, stdio preservation, the direct HTTP alias and invalid HTTP startup
+refusal. Grading uses synthetic loopback requests, an empty home and disabled
+telemetry; it does not install from npm or call upstream tools. Compilation and
+unresponsive startup stop collection as setup errors. Calibrate with
+`bun test evals/coding-agent/calibrate-mcp-package-dispatch.test.js`.
diff --git a/evals/coding-agent/calibrate-mcp-package-dispatch.test.js b/evals/coding-agent/calibrate-mcp-package-dispatch.test.js
new file mode 100644
index 000000000..f8ee43279
--- /dev/null
+++ b/evals/coding-agent/calibrate-mcp-package-dispatch.test.js
@@ -0,0 +1,41 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import { afterAll, expect, test } from 'bun:test';
+import { execFileSync, spawnSync } from 'node:child_process';
+import { mkdtempSync, mkdirSync, readFileSync, writeFileSync, symlinkSync, rmSync, renameSync } from 'node:fs';
+import { resolve, join } from 'node:path';
+import { tmpdir } from 'node:os';
+import { classifyGraderError } from './grader-outcome.mjs';
+const repo = resolve(import.meta.dir, '../..');
+const item = JSON.parse(readFileSync(join(import.meta.dir, 'cases.json'))).cases.find(c => c.id === 'app-mcp-package-http-dispatch');
+const root = mkdtempSync(join(tmpdir(), 'mcp-dispatch-calibration-'));
+afterAll(() => rmSync(root, { recursive: true, force: true }));
+function grade(name, ref, mutate = () => {}) {
+ const cwd = join(root, name); mkdirSync(cwd);
+ execFileSync('tar', ['-xf', '-', '-C', cwd], { input: execFileSync('git', ['archive', ref, 'packages/screenpipe-mcp'], { cwd: repo, maxBuffer: 24 * 1024 * 1024 }) });
+ const pkg = join(cwd, 'packages/screenpipe-mcp');
+ symlinkSync(join(repo, 'packages/screenpipe-mcp/node_modules'), join(pkg, 'node_modules'), 'dir');
+ writeFileSync(join(pkg, 'src/eval-package-dispatch.test.js'), readFileSync(join(import.meta.dir, 'graders/mcp-package-dispatch.fixture.js.txt')));
+ mutate(pkg);
+ const r = spawnSync(process.execPath, ['test', 'src/eval-package-dispatch.test.js'], { cwd: pkg, encoding: 'utf8', timeout: 90000, maxBuffer: 4 * 1024 * 1024, env: { PATH: process.env.PATH, CI: 'true', TZ: 'UTC' } });
+ if (process.env.MCP_DISPATCH_CALIBRATION_RESULTS) {
+ mkdirSync(process.env.MCP_DISPATCH_CALIBRATION_RESULTS, { recursive: true });
+ writeFileSync(join(process.env.MCP_DISPATCH_CALIBRATION_RESULTS, name + '.json'), JSON.stringify({ status: r.status, signal: r.signal, error: r.error?.message ?? null, stdout: r.stdout, stderr: r.stderr, classification: classifyGraderError(r) }, null, 2) + '\n');
+ }
+ return r;
+}
+function pass(r) { expect(r.error).toBeUndefined(); expect(r.signal).toBeNull(); expect(r.status, r.stdout + r.stderr).toBe(0); expect(r.stderr).toContain('7 pass'); }
+function fail(r) { expect(r.error).toBeUndefined(); expect(r.signal).toBeNull(); expect(r.status).toBe(1); expect(classifyGraderError(r)).toBeNull(); expect(r.stderr).toContain('expect(received)'); }
+function edit(pkg, file, from, to) { const p = join(pkg, file), s = readFileSync(p, 'utf8'); expect(s.split(from)).toHaveLength(2); writeFileSync(p, s.replace(from, to)); }
+function manifest(pkg, mutate) { const p = join(pkg, 'package.json'), m = JSON.parse(readFileSync(p)); mutate(m); writeFileSync(p, JSON.stringify(m)); }
+test('broken package responds on wrong transport; three preserved outcomes', () => { const r = grade('parent', item.base_ref); fail(r); expect(r.stderr).toContain('4 fail'); expect(r.stderr).toContain('3 pass'); });
+test('historical package fix passes', () => pass(grade('reference', item.oracle_ref)));
+test('current source passes', () => pass(grade('current', 'HEAD')));
+test('unused correct dispatch file cannot fix package bin', () => fail(grade('unused', item.oracle_ref, p => manifest(p, m => { m.bin['screenpipe-mcp'] = 'dist/index.js'; }))));
+test('equivalent renamed dispatch module passes', () => pass(grade('equivalent', item.oracle_ref, p => { renameSync(join(p, 'src/cli.ts'), join(p, 'src/entry.ts')); manifest(p, m => { m.bin['screenpipe-mcp'] = 'dist/entry.js'; }); })));
+test('always HTTP fails preserved stdio', () => fail(grade('always-http', item.oracle_ref, p => edit(p, 'src/cli.ts', 'argv.includes("--http")', 'true'))));
+test('similar flag must not enable HTTP', () => fail(grade('substring', item.oracle_ref, p => edit(p, 'src/cli.ts', 'argv.includes("--http")', 'argv.some(a => a.startsWith("--http"))'))));
+test('direct alias must remain HTTP', () => fail(grade('alias-stdio', item.oracle_ref, p => manifest(p, m => { m.bin['screenpipe-mcp-http'] = 'dist/index.js'; }))));
+test('no-op package scripts cannot hide wrong entry point', () => fail(grade('noop-broken', item.base_ref, p => manifest(p, m => { m.scripts.build = 'exit 0'; m.scripts.test = 'exit 0'; }))));
+test('missing dispatch module is setup error', () => { const r = grade('missing', item.oracle_ref, p => rmSync(join(p, 'src/cli.ts'))); expect(r.status).toBe(1); expect(classifyGraderError(r)).toBe('bun_unhandled_error'); expect(r.stderr).toContain('0 pass'); });
+test('compilation failure is setup error', () => { const r = grade('compile-error', item.oracle_ref, p => writeFileSync(join(p, 'src/cli.ts'), 'export const broken = ;\n')); expect(r.status).toBe(1); expect(classifyGraderError(r)).toBe('bun_unhandled_error'); expect(r.stderr).toContain('0 pass'); });
diff --git a/evals/coding-agent/cases.json b/evals/coding-agent/cases.json
index 2411b9a59..3f8b68ab8 100644
--- a/evals/coding-agent/cases.json
+++ b/evals/coding-agent/cases.json
@@ -6172,6 +6172,52 @@
],
"command": "bun --no-env-file vault-cli.eval.js"
}
+ },
+ {
+ "id": "app-mcp-package-http-dispatch",
+ "name": "Dispatch the published package HTTP flag while preserving stdio",
+ "source": {
+ "kind": "git_regression",
+ "fix_commit": "2c687b0b530623c750fdafda7bcc8985ee755a87"
+ },
+ "base_ref": "e4341ef7c9bc4ade2dfb5ea3bcb6a149bae28146",
+ "oracle_ref": "2c687b0b530623c750fdafda7bcc8985ee755a87",
+ "oracle_paths": [
+ "packages/screenpipe-mcp/package.json",
+ "packages/screenpipe-mcp/src/cli.ts",
+ "packages/screenpipe-mcp/src/http-server.ts"
+ ],
+ "gate": "advisory",
+ "trigger_paths": [
+ "packages/screenpipe-mcp/package.json",
+ "packages/screenpipe-mcp/src/cli.ts",
+ "packages/screenpipe-mcp/src/index.ts",
+ "packages/screenpipe-mcp/src/http-server.ts"
+ ],
+ "tags": [
+ "regression",
+ "mcp",
+ "cli",
+ "transport"
+ ],
+ "prompt": "Invoking the screenpipe-mcp package with --http still starts its stdio transport. Repair the package entry point. After compiling its TypeScript, launching the screenpipe-mcp bin declared in package.json with --http either before or after --port must open HTTP on that requested loopback port. Preserve the separate screenpipe-mcp-http bin without requiring --http. Both HTTP entry points must return unauthenticated /health with status ok and zero initial sessions, HTTP 404 for unknown routes, and a successful MCP initialize response advertising tools. Without --http, including the unrelated --httpish flag, the primary bin must preserve newline JSON-RPC stdio initialization and tools/list containing search-content. HTTP requests with --port 0 or --listen-on-lan without --api-key must refuse startup with exit 2 and a diagnostic. Use synthetic loopback probes only, disable telemetry and supply a synthetic local API key with an empty home. No particular dispatch helper or source filename is required. This task covers compiled package bins, not registry installation, packaged installers, external API calls, HTTP session reuse, authorized LAN serving or deployed recordings.",
+ "agent_timeout_seconds": 900,
+ "grader_dependency_links": [
+ {
+ "source_path": "packages/screenpipe-mcp/node_modules",
+ "destination_path": "packages/screenpipe-mcp/node_modules"
+ }
+ ],
+ "grader": {
+ "timeout_seconds": 90,
+ "fixtures": [
+ {
+ "local_path": "graders/mcp-package-dispatch.fixture.js.txt",
+ "destination_path": "packages/screenpipe-mcp/src/eval-package-dispatch.test.js"
+ }
+ ],
+ "command": "cd packages/screenpipe-mcp && bun test src/eval-package-dispatch.test.js"
+ }
}
]
}
diff --git a/evals/coding-agent/graders/mcp-package-dispatch.fixture.js.txt b/evals/coding-agent/graders/mcp-package-dispatch.fixture.js.txt
new file mode 100644
index 000000000..9439f6eaa
--- /dev/null
+++ b/evals/coding-agent/graders/mcp-package-dispatch.fixture.js.txt
@@ -0,0 +1,102 @@
+// screenpipe — AI that knows everything you've seen, said, or heard
+// https://screenpipe.com
+import { test, expect } from 'bun:test';
+import { spawn, execFileSync } from 'node:child_process';
+import { readFileSync, mkdtempSync, rmSync } from 'node:fs';
+import { resolve, join } from 'node:path';
+import { tmpdir } from 'node:os';
+import { createServer } from 'node:net';
+
+// Build and collect observations before registering assertions. Compilation,
+// missing binaries and unresponsive processes remain Bun setup errors.
+const pkg = JSON.parse(readFileSync('package.json', 'utf8'));
+execFileSync(process.env.NODE_BIN || 'node', ['node_modules/typescript/bin/tsc'], { timeout: 30000, stdio: 'pipe' });
+const initialize = { jsonrpc: '2.0', id: 1, method: 'initialize', params: {
+ protocolVersion: '2024-11-05', capabilities: {}, clientInfo: { name: 'synthetic-dispatch-eval', version: '1' },
+}};
+const contracts = [
+ ['HTTP flag before options', 'screenpipe-mcp', ['--http'], 'http'],
+ ['HTTP flag after options', 'screenpipe-mcp', [], 'http'],
+ ['default stdio', 'screenpipe-mcp', [], 'stdio'],
+ ['similar flag preserves stdio', 'screenpipe-mcp', ['--httpish'], 'stdio'],
+ ['direct HTTP alias', 'screenpipe-mcp-http', [], 'http'],
+ ['invalid HTTP port refuses startup', 'screenpipe-mcp', ['--http', '--port', '0'], 'rejected'],
+ ['LAN without key refuses startup', 'screenpipe-mcp', ['--http', '--listen-on-lan'], 'rejected'],
+];
+const delay = ms => new Promise(r => setTimeout(r, ms));
+async function freePort() {
+ const s = createServer(); await new Promise((r, reject) => { s.once('error', reject); s.listen(0, '127.0.0.1', r); });
+ const p = s.address().port; await new Promise(r => s.close(r)); return p;
+}
+function decode(text) {
+ for (const line of text.split('\n')) { try { const v = JSON.parse(line.replace(/^data:\s*/, '')); if (v && typeof v === 'object') return v; } catch {} }
+}
+function rpcLines(text) { return text.split('\n').map(decode).filter(Boolean); }
+async function observe(name, alias, options) {
+ const port = await freePort(), home = mkdtempSync(join(tmpdir(), 'mcp-dispatch-home-'));
+ const args = name === 'HTTP flag after options' ? ['--port', String(port), '--http'] :
+ name === 'invalid HTTP port refuses startup' ? options : [...options, '--port', String(port)];
+ if (!pkg.bin?.[alias]) throw new Error(`Package bin missing: ${alias}`);
+ const child = spawn(process.env.NODE_BIN || 'node', [resolve(pkg.bin[alias]), ...args], {
+ env: { PATH: process.env.PATH, HOME: home, SCREENPIPE_LOCAL_API_KEY: 'sp-synthetic-eval-only',
+ SCREENPIPE_DISABLE_TELEMETRY: '1', SCREENPIPE_MCP_SENTRY_DISABLED: '1', SENTRY_DISABLED: '1', DO_NOT_TRACK: '1' },
+ stdio: ['pipe', 'pipe', 'pipe'],
+ });
+ let stdout = '', stderr = '', spawnError;
+ child.on('error', e => { spawnError = e; }); child.stdin.on('error', () => {});
+ child.stdout.on('data', b => { stdout += b; }); child.stderr.on('data', b => { stderr += b; });
+ const closed = new Promise(r => child.once('close', r));
+ child.stdin.write(JSON.stringify(initialize) + '\n');
+ const base = `http://127.0.0.1:${port}`;
+ try {
+ const end = Date.now() + 5000;
+ while (Date.now() < end) {
+ if (spawnError) throw spawnError;
+ const stdio = rpcLines(stdout).find(v => v.id === 1);
+ if (stdio) {
+ if (!stdio.result) throw new Error(`Stdio setup failed: ${JSON.stringify(stdio)}`);
+ child.stdin.write(JSON.stringify({ jsonrpc: '2.0', method: 'notifications/initialized' }) + '\n' +
+ JSON.stringify({ jsonrpc: '2.0', id: 2, method: 'tools/list' }) + '\n');
+ const listEnd = Date.now() + 2000;
+ while (Date.now() < listEnd) {
+ const list = rpcLines(stdout).find(v => v.id === 2);
+ if (list) return { transport: 'stdio', initialize: stdio, tools: list.result?.tools ?? [] };
+ await delay(20);
+ }
+ throw new Error('Stdio list response unavailable during setup');
+ }
+ if (child.exitCode !== null) {
+ if (child.exitCode === 2 && stderr.trim()) return { transport: 'rejected', code: 2, stderr };
+ throw new Error(`Package startup failed (${child.exitCode}): ${stderr}`);
+ }
+ let health;
+ try { const r = await fetch(base + '/health', { signal: AbortSignal.timeout(150) }); if (r.status === 200) health = await r.json(); } catch {}
+ if (health) {
+ const unknown = await fetch(base + '/not-a-route', { signal: AbortSignal.timeout(2000) }); await unknown.text();
+ const response = await fetch(base + '/mcp', { method: 'POST', headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream' }, body: JSON.stringify(initialize), signal: AbortSignal.timeout(2000) });
+ return { transport: 'http', health, unknownStatus: unknown.status, status: response.status, initialize: decode(await response.text()) };
+ }
+ await delay(20);
+ }
+ throw new Error(`Package setup produced no responsive transport: ${stderr}`);
+ } finally {
+ if (child.exitCode === null) child.kill('SIGTERM');
+ await Promise.race([closed, delay(1000)]);
+ if (child.exitCode === null && child.signalCode === null) { child.kill('SIGKILL'); await closed; }
+ rmSync(home, { recursive: true, force: true });
+ }
+}
+const observations = [];
+for (const [name, alias, options, expected] of contracts) observations.push({ name, expected, observed: await observe(name, alias, options) });
+for (const { name, expected, observed } of observations) test(name, () => {
+ expect(observed.transport).toBe(expected);
+ if (expected === 'http') {
+ expect(observed.health).toEqual({ status: 'ok', sessions: 0 });
+ expect(observed.unknownStatus).toBe(404);
+ expect(observed.status).toBe(200);
+ expect(observed.initialize?.result?.capabilities).toHaveProperty('tools');
+ } else if (expected === 'stdio') {
+ expect(observed.initialize.result.capabilities).toHaveProperty('tools');
+ expect(observed.tools.some(t => t.name === 'search-content')).toBe(true);
+ } else { expect(observed.code).toBe(2); expect(observed.stderr.trim().length).toBeGreaterThan(0); }
+});