#!/usr/bin/env node // mcp-2026-07-28-schema-check.mjs, version 1.1 (2026-11-28), from https://jwatte.com/blog/change-live-mcp-connector-without-breaking-it/ // // A read-only check of one MCP server against the official 2026-07-28 schema.json, the way a validating // client (public reports say claude.ai on the web reads MCP Apps views this way) sees it. It sends at most 16 requests, paced 1.1 s apart: // // server/discover, tools/list, resources/list, resources/templates/list, prompts/list, then tools/list and resources/list // again with the MCP Apps capability (some servers name or list their views only then; views are taken from both), // resources/read of the first listed resource and of the first two ui:// views (each also with the MCP Apps capability), // resources/read of a resource that does not exist (expects -32602), // and three refusals: a header that does not match the body (400, -32020), an unknown protocol version // (400, -32022) and a request with no _meta envelope (any refusal; 400 and -32602 is OK, another code a WARN). // // It never calls tools/call, prompts/get or anything that could change data. Check only servers you operate. // It does not follow redirects: give it the final /mcp address. // // Limits: // - It checks only the list methods and resources/read. Results of tools/call, prompts/get and // completion/complete are not checked, and initialize, ping and -32021 are not sent. // - It sends no Authorization header, so it checks only a public server (no sign-in). // - It does not enforce the JSON Schema `format` keyword (uri, date-time and the like). // - It puts a resource address in the Mcp-Name header as is; an address with non-ASCII characters is not // Base64-encoded as the HTTP transport requires, so test such addresses another way. // // node mcp-2026-07-28-schema-check.mjs https://example.com/mcp // node mcp-2026-07-28-schema-check.mjs https://example.com/mcp --schema ./schema.json --pace 1500 // // Node 18 or later. No dependency: the schema checker below handles $ref, type, required, properties, // additionalProperties, items, enum, const, anyOf, oneOf, allOf and the numeric, string and array bounds. It // skips `format` and the annotation keywords, and names any other keyword it does not know, so a later schema // cannot pass unnoticed. If you prefer Ajv, validate the saved rows (--json) with it; the two agreed on every row we ran. // Without --schema, the schema is downloaded once from the official repository: // https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/schema/2026-07-28/schema.json // // Exit code: 0 when nothing FAILED, 1 on any FAIL, 2 on a usage or download error. import { readFileSync, writeFileSync } from 'node:fs'; const V = '2026-07-28'; const SCHEMA_URL = 'https://raw.githubusercontent.com/modelcontextprotocol/modelcontextprotocol/main/schema/2026-07-28/schema.json'; const UI_EXT = 'io.modelcontextprotocol/ui'; const UI_MIME = 'text/html;profile=mcp-app'; const SI = 'io.modelcontextprotocol/serverInfo'; const args = process.argv.slice(2); const opt = (name, dflt) => { const i = args.indexOf(name); return i >= 0 ? args[i + 1] : dflt; }; const endpoint = args.find((a) => /^https?:\/\//.test(a)); const pace = Math.max(1000, Number(opt('--pace', 1100)) || 1100); const jsonOut = opt('--json', ''); if (!endpoint) { console.error('usage: node mcp-2026-07-28-schema-check.mjs https://your-site/mcp [--schema schema.json] [--pace ms] [--json rows.json]'); process.exit(2); } // ---- schema ------------------------------------------------------------------------------------------- let raw; try { const file = opt('--schema', ''); raw = file ? JSON.parse(readFileSync(file, 'utf8')) : await (await fetch(SCHEMA_URL, { signal: AbortSignal.timeout(30000) })).json(); } catch (e) { console.error(`could not read the schema: ${e.message}`); process.exit(2); } const defs = raw.$defs || raw.definitions; if (!defs?.ReadResourceResult) { console.error('that file is not the MCP 2026-07-28 schema.json'); process.exit(2); } const KNOWN = new Set(['$ref', 'type', 'required', 'properties', 'additionalProperties', 'items', 'enum', 'const', 'anyOf', 'oneOf', 'allOf', 'minimum', 'maximum', 'minLength', 'maxLength', 'minItems', 'maxItems', 'description', 'format', '$schema', '$id', 'title', 'default', 'examples', 'deprecated', '$comment', 'readOnly', 'writeOnly', 'contentMediaType', 'contentEncoding']); const unknown = new Set(); (function walk(n) { if (Array.isArray(n)) return n.forEach(walk); if (!n || typeof n !== 'object') return; for (const [k, v] of Object.entries(n)) { if (!KNOWN.has(k)) unknown.add(k); if (k === 'properties') Object.values(v).forEach(walk); else if (!['enum', 'const', 'default', 'examples'].includes(k)) walk(v); } })(Object.values(defs)); const typeOf = (v) => (v === null ? 'null' : Array.isArray(v) ? 'array' : typeof v); const typeOk = (t, v) => (t === 'integer' ? Number.isInteger(v) : t === 'number' ? typeof v === 'number' && Number.isFinite(v) : typeOf(v) === t); const same = (a, b) => JSON.stringify(a) === JSON.stringify(b); const own = (o, k) => Object.prototype.hasOwnProperty.call(o, k); function check(node, v, path, out, depth) { const at = path || '/'; if (depth > 64 || node === true || node === undefined) return; if (node === false) { out.push(`${at} is not allowed`); return; } if (node.$ref) { const m = /^#\/(\$defs|definitions)\/(.+)$/.exec(node.$ref); const target = m && defs[decodeURIComponent(m[2])]; if (!target) { out.push(`${at} unresolved $ref ${node.$ref}`); return; } check(target, v, path, out, depth + 1); } if (node.type !== undefined) { const types = [].concat(node.type); if (!types.some((t) => typeOk(t, v))) { out.push(`${at} must be ${types.join(' or ')} (is ${typeOf(v)})`); return; } } if (node.enum && !node.enum.some((e) => same(e, v))) out.push(`${at} must be one of ${JSON.stringify(node.enum)}`); if (own(node, 'const') && !same(node.const, v)) out.push(`${at} must be ${JSON.stringify(node.const)}`); if (typeof v === 'number') { if (node.minimum !== undefined && v < node.minimum) out.push(`${at} must be >= ${node.minimum}`); if (node.maximum !== undefined && v > node.maximum) out.push(`${at} must be <= ${node.maximum}`); } if (typeof v === 'string') { if (node.minLength !== undefined && [...v].length < node.minLength) out.push(`${at} is too short`); if (node.maxLength !== undefined && [...v].length > node.maxLength) out.push(`${at} is too long`); } if (Array.isArray(v)) { if (node.minItems !== undefined && v.length < node.minItems) out.push(`${at} has too few items`); if (node.maxItems !== undefined && v.length > node.maxItems) out.push(`${at} has too many items`); if (node.items && typeof node.items === 'object' && !Array.isArray(node.items)) v.forEach((x, i) => check(node.items, x, `${path}/${i}`, out, depth + 1)); } if (v && typeof v === 'object' && !Array.isArray(v)) { for (const r of node.required || []) if (!own(v, r)) out.push(`${at} must have required property '${r}'`); const props = node.properties || {}; for (const [k, x] of Object.entries(v)) { if (own(props, k)) check(props[k], x, `${path}/${k}`, out, depth + 1); else if (node.additionalProperties === false) out.push(`${at} must not have additional property '${k}'`); else if (node.additionalProperties && typeof node.additionalProperties === 'object') check(node.additionalProperties, x, `${path}/${k}`, out, depth + 1); } } for (const sub of node.allOf || []) check(sub, v, path, out, depth + 1); if (node.anyOf) { const runs = node.anyOf.map((sub) => { const o = []; check(sub, v, path, o, depth + 1); return o; }); if (!runs.some((o) => !o.length)) out.push(`${at} matches no anyOf branch (closest: ${runs.reduce((a, b) => (b.length < a.length ? b : a)).slice(0, 2).join('; ')})`); } if (node.oneOf) { const n = node.oneOf.filter((sub) => { const o = []; check(sub, v, path, o, depth + 1); return !o.length; }).length; if (n !== 1) out.push(`${at} must match exactly one oneOf branch (matches ${n})`); } } const validate = (def, value) => { const out = []; check(defs[def], value, '', out, 0); return [...new Set(out)]; }; // ---- requests ----------------------------------------------------------------------------------------- const NAME_FIELD = { 'tools/call': 'name', 'prompts/get': 'name', 'resources/read': 'uri' }; const sleep = (ms) => new Promise((r) => setTimeout(r, ms)); let id = 0; async function send(method, params = {}, { version = V, envelope = true, caps = {}, headers: extra = {} } = {}) { await sleep(id ? pace : 0); const headers = { 'content-type': 'application/json', accept: 'application/json, text/event-stream', 'mcp-protocol-version': version, 'mcp-method': method }; if (NAME_FIELD[method] && typeof params[NAME_FIELD[method]] === 'string') headers['mcp-name'] = params[NAME_FIELD[method]]; Object.assign(headers, extra); const p = envelope ? { ...params, _meta: { 'io.modelcontextprotocol/protocolVersion': version, 'io.modelcontextprotocol/clientInfo': { name: 'mcp-2026-07-28-schema-check', version: '1.1' }, 'io.modelcontextprotocol/clientCapabilities': caps } } : params; let res, text; try { res = await fetch(endpoint, { method: 'POST', headers, redirect: 'manual', signal: AbortSignal.timeout(30000), body: JSON.stringify({ jsonrpc: '2.0', id: ++id, method, params: p }) }); text = await res.text(); } catch (e) { return { status: 0, message: { unparsed: `request failed: ${e.cause?.code || e.message}` } }; } if (res.status >= 300 && res.status < 400) return { status: res.status, message: { unparsed: `redirect to ${res.headers.get('location') || '(no Location)'} not followed; give the final /mcp address` } }; const events = [...text.matchAll(/^data: (.*)$/gm)].map((m) => m[1]); let message; try { message = JSON.parse(events.length ? events[events.length - 1] : text); } catch { message = null; } if (!message || typeof message !== 'object' || Array.isArray(message)) message = { unparsed: text.slice(0, 200) }; return { status: res.status, message }; } const rows = []; let fails = 0; const report = (verdict, label, detail) => { if (verdict === 'FAIL') fails++; rows.push({ verdict, label, detail }); console.log(`${verdict.padEnd(4)} ${label}${detail ? `: ${detail}` : ''}`); }; const extras = (res) => { const w = []; if (!res?._meta?.[SI]) w.push(`no _meta["${SI}"] (SHOULD be on every result)`); return w; }; // Validate a success result against its definition; -32601 means the server does not offer the method. async function resultRow(label, method, params, def, opts, refusedNote = '') { const r = await send(method, params, opts); const { result, error } = r.message; if (error?.code === -32601) { report('SKIP', label, 'method not offered (-32601)'); return null; } if (!result) { report(refusedNote ? 'INFO' : 'FAIL', label, `${refusedNote ? `${refusedNote}; ` : ''}HTTP ${r.status}, no result: ${JSON.stringify(error || r.message).slice(0, 160)}`); return null; } const problems = validate(def, result); if (problems.length) report('FAIL', label, `${def} INVALID: ${problems.slice(0, 4).join('; ')}`); else report('OK', label, `${def} valid (resultType ${result.resultType}${own(result, 'ttlMs') ? `, ttlMs ${result.ttlMs}, cacheScope ${result.cacheScope}` : ''})`); for (const w of extras(result)) report('WARN', label, w); return result; } async function errorRow(label, method, params, opts, wantStatus, wantCode, def = 'JSONRPCErrorResponse') { const r = await send(method, params, opts); const e = r.message.error; if (!r.message.error && r.message.unparsed) { report('FAIL', label, `HTTP ${r.status}, ${r.message.unparsed}`); return; } const problems = validate(def, r.message); const good = e && e.code === wantCode && (wantStatus === null || r.status === wantStatus) && !problems.length; report(good ? 'OK' : 'FAIL', label, `HTTP ${r.status}, code ${e?.code ?? 'none'} (want ${wantStatus ?? 'any'} and ${wantCode})${problems.length ? `; ${problems[0]}` : ''}`); } console.log(`MCP ${V} schema check of ${endpoint} (pace ${pace} ms)`); if (unknown.size) report('WARN', 'schema keywords', `this checker does not know: ${[...unknown].join(', ')}; validate with Ajv as well`); const discover = await resultRow('server/discover', 'server/discover', {}, 'DiscoverResult'); if (discover && !(Array.isArray(discover.supportedVersions) && discover.supportedVersions.includes(V))) report('FAIL', 'server/discover', `supportedVersions does not list ${V}`); const serverExt = discover?.capabilities?.extensions || {}; const tl = await resultRow('tools/list', 'tools/list', {}, 'ListToolsResult'); const uiTools = (Array.isArray(tl?.tools) ? tl.tools : []).filter((t) => t?._meta?.ui?.resourceUri); const rl = await resultRow('resources/list', 'resources/list', {}, 'ListResourcesResult'); await resultRow('resources/templates/list', 'resources/templates/list', {}, 'ListResourceTemplatesResult'); await resultRow('prompts/list', 'prompts/list', {}, 'ListPromptsResult'); const uiCaps = { extensions: { [UI_EXT]: { mimeTypes: [UI_MIME] } } }; const CAP = ' (with the MCP Apps capability)'; // Hosts that render views send the MCP Apps capability; some servers name or list their views only then. const tlc = tl ? await resultRow(`tools/list${CAP}`, 'tools/list', {}, 'ListToolsResult', { caps: uiCaps }) : null; const rlc = rl ? await resultRow(`resources/list${CAP}`, 'resources/list', {}, 'ListResourcesResult', { caps: uiCaps }) : null; const listed = (Array.isArray(rl?.resources) ? rl.resources : []).map((r) => r?.uri).filter((u) => typeof u === 'string'); const plain = listed.find((u) => !u.startsWith('ui://')); if (plain) await resultRow(`resources/read ${plain}`, 'resources/read', { uri: plain }, 'ReadResourceResult'); const seenWithout = new Set([...uiTools.map((t) => t._meta.ui.resourceUri), ...listed]); uiTools.push(...(Array.isArray(tlc?.tools) ? tlc.tools : []).filter((t) => t?._meta?.ui?.resourceUri)); listed.push(...(Array.isArray(rlc?.resources) ? rlc.resources : []).map((r) => r?.uri).filter((u) => typeof u === 'string')); const views = [...new Set([...uiTools.map((t) => t._meta.ui.resourceUri).filter((u) => typeof u === 'string'), ...listed.filter((u) => u.startsWith('ui://'))])].slice(0, 2); for (const uri of views) { // Each view is read without and with the capability; a view seen only with it may be refused without it. for (const [tag, caps] of [['', {}], [CAP, uiCaps]]) { const res = await resultRow(`resources/read ${uri}${tag}`, 'resources/read', { uri }, 'ReadResourceResult', { caps }, caps === uiCaps || seenWithout.has(uri) ? '' : 'this view is named or listed only with the MCP Apps capability, so a read without it may be refused (a separate path is allowed)'); const c = Array.isArray(res?.contents) ? res.contents : []; if (res && !(c.length === 1 && c[0]?.mimeType === UI_MIME)) report('FAIL', `view ${uri}${tag}`, `want exactly one content item with mimeType ${UI_MIME}, got ${c.map((x) => x?.mimeType).join(', ') || 'none'}`); } } if (uiTools.length && !serverExt[UI_EXT]) report('INFO', 'capabilities.extensions', `tools carry _meta.ui.resourceUri but server/discover (sent without the MCP Apps capability) does not advertise ${UI_EXT}; the views still render in hosts that read the tool _meta`); if (uiTools.some((t) => !String(t._meta.ui.resourceUri).startsWith('ui://'))) report('FAIL', 'tool _meta.ui.resourceUri', 'every resourceUri must use the ui:// scheme'); const missing = views[0] ? `${views[0].replace(/[^/]*$/, '')}no-such-view-zz.html` : 'https://example.invalid/no-such-resource-zz'; if (rl) await errorRow(`resources/read of a missing resource (${missing})`, 'resources/read', { uri: missing }, {}, null, -32602); else report('SKIP', 'resources/read of a missing resource', 'resources/list gave no list, so there is no resource to miss'); await errorRow('header mismatch (Mcp-Method says prompts/list, body says tools/list)', 'tools/list', {}, { headers: { 'mcp-method': 'prompts/list' } }, 400, -32020, 'HeaderMismatchError'); await errorRow('unknown protocol version 2099-01-01', 'tools/list', {}, { version: '2099-01-01' }, 400, -32022, 'UnsupportedProtocolVersionError'); { // The schema requires params._meta but names no single error code for a request without it. const r = await send('tools/list', {}, { envelope: false }); const e = r.message.error; if (!e && r.message.unparsed) report('FAIL', 'no _meta envelope', `HTTP ${r.status}, ${r.message.unparsed}`); else if (!e) report('FAIL', 'no _meta envelope', `HTTP ${r.status}: the request was not refused`); else if (r.status === 400 && e.code === -32602) report('OK', 'no _meta envelope', 'HTTP 400, code -32602'); else report('WARN', 'no _meta envelope', `refused with HTTP ${r.status}, code ${e.code} (ours answer 400 and -32602)`); } console.log(`\n${fails ? 'FAILED' : 'OK'}: ${rows.filter((r) => r.verdict === 'OK').length} ok, ${rows.filter((r) => r.verdict === 'WARN').length} warn, ${fails} fail, ${rows.filter((r) => r.verdict === 'SKIP').length} skipped, ${id} requests`); if (jsonOut) writeFileSync(jsonOut, JSON.stringify(rows, null, 2)); process.exitCode = fails ? 1 : 0;