fix(mcp-config-validator): remove invented trust field (verify-first)

`.mcp.json` has no per-server `trust` key — verified 2026-06-18 against
code.claude.com/docs/en/mcp + /settings. MCP server approval is
dialog/settings-based (enableAllProjectMcpServers / enabledMcpjsonServers /
disabledMcpjsonServers), never a JSON field. The scanner's "Missing trust
level" (CA-MCP-001, medium) and "Invalid trust level" (high) were false
positives flagging a field that does not exist.

- scanner: delete both trust checks + VALID_TRUST_LEVELS; drop `trust` from
  VALID_SERVER_FIELDS so a stray `trust` is now flagged as an unknown field
- humanizer: remove the two trust-level entries
- knowledge (5 files): point to the real approval mechanism, not a trust field
- fixtures: scrub `trust` (incl. the invalid "local" in optimal-setup)
- tests: flip assertions (no trust-level finding; stray trust -> unknown
  field) + add knowledge-staleness re-freeze guards
- snapshots: reseed (marketplace-medium .mcp.json -8 tokens, hermetic)
- gap-matrix: mark the trust verify-first item DONE

Suite: 853/853 green.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Ter3E2JSi1Khgmuf2kady8
This commit is contained in:
Kjell Tore Guttormsen 2026-06-18 14:22:56 +02:00
commit b3c572ad46
22 changed files with 110 additions and 100 deletions

View file

@ -3,8 +3,7 @@
"memory": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"trust": "workspace"
"args": ["-y", "@modelcontextprotocol/server-memory"]
}
}
}

View file

@ -3,14 +3,12 @@
"memory": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"trust": "workspace"
"args": ["-y", "@modelcontextprotocol/server-memory"]
},
"filesystem": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./docs"],
"trust": "trusted"
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./docs"]
}
}
}

View file

@ -3,20 +3,17 @@
"memory": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"trust": "workspace"
"args": ["-y", "@modelcontextprotocol/server-memory"]
},
"filesystem": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./docs"],
"trust": "trusted"
"args": ["-y", "@modelcontextprotocol/server-filesystem", "./docs"]
},
"github": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"trust": "trusted"
"args": ["-y", "@modelcontextprotocol/server-github"]
}
}
}

View file

@ -3,8 +3,7 @@
"memory": {
"type": "stdio",
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-memory"],
"trust": "workspace"
"args": ["-y", "@modelcontextprotocol/server-memory"]
}
}
}

View file

@ -73,3 +73,22 @@ test('claude-code-capabilities.md documents /config key=value', () => {
const md = read('claude-code-capabilities.md');
assert.match(md, /\/config/, '/config key=value in-session settings (2.1.181)');
});
// MCP `trust` is NOT a real .mcp.json field (verified 2026-06-18 against
// code.claude.com/docs/en/mcp + /settings). Approval is dialog/settings-based.
// These guards stop the corpus from re-fabricating the field.
test('claude-code-capabilities.md does not resurrect the invented MCP `trust` field', () => {
const md = read('claude-code-capabilities.md');
assert.doesNotMatch(md, /"trust":\s*"workspace/,
'the fabricated `trust` field must not return to the .mcp.json schema example');
assert.match(md, /enableAllProjectMcpServers|enabledMcpjsonServers/,
'must document the real MCP approval mechanism');
});
test('configuration-best-practices.md recommends real MCP approval, not a `trust` field', () => {
const md = read('configuration-best-practices.md');
assert.match(md, /enabledMcpjsonServers|enableAllProjectMcpServers/,
'must point to the real settings-based approval mechanism');
assert.doesNotMatch(md, /Set trust levels explicitly/,
'the invented "set trust levels" advice must be gone');
});

View file

@ -81,13 +81,9 @@ describe('MCP scanner — broken project', () => {
assert.equal(unknown.severity, 'high');
});
it('detects missing trust level', () => {
assert.ok(result.findings.some(f => f.title.includes('Missing trust level')));
});
it('missing trust is medium severity', () => {
const trust = result.findings.find(f => f.title.includes('Missing trust level'));
assert.equal(trust.severity, 'medium');
it('does NOT flag any trust level — `trust` is not a real .mcp.json field (CC docs verified 2026-06-18)', () => {
assert.ok(!result.findings.some(f => /trust level/i.test(f.title)),
'no "Missing trust level"/"Invalid trust level" findings: the field does not exist in the official schema');
});
it('detects unreferenced env vars in args', () => {
@ -103,6 +99,43 @@ describe('MCP scanner — broken project', () => {
});
});
describe('MCP scanner — stray `trust` field is an unknown field (verify-first, 2026-06-18)', () => {
let result;
let tmpRoot;
beforeEach(async () => {
resetCounter();
tmpRoot = await mkdtemp(join(tmpdir(), 'ca-mcp-trust-'));
// `trust` is NOT a field in the official .mcp.json schema (verified against
// code.claude.com/docs/en/mcp + /settings, 2026-06-18). Approval is
// dialog/settings-based (enableAllProjectMcpServers / enabledMcpjsonServers /
// disabledMcpjsonServers), never a per-server JSON field.
const mcp = {
mcpServers: {
legacy: { type: 'stdio', command: 'node', args: ['server.mjs'], trust: 'workspace' },
},
};
await writeFile(join(tmpRoot, '.mcp.json'), JSON.stringify(mcp, null, 2) + '\n', 'utf8');
const discovery = await discoverConfigFiles(tmpRoot);
result = await scan(tmpRoot, discovery);
});
afterEach(async () => {
if (tmpRoot) await rm(tmpRoot, { recursive: true, force: true });
});
it('flags `trust` as an unknown MCP server field', () => {
const f = result.findings.find(x => x.title.includes('Unknown MCP server field')
&& /trust/.test(x.description || ''));
assert.ok(f, 'a `trust` field must now be reported as an unknown field');
});
it('emits no "trust level" findings at all', () => {
assert.ok(!result.findings.some(x => /trust level/i.test(x.title)),
'the invented trust-level checks must be gone');
});
});
describe('MCP scanner — env-var false positives (CC 2.1.139/2.1.142, Batch 1)', () => {
let tmpRoot;
let envFindings;
@ -118,13 +151,11 @@ describe('MCP scanner — env-var false positives (CC 2.1.139/2.1.142, Batch 1)'
// CLAUDE_PROJECT_DIR is auto-injected (CC 2.1.139); ${VAR%…}/${VAR:-…}
// are POSIX expansions CC resolves (2.1.142) — none need an env block.
args: ['${CLAUDE_PROJECT_DIR}/server.mjs', '--root', '${HOME%/}', '--cfg', '${CONFIG_DIR:-/etc}'],
trust: 'workspace',
},
legacy: {
type: 'stdio',
command: 'node',
args: ['${REAL_MISSING}'],
trust: 'workspace',
},
},
};

View file

@ -481,7 +481,7 @@
},
{
"source": ".mcp.json",
"estimated_tokens": 53,
"estimated_tokens": 45,
"rank": 5,
"recommendations": [
"Deduplicate overlapping entries — each duplicate inflates the per-turn schema payload.",
@ -490,7 +490,7 @@
"path": "/Users/ktg/repos/ktg-plugin-marketplace/config-audit/tests/fixtures/marketplace-medium/.mcp.json"
}
],
"total_estimated_tokens": 809,
"total_estimated_tokens": 801,
"activeConfig": {
"claudeMdEstimatedTokens": "<ANCESTOR_DERIVED>",
"mcpServerCount": 1,

View file

@ -5,7 +5,7 @@
"status": "ok",
"files_scanned": 2,
"duration_ms": 0,
"total_estimated_tokens": 809,
"total_estimated_tokens": 801,
"hotspots": [
{
"source": "mcp:memory (.mcp.json)",
@ -47,7 +47,7 @@
},
{
"source": ".mcp.json",
"estimated_tokens": 53,
"estimated_tokens": 45,
"rank": 5,
"recommendations": [
"Deduplicate overlapping entries — each duplicate inflates the per-turn schema payload.",

View file

@ -1,15 +1,15 @@
[CML] CLAUDE.md Linter: 1 finding(s) (14ms)
[SET] Settings Validator: 0 finding(s) (1ms)
[SET] Settings Validator: 0 finding(s) (2ms)
[HKV] Hook Validator: 0 finding(s) (1ms)
[RUL] Rules Validator: 0 finding(s) (1ms)
[RUL] Rules Validator: 0 finding(s) (0ms)
[MCP] MCP Config Validator: 0 finding(s) (0ms)
[IMP] Import Resolver: 0 finding(s) (1ms)
[IMP] Import Resolver: 0 finding(s) (2ms)
[CNF] Conflict Detector: 0 finding(s) (1ms)
[GAP] Feature Gap Scanner: 17 finding(s) (2ms)
[TOK] Token Hotspots: 1 finding(s) (8ms)
[CPS] Cache-Prefix Stability: 0 finding(s) (1ms)
[DIS] Disabled-In-Schema: 0 finding(s) (0ms)
[COL] Plugin Skill Collision: 0 finding(s) (1ms)
[CPS] Cache-Prefix Stability: 0 finding(s) (0ms)
[DIS] Disabled-In-Schema: 0 finding(s) (1ms)
[COL] Plugin Skill Collision: 0 finding(s) (0ms)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Config-Audit Health Score

View file

@ -94,7 +94,7 @@
"scannerEnvelope": {
"meta": {
"target": "/Users/ktg/repos/ktg-plugin-marketplace/config-audit/tests/fixtures/marketplace-medium",
"timestamp": "2026-06-18T11:03:14.339Z",
"timestamp": "2026-06-18T12:19:30.125Z",
"version": "2.2.0",
"tool": "config-audit"
},
@ -145,7 +145,7 @@
"scanner": "HKV",
"status": "ok",
"files_scanned": 1,
"duration_ms": 1,
"duration_ms": 2,
"findings": [],
"counts": {
"critical": 0,
@ -187,7 +187,7 @@
"scanner": "IMP",
"status": "ok",
"files_scanned": 1,
"duration_ms": 1,
"duration_ms": 2,
"findings": [],
"counts": {
"critical": 0,
@ -201,7 +201,7 @@
"scanner": "CNF",
"status": "ok",
"files_scanned": 2,
"duration_ms": 0,
"duration_ms": 1,
"findings": [],
"counts": {
"critical": 0,
@ -451,7 +451,7 @@
"scanner": "TOK",
"status": "ok",
"files_scanned": 2,
"duration_ms": 8,
"duration_ms": 7,
"findings": [
{
"id": "CA-TOK-001",
@ -515,7 +515,7 @@
},
{
"source": ".mcp.json",
"estimated_tokens": 53,
"estimated_tokens": 45,
"rank": 5,
"recommendations": [
"Deduplicate overlapping entries — each duplicate inflates the per-turn schema payload.",
@ -524,7 +524,7 @@
"path": "/Users/ktg/repos/ktg-plugin-marketplace/config-audit/tests/fixtures/marketplace-medium/.mcp.json"
}
],
"total_estimated_tokens": 809,
"total_estimated_tokens": 801,
"activeConfig": {
"claudeMdEstimatedTokens": 1639,
"mcpServerCount": 1,
@ -536,20 +536,6 @@
"scanner": "CPS",
"status": "ok",
"files_scanned": 1,
"duration_ms": 1,
"findings": [],
"counts": {
"critical": 0,
"high": 0,
"medium": 0,
"low": 0,
"info": 0
}
},
{
"scanner": "DIS",
"status": "ok",
"files_scanned": 1,
"duration_ms": 0,
"findings": [],
"counts": {
@ -560,11 +546,25 @@
"info": 0
}
},
{
"scanner": "DIS",
"status": "ok",
"files_scanned": 1,
"duration_ms": 1,
"findings": [],
"counts": {
"critical": 0,
"high": 0,
"medium": 0,
"low": 0,
"info": 0
}
},
{
"scanner": "COL",
"status": "ok",
"files_scanned": 0,
"duration_ms": 1,
"duration_ms": 0,
"findings": [],
"counts": {
"critical": 0,

View file

@ -1,7 +1,7 @@
{
"meta": {
"target": "/Users/ktg/repos/ktg-plugin-marketplace/config-audit/tests/fixtures/marketplace-medium",
"timestamp": "2026-06-18T11:03:14.159Z",
"timestamp": "2026-06-18T12:19:29.934Z",
"version": "2.2.0",
"tool": "config-audit"
},
@ -422,7 +422,7 @@
},
{
"source": ".mcp.json",
"estimated_tokens": 53,
"estimated_tokens": 45,
"rank": 5,
"recommendations": [
"Deduplicate overlapping entries — each duplicate inflates the per-turn schema payload.",
@ -431,7 +431,7 @@
"path": "/Users/ktg/repos/ktg-plugin-marketplace/config-audit/tests/fixtures/marketplace-medium/.mcp.json"
}
],
"total_estimated_tokens": 809,
"total_estimated_tokens": 801,
"activeConfig": {
"claudeMdEstimatedTokens": 1639,
"mcpServerCount": 1,
@ -457,7 +457,7 @@
"scanner": "DIS",
"status": "ok",
"files_scanned": 1,
"duration_ms": 0,
"duration_ms": 1,
"findings": [],
"counts": {
"critical": 0,
@ -471,7 +471,7 @@
"scanner": "COL",
"status": "ok",
"files_scanned": 0,
"duration_ms": 1,
"duration_ms": 0,
"findings": [],
"counts": {
"critical": 0,

View file

@ -3,7 +3,7 @@
"status": "ok",
"files_scanned": 2,
"duration_ms": 9,
"total_estimated_tokens": 809,
"total_estimated_tokens": 801,
"hotspots": [
{
"source": "mcp:memory (.mcp.json)",
@ -45,7 +45,7 @@
},
{
"source": ".mcp.json",
"estimated_tokens": 53,
"estimated_tokens": 45,
"rank": 5,
"recommendations": [
"Deduplicate overlapping entries — each duplicate inflates the per-turn schema payload.",