🌊 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(mcp): allow explicit audit destination before environment
Rudy Celekli3d87b4e7d3ab
diff --git a/docs/mcp-audit-retention.md b/docs/mcp-audit-retention.mdindex 06a59c04f7..eb0daf2135 100644--- a/docs/mcp-audit-retention.md+++ b/docs/mcp-audit-retention.md@@ -7,7 +7,11 @@ working directory, alongside the project whose policy is loaded. Each recordalso includes `projectPath` so records remain attributable if explicitly routedto a shared destination.-Set `RUFLO_MCP_AUDIT_LOG_PATH` on the server process to choose another destination.+Set `auditLogPath` in the policy to choose an explicit destination. It takes+precedence over `RUFLO_MCP_AUDIT_LOG_PATH` on the server process, which is the+fallback when the policy omits the path. If both are absent, the project default+applies. An explicit path must be a non-empty string; invalid values deny+mandatory audit writes instead of silently selecting another destination.Absolute paths are used directly; relative paths resolve against the server'sworking directory. Missing parent directories are created. New directories usemode `0700`, and new logs use `0600` on systems that support POSIX permissions;@@ -43,5 +47,5 @@ resize existing segments or delete higher-numbered segments from an earlierconfiguration. Archive or prune those separately while writers are stopped.The old machine-wide temporary log is not migrated or deleted. Update log readersto the project path or set the environment variable to an explicitly managed-path. Enforcement coverage is unchanged: this does not add governance enforcement+path (unless the policy already sets `auditLogPath`). Enforcement coverage is unchanged: this does not add governance enforcementto HTTP/WebSocket dispatchers.diff --git a/v3/@claude-flow/cli/__tests__/mcp-audit-retention-3417.test.ts b/v3/@claude-flow/cli/__tests__/mcp-audit-retention-3417.test.tsindex 2b4b1b3e54..c1449a9459 100644--- a/v3/@claude-flow/cli/__tests__/mcp-audit-retention-3417.test.ts+++ b/v3/@claude-flow/cli/__tests__/mcp-audit-retention-3417.test.ts@@ -36,6 +36,23 @@ describe('project audit retention (#3417)', () => {vi.stubEnv('RUFLO_MCP_AUDIT_LOG_PATH', configured);expect(getAuditLogPath()).toBe(path.resolve(project, configured));});+ it.each(['policy/events.jsonl', path.join(os.tmpdir(), 'explicit-policy/events.jsonl')])('gives the explicit policy path precedence over the environment: %s', auditLogPath => {+ vi.stubEnv('RUFLO_MCP_AUDIT_LOG_PATH', 'env/events.jsonl');+ expect(getAuditLogPath({ auditLogPath })).toBe(path.resolve(project, auditLogPath));+ });+ it('writes mandatory audit evidence to the explicit policy destination', () => {+ vi.stubEnv('RUFLO_MCP_AUDIT_LOG_PATH', 'env/events.jsonl');+ const policy = { auditLog: true, auditLogPath: 'policy/events.jsonl' };+ expect(evaluateToolCall(policy, 's', 'tool').allowed).toBe(true);+ expect(records(path.join(project, policy.auditLogPath))[0]).toMatchObject({ toolName: 'tool', allowed: true });+ expect(fs.existsSync(path.join(project, 'env'))).toBe(false);+ expect(fs.existsSync(path.join(project, '.claude-flow'))).toBe(false);+ });+ it.each(['', ' ', null, 42])('fails closed for an invalid explicit audit path: %s', auditLogPath => {+ vi.stubEnv('RUFLO_MCP_AUDIT_LOG_PATH', 'env/events.jsonl');+ expect(evaluateToolCall({ auditLog: true, auditLogPath: auditLogPath as string }, 's', 'tool').allowed).toBe(false);+ expect(fs.readdirSync(project)).toEqual([]);+ });it('creates the configured parent and records the project with private permissions', () => {vi.stubEnv('RUFLO_MCP_AUDIT_LOG_PATH', 'custom/events.jsonl');expect(appendAuditLog({ auditLog: true }, entry(1))).toBe(true);diff --git a/v3/@claude-flow/cli/src/mcp-tools/policy-enforcer.ts b/v3/@claude-flow/cli/src/mcp-tools/policy-enforcer.tsindex 6838d7fdce..1a8b114cbb 100644--- a/v3/@claude-flow/cli/src/mcp-tools/policy-enforcer.ts+++ b/v3/@claude-flow/cli/src/mcp-tools/policy-enforcer.ts@@ -66,6 +66,8 @@ export interface McpPolicy {harnessId?: string;defaultDeny?: boolean;auditLog?: boolean;+ /** Explicit destination; takes precedence over the environment and project default. */+ auditLogPath?: string;/** Maximum bytes per audit segment. Default 10 MiB; oversized records fail closed. */auditLogMaxBytes?: number;/** Rotated segments retained in addition to the active log. Default 5, maximum 100. */@@ -181,17 +183,19 @@ export function setAuditLogPathForTesting(p: string | null): void {auditLogPathOverride = p;}-function defaultAuditLogPath(): string {- const configured = process.env.RUFLO_MCP_AUDIT_LOG_PATH;+export function getAuditLogPath(options: Pick<McpPolicy, 'auditLogPath'> = {}): string {+ if (auditLogPathOverride !== null) return auditLogPathOverride;+ if (options.auditLogPath !== undefined &&+ (typeof options.auditLogPath !== 'string' || options.auditLogPath.trim().length === 0)) {+ throw new Error('auditLogPath must be a non-empty string');+ }+ // Precedence: explicit caller/policy destination, environment, project default.+ const configured = options.auditLogPath ?? process.env.RUFLO_MCP_AUDIT_LOG_PATH;return configured? path.resolve(process.cwd(), configured): path.join(process.cwd(), '.claude-flow', 'logs', 'mcp-audit.jsonl');}-export function getAuditLogPath(): string {- return auditLogPathOverride ?? defaultAuditLogPath();-}-/*** Appends one JSONL audit record. Returns `true` if `policy.auditLog` is not* set (nothing was required) or the write succeeded; `false` only when@@ -210,7 +214,7 @@ export function appendAuditLog(policy: McpPolicy, entry: AuditLogEntry): booleanconst bytes = Buffer.byteLength(line, 'utf8');if (bytes > maxBytes) return false;- const logPath = getAuditLogPath();+ const logPath = getAuditLogPath(policy);fs.mkdirSync(path.dirname(logPath), { recursive: true, mode: 0o700 });// All writers of a configured path serialize rotation AND append. On// contention (or a stale lock after a crash), deny rather than lose audit