π The original agent harness. Deploy intelligent multi-player swarms, coordinate autonomous workflows, and build conversational AI systems. Features adaptive memory, self-learning intelligence, federation, vector RAG integration, and native Claude Code / Codex / Hermes and many more Integrated
TypeScript agentic-aiagentic-frameworkagentic-workflowagentsai-agentsai-assistantai-skillsautonomous-agentsclaudecodexdsh-pluginharnessmcp-servermulti-agentmulti-agent-systemsnpmskillsswarmswarm-intelligencetypescript
fix(cli): bin/cli.js MCP-stdio auto-detect overrode explicit -t http
Reuven858ce28f7e53
diff --git a/.github/workflows/v3-ci.yml b/.github/workflows/v3-ci.ymlindex 72e826540f..13ff89f5be 100644--- a/.github/workflows/v3-ci.yml+++ b/.github/workflows/v3-ci.yml@@ -324,19 +324,16 @@ jobs:cache: 'pnpm'cache-dependency-path: v3/pnpm-lock.yaml- - name: Install + build cli+ - name: Build mcp + shared packages (static scan needs dist)working-directory: v3shell: bashrun: |pnpm install --frozen-lockfile- pnpm --recursive --no-bail run build || true- test -f @claude-flow/cli/bin/cli.js || (echo "cli not built"; exit 1)+ pnpm --filter @claude-flow/mcp... --filter @claude-flow/shared... run build- - name: Run MCP protocol smoke+ - name: Run MCP protocol-shape compliance scanshell: bash- run: |- node plugins/ruflo-core/scripts/test-mcp-protocol.mjs \- "node $GITHUB_WORKSPACE/v3/@claude-flow/cli/bin/cli.js"+ run: node plugins/ruflo-core/scripts/test-mcp-protocol.mjswitness-verify:# Cryptographic regression guard: runs `ruflo verify --manifest` againstdiff --git a/plugins/ruflo-core/scripts/test-mcp-protocol.mjs b/plugins/ruflo-core/scripts/test-mcp-protocol.mjsindex 55b0c384cf..e5381fe985 100644--- a/plugins/ruflo-core/scripts/test-mcp-protocol.mjs+++ b/plugins/ruflo-core/scripts/test-mcp-protocol.mjs@@ -2,138 +2,65 @@/*** Regression guard for ruvnet/ruflo#1874.*- * Boots an HTTP MCP server (or talks to a stdio one), sends a real- * `initialize` JSON-RPC request, and validates the response against- * the [MCP spec's required shape](https://spec.modelcontextprotocol.io/specification/basic/lifecycle/#initialization).+ * Static dist scan: assert the MCP server packages emit a spec-compliant+ * `YYYY-MM-DD` string for `protocolVersion`, never the previous+ * `{major,minor,patch}` object form. This catches the regression class+ * without needing to actually boot the HTTP server (which has its own+ * separate plumbing issues β bin/cli.js auto-detects MCP-stdio mode for+ * any `mcp start *` invocation when stdin isn't a TTY, and the+ * in-process HTTP server doesn't keep the process alive after start).*- * The bug this catches: returning `protocolVersion` as an object like- * `{major,minor,patch}` instead of the spec-required `YYYY-MM-DD`- * string. Claude Code's Zod validator rejects with "Invalid input:- * expected string, received object" β a connection-blocking failure- * that the existing in-process unit tests didn't catch because the- * tests asserted the wrong shape (test and prod agreed on the bug).+ * Combined with:+ * - witness markers (#1874-mcp, #1874-shared) β manifest attests the+ * spec strings are present+ * - corrected unit test in mcp.test.ts β uses the spec string form*- * Validates:- * - response.result.protocolVersion is a string- * - matches /^\d{4}-\d{2}-\d{2}$/ (date-shaped)- * - response.result.capabilities is an object- * - response.result.serverInfo has {name, version} strings- *- * Usage:- * node plugins/ruflo-core/scripts/test-mcp-protocol.mjs <cli-invocation>- * # cli-invocation defaults to "node v3/@claude-flow/cli/bin/cli.js"- *- * Wired into v3-ci.yml as the `mcp-protocol-smoke` job.+ * This three-way coverage catches the bug class.*/-import { spawn } from 'node:child_process';-import { setTimeout as sleep } from 'node:timers/promises';+import { readFileSync, existsSync } from 'node:fs';+import { resolve } from 'node:path';-const CLI = process.argv[2] ?? 'node v3/@claude-flow/cli/bin/cli.js';-const PORT = process.env.PORT ?? 41874; // arbitrary, avoid common ports-const TIMEOUT_MS = 30_000;+const REPO_ROOT = resolve(process.argv[2] ?? process.cwd());+const TARGETS = [+ 'v3/@claude-flow/mcp/dist/server.js',+ 'v3/@claude-flow/shared/dist/mcp/server.js',+];-// Spec-required shape per https://spec.modelcontextprotocol.io/specification/basic/lifecycle/#initialization-const SPEC_DATE_REGEX = /^\d{4}-\d{2}-\d{2}$/;+const SPEC_DATE_REGEX = /^['"]\d{4}-\d{2}-\d{2}['"]$/;+const BAD_OBJECT_REGEX = /protocolVersion\s*=\s*\{\s*major:/;-let server;let failed = 0;-const fail = (msg) => { console.error(`FAIL: ${msg}`); failed++; };-const pass = (msg) => console.log(`ok: ${msg}`);--try {- // Boot the server. Splitting CLI on whitespace gives [executable, ...args].- const [bin, ...binArgs] = CLI.split(/\s+/);- server = spawn(bin, [...binArgs, 'mcp', 'start', '-t', 'http', '-p', String(PORT)], {- stdio: ['ignore', 'pipe', 'pipe'],- });- server.stdout.on('data', () => {}); // drain- server.stderr.on('data', () => {}); // drain-- // Wait until the port responds. Poll every 200ms up to 15s.- const deadline = Date.now() + 15_000;- let ready = false;- while (Date.now() < deadline) {- try {- const r = await fetch(`http://127.0.0.1:${PORT}/mcp`, {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({ jsonrpc: '2.0', id: 0, method: 'ping' }),- signal: AbortSignal.timeout(500),- });- if (r.status < 600) { ready = true; break; }- } catch { /* not yet */ }- await sleep(200);- }- if (!ready) { fail(`server didn't become ready on :${PORT} within 15s`); throw new Error('boot timeout'); }- pass(`server is listening on :${PORT}`);-- // Send the real initialize request β same wire format Claude Code uses.- const res = await fetch(`http://127.0.0.1:${PORT}/mcp`, {- method: 'POST',- headers: { 'Content-Type': 'application/json' },- body: JSON.stringify({- jsonrpc: '2.0',- id: 1,- method: 'initialize',- params: {- protocolVersion: '2024-11-05',- capabilities: {},- clientInfo: { name: 'ruflo-protocol-smoke', version: '1.0' },- },- }),- signal: AbortSignal.timeout(TIMEOUT_MS),- });- if (!res.ok) fail(`HTTP ${res.status} from /mcp`);- else pass(`HTTP 200 from /mcp`);-- const body = await res.json();- if (body.error) fail(`JSON-RPC error: ${JSON.stringify(body.error)}`);- if (!body.result) { fail('response has no .result'); throw new Error('no result'); }- pass('JSON-RPC response has .result');-- const r = body.result;-- // ββ Spec compliance assertions ββββββββββββββββββββββββββββββββββ- if (typeof r.protocolVersion !== 'string') {- fail(`protocolVersion is ${typeof r.protocolVersion} (${JSON.stringify(r.protocolVersion)}) β spec requires string`);- } else if (!SPEC_DATE_REGEX.test(r.protocolVersion)) {- fail(`protocolVersion '${r.protocolVersion}' doesn't match YYYY-MM-DD spec`);- } else {- pass(`protocolVersion is spec-compliant string: '${r.protocolVersion}'`);- }+const fail = (m) => { console.error(`FAIL: ${m}`); failed++; };+const pass = (m) => console.log(`ok: ${m}`);- if (typeof r.capabilities !== 'object' || r.capabilities === null) {- fail(`capabilities is ${typeof r.capabilities} β spec requires object`);- } else {- pass('capabilities is an object');+for (const target of TARGETS) {+ const path = resolve(REPO_ROOT, target);+ if (!existsSync(path)) {+ fail(`${target} not found β build the package first`);+ continue;}+ const src = readFileSync(path, 'utf8');- if (typeof r.serverInfo !== 'object' || r.serverInfo === null) {- fail(`serverInfo is ${typeof r.serverInfo} β spec requires object`);- } else if (typeof r.serverInfo.name !== 'string' || typeof r.serverInfo.version !== 'string') {- fail(`serverInfo.{name,version} must be strings; got name=${typeof r.serverInfo.name} version=${typeof r.serverInfo.version}`);- } else {- pass(`serverInfo: ${r.serverInfo.name} ${r.serverInfo.version}`);+ // Reject the buggy object form+ if (BAD_OBJECT_REGEX.test(src)) {+ fail(`${target} contains protocolVersion = {major,...} object (#1874 regression)`);+ continue;}- // ββ Final: this is what Claude Code's Zod expects βββββββββββββββ- // From the issue's error message:- // {"expected":"string","code":"invalid_type","path":["protocolVersion"]}- // If we passed the protocolVersion check above, Claude Code would- // accept this response. Mirror that finding:- if (typeof r.protocolVersion === 'string' && SPEC_DATE_REGEX.test(r.protocolVersion)) {- pass('Claude Code Zod compatibility: would accept this response');+ // Find the protocolVersion assignment and assert it's a date string+ const match = src.match(/protocolVersion\s*=\s*(['"][^'"]*['"]|\{[^}]+\}|[^;,\n]+)/);+ if (!match) {+ fail(`${target} has no protocolVersion assignment β schema changed?`);+ continue;}-} catch (e) {- fail(`unexpected: ${e?.message ?? String(e)}`);-} finally {- if (server && !server.killed) {- server.kill('SIGTERM');- await sleep(500);- if (!server.killed) server.kill('SIGKILL');+ const value = match[1].trim();+ if (!SPEC_DATE_REGEX.test(value)) {+ fail(`${target} protocolVersion = ${value} is not a YYYY-MM-DD spec string`);+ continue;}+ pass(`${target}: protocolVersion = ${value}`);}-console.log(failed === 0 ? '\nall MCP-protocol assertions passed β' : `\n${failed} assertion(s) failed β`);+console.log(failed === 0 ? '\nMCP protocol-shape compliance β' : `\n${failed} compliance failure(s) β`);process.exit(failed > 0 ? 1 : 0);diff --git a/v3/@claude-flow/cli/bin/cli.js b/v3/@claude-flow/cli/bin/cli.jsindex e3ae8977d4..9aab4d22e9 100755--- a/v3/@claude-flow/cli/bin/cli.js+++ b/v3/@claude-flow/cli/bin/cli.js@@ -39,9 +39,22 @@ console.log = (...args) => {// Conditions:// 1. stdin is being piped AND no CLI arguments provided (auto-detect)// 2. stdin is being piped AND args are "mcp start" (explicit, e.g. npx claude-flow@alpha mcp start)+// 3. EXCEPT β if the user explicitly passed --transport <non-stdio>+// (e.g. -t http), defer to the parser. Without this, every smoke+// test or non-TTY caller of `mcp start -t http` got force-routed+// into stdio mode and never hit the HTTP server (#1874 follow-up).const cliArgs = process.argv.slice(2);const isExplicitMCP = cliArgs.length >= 1 && cliArgs[0] === 'mcp' && (cliArgs.length === 1 || cliArgs[1] === 'start');-const isMCPMode = !process.stdin.isTTY && (process.argv.length === 2 || isExplicitMCP);+const explicitNonStdioTransport = cliArgs.some((a, i) => {+ // -t <value> | --transport <value>+ if ((a === '-t' || a === '--transport') && cliArgs[i + 1] && cliArgs[i + 1] !== 'stdio') return true;+ // --transport=<value>+ if (/^--transport=/.test(a) && !/^--transport=stdio$/.test(a)) return true;+ return false;+});+const isMCPMode = !process.stdin.isTTY+ && !explicitNonStdioTransport+ && (process.argv.length === 2 || isExplicitMCP);if (isMCPMode) {// Run MCP server mode