🌊 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(x-gateway): argument-less tools/call, bare-host POST, reject diagnostics (0.9.1) (#4468)
rUv979cce0ab5a4
diff --git a/plugins/ruflo-x-gateway/.claude-plugin/plugin.json b/plugins/ruflo-x-gateway/.claude-plugin/plugin.jsonindex b68770286b..5fe84efcdf 100644--- a/plugins/ruflo-x-gateway/.claude-plugin/plugin.json+++ b/plugins/ruflo-x-gateway/.claude-plugin/plugin.json@@ -1,7 +1,7 @@{"name": "ruflo-x-gateway","description": "Coordinate AI-agent swarms through signed federation messages, channels, and work claims. The remote Claude connector exposes a directory-safe Streamable HTTP MCP surface with OAuth-protected publishing and five ruv:// reference resources.",- "version": "0.10.1",+ "version": "0.10.2","author": {"name": "ruvnet","url": "https://github.com/ruvnet"diff --git a/plugins/ruflo-x-gateway/CHANGELOG.md b/plugins/ruflo-x-gateway/CHANGELOG.mdindex f39a277f9c..d561f2987a 100644--- a/plugins/ruflo-x-gateway/CHANGELOG.md+++ b/plugins/ruflo-x-gateway/CHANGELOG.md@@ -2,6 +2,11 @@Newest first. One `## <version> — <date>` heading per version, then `feat:`, `fix:`, `breaking:` and `chore:` bullets (ADR-478). Built from git history; older versions: `git log -- plugins/ruflo-x-gateway`.+## 0.10.2 — 2026-10-24+- fix: a `tools/call` without an `arguments` field (allowed by MCP, and what clients send for tools that take none) failed with `-32602 expected object, received undefined` on every path; an absent or null `arguments` is now treated as `{}` (gateway 0.9.1)+- fix: `POST /` on the bare host now serves the directory-safe profile instead of a 404, so a connector added as `https://x.ruv.io` (no path) works; its OAuth challenge points at the root metadata+- chore: the gateway log now records why a bearer was denied (`why=`) and one `mcp-reject` line per 4xx/5xx MCP response (path, status, JSON-RPC method, protocol-version header, client name); no body or token is logged+## 0.10.1 — 2026-10-12- fix: the shared text screen now catches `.env` and e-mailed credentials, no longer flags a model's token talk (`--max-tokens`, `/oauth/token`, "token usage"), and no longer flags values that only name where a secret lives (`./service-account.json`, `--set-secrets=NAME=NAME:latest`); every rule stays linear (#4094, thanks @proffesor-for-testing)diff --git a/plugins/ruflo-x-gateway/package-lock.json b/plugins/ruflo-x-gateway/package-lock.jsonindex 569701d7af..cd8cec8b21 100644--- a/plugins/ruflo-x-gateway/package-lock.json+++ b/plugins/ruflo-x-gateway/package-lock.json@@ -1,12 +1,12 @@{"name": "@ruflo/x-gateway",- "version": "0.9.0",+ "version": "0.9.1","lockfileVersion": 3,"requires": true,"packages": {"": {"name": "@ruflo/x-gateway",- "version": "0.9.0",+ "version": "0.9.1","license": "MIT","dependencies": {"@google-cloud/firestore": "^9.2.0",diff --git a/plugins/ruflo-x-gateway/package.json b/plugins/ruflo-x-gateway/package.jsonindex 0069074ad3..03c922b4df 100644--- a/plugins/ruflo-x-gateway/package.json+++ b/plugins/ruflo-x-gateway/package.json@@ -1,6 +1,6 @@{"name": "@ruflo/x-gateway",- "version": "0.9.0",+ "version": "0.9.1","private": true,"type": "module","description": "x.ruv.io gateway — MCP server for ruflo swarm federation + claims over a signed, membership-gated Nostr relay. Exposes /mcp tools and ruv:// resources.",diff --git a/plugins/ruflo-x-gateway/src/server.mjs b/plugins/ruflo-x-gateway/src/server.mjsindex 0e789a1333..ae91bad01b 100644--- a/plugins/ruflo-x-gateway/src/server.mjs+++ b/plugins/ruflo-x-gateway/src/server.mjs@@ -50,6 +50,24 @@ const PUBLIC_PAGES = {// truth; read it rather than keeping a fourth copy in sync by hand.export const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;+/**+ * MCP makes `params.arguments` optional on tools/call, and clients commonly omit it for tools that take+ * none. The SDK validates the missing value against an object schema and answers -32602 ("expected+ * object, received undefined"), so a freshly registered connector failed its first no-argument call.+ * Treat an absent or null `arguments` as `{}`; anything the client did send is left untouched.+ * Handles a JSON-RPC batch too. Mutates in place and returns the message(s).+ */+export function normaliseToolCallArguments(parsed) {+ for (const msg of Array.isArray(parsed) ? parsed : [parsed]) {+ if (msg && typeof msg === 'object' && msg.method === 'tools/call'+ && msg.params && typeof msg.params === 'object' && !Array.isArray(msg.params)+ && (msg.params.arguments === undefined || msg.params.arguments === null)) {+ msg.params.arguments = {};+ }+ }+ return parsed;+}+export function createGateway({ relay, keyFile, port, registration, github: githubOverride } = {}) {const RELAY = relay || process.env.RUFLO_RELAY_URL || 'wss://relay.ruv.io';const HTTP_BASE = RELAY.replace(/^wss:/, 'https:').replace(/^ws:/, 'http:');@@ -489,14 +507,17 @@ export function createGateway({ relay, keyFile, port, registration, github: gith// service-side callers depend on. /chatgpt/mcp and /claude/mcp are isolated// directory-safe profiles: no membership administration and no// secret-bearing input field.- if (url.pathname === '/mcp' || url.pathname === '/chatgpt/mcp' || url.pathname === '/claude/mcp') {- const review = url.pathname === '/chatgpt/mcp' || url.pathname === '/claude/mcp';+ // POST on the bare host: connector UIs are routinely given `https://x.ruv.io` without the /mcp path.+ // Serve the directory-safe profile there instead of a 404 (the 401 challenge points at root metadata).+ const bareHostPost = req.method === 'POST' && url.pathname === '/';+ if (url.pathname === '/mcp' || url.pathname === '/chatgpt/mcp' || url.pathname === '/claude/mcp' || bareHostPost) {+ const review = url.pathname !== '/mcp';if (rateLimited(req)) return res.writeHead(429, { 'content-type': 'application/json' }).end('{"error":"rate limited"}');const auth = await oauthContext(req);try {const sub = auth.subject ? createHash('sha256').update(auth.subject).digest('hex').slice(0, 12) : '-';console.log(`mcp path=${url.pathname} auth=${auth.mode} scopes=${(auth.scopes || []).join('+') || '-'} sub=${sub}`- + (auth.mode === 'denied' ? ` reason=${auth.error} aud=${auth.observedAudience || '-'}` : ''));+ + (auth.mode === 'denied' ? ` reason=${auth.error} aud=${auth.observedAudience || '-'} why="${String(auth.description || '-').replace(/[^A-Za-z0-9 ,.:()_-]/g, '?').slice(0, 160)}"` : ''));} catch { /* diagnostic logging must never break a request */ }if (auth.mode === 'denied') {const { error, description } = auth;@@ -509,6 +530,16 @@ export function createGateway({ relay, keyFile, port, registration, github: gith// Reads remain public. A write attempted through either directory profile must// receive an HTTP challenge, not a model-level 200 error that an OAuth// client cannot use to discover the authorization server.+ normaliseToolCallArguments(parsed);+ const rejectedAs = (res) => res.on('finish', () => {+ if (res.statusCode < 400) return;+ try {+ const m = (x) => String(x ?? '-').replace(/[^A-Za-z0-9/_.:-]/g, '?').slice(0, 64);+ console.log(`mcp-reject path=${url.pathname} status=${res.statusCode} rpc=${m(Array.isArray(parsed) ? 'batch' : parsed?.method)}`+ + ` proto=${m(req.headers['mcp-protocol-version'])} ua=${m(String(req.headers['user-agent'] || '').split(' ')[0])}`);+ } catch { /* diagnostic logging must never break a request */ }+ });+ rejectedAs(res);const calledTool = parsed?.method === 'tools/call' ? parsed?.params?.name : undefined;if (review && auth.mode === 'anonymous' && OAUTH_WRITE_TOOLS.has(calledTool)) {const error = 'invalid_request';diff --git a/plugins/ruflo-x-gateway/test/registration-compat.test.mjs b/plugins/ruflo-x-gateway/test/registration-compat.test.mjsnew file mode 100644index 0000000000..b3342e1da6--- /dev/null+++ b/plugins/ruflo-x-gateway/test/registration-compat.test.mjs@@ -0,0 +1,87 @@+import { test } from 'node:test';+import assert from 'node:assert/strict';+import { createGateway } from '../src/server.mjs';++// Client-compat regressions behind "x.ruv.io/mcp registration problems": what a connector does+// right after it is added must work for the request shapes real clients send.++async function withGateway(fn) {+ const gw = createGateway({ relay: 'ws://127.0.0.1:1', keyFile: '/tmp/gw-compat-test.key' });+ const port = await gw.listen(0);+ try { return await fn(`http://127.0.0.1:${port}`); } finally { gw.server.close(); gw.server.closeAllConnections?.(); }+}++const rpc = (base, path, body, extra = {}) => fetch(base + path, {+ method: 'POST',+ headers: { 'content-type': 'application/json', accept: 'application/json, text/event-stream', ...extra },+ body: JSON.stringify(body),+});+const dataOf = async (res) => JSON.parse((await res.text()).split('\n').find((l) => l.startsWith('data:')).slice(5));++for (const path of ['/mcp', '/claude/mcp', '/chatgpt/mcp']) {+ test(`${path}: tools/call without an "arguments" field is accepted for tools that take none`, async () => {+ await withGateway(async (base) => {+ for (const name of ['federation_identity', 'claims_status', 'federation_onboarding']) {+ const res = await rpc(base, path, { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name } });+ assert.equal(res.status, 200);+ const out = await dataOf(res);+ // Relay-backed tools may legitimately error here (the test relay is unreachable); validation must not.+ assert.doesNotMatch(JSON.stringify(out), /-32602|Input validation|expected object/, `${name} without arguments must not fail validation: ${JSON.stringify(out).slice(0, 200)}`);+ }+ });+ });++ test(`${path}: tools/call with "arguments": null is treated like {}`, async () => {+ await withGateway(async (base) => {+ const res = await rpc(base, path, { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'federation_identity', arguments: null } });+ assert.ok(!(await dataOf(res)).result?.isError);+ });+ });++ test(`${path}: a batch with one argument-less call is normalised too`, async () => {+ await withGateway(async (base) => {+ const res = await rpc(base, path, [+ { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'federation_identity' } },+ { jsonrpc: '2.0', id: 2, method: 'tools/list' },+ ]);+ const body = await res.text();+ assert.doesNotMatch(body, /expected object, received undefined/);+ });+ });+}++test('arguments that are present are never rewritten (a required field still fails)', async () => {+ await withGateway(async (base) => {+ const res = await rpc(base, '/claude/mcp', { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'channel_sync', arguments: {} } });+ assert.match(JSON.stringify(await dataOf(res)), /Required|invalid|channel/i);+ });+});++test('a client that registers the bare host (POST /) reaches the directory-safe MCP profile, not a 404', async () => {+ await withGateway(async (base) => {+ const init = await rpc(base, '/', { jsonrpc: '2.0', id: 1, method: 'initialize',+ params: { protocolVersion: '2025-06-18', capabilities: {}, clientInfo: { name: 't', version: '0' } } });+ assert.equal(init.status, 200);+ assert.equal((await dataOf(init)).result.serverInfo.name, 'ruflo-x-gateway-public');+ const tools = await dataOf(await rpc(base, '/', { jsonrpc: '2.0', id: 2, method: 'tools/list' }));+ const names = tools.result.tools.map((t) => t.name);+ assert.ok(names.includes('federation_identity'));+ assert.ok(!names.includes('federation_admit') && !names.includes('federation_invite_mint'), 'no operator tools on the bare host');+ });+});++test('a write attempted on the bare host gets the OAuth challenge, pointing at root metadata', async () => {+ await withGateway(async (base) => {+ const res = await rpc(base, '/', { jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'federation_publish', arguments: { msgType: 'Status', payload: {} } } });+ assert.equal(res.status, 401);+ assert.match(res.headers.get('www-authenticate'), /resource_metadata="[^"]*\/\.well-known\/oauth-protected-resource"/);+ });+});++test('GET / still returns the service document', async () => {+ await withGateway(async (base) => {+ const res = await fetch(base + '/');+ assert.equal(res.status, 200);+ assert.equal((await res.json()).service, 'ruflo-x-gateway');+ });+});diff --git a/scripts/ci-test-baseline.txt b/scripts/ci-test-baseline.txtindex a80ce5ede8..df22faf772 100644--- a/scripts/ci-test-baseline.txt+++ b/scripts/ci-test-baseline.txt@@ -136,6 +136,7 @@ plugins/ruflo-x-gateway/test/registration.test.mjsplugins/ruflo-x-gateway/test/claude-directory.test.mjsplugins/ruflo-x-gateway/test/github.test.mjsplugins/ruflo-x-gateway/test/relay-robustness.test.mjs+plugins/ruflo-x-gateway/test/registration-compat.test.mjs# ruflo-chatgpt-federation: same pattern — plugin-local deps (jose, nostr-tools/pure) not resolvable from root vitestplugins/ruflo-chatgpt-federation/test/oauth.test.mjs