@craswitch/mcp-server 0.0.0-stage → 2.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,3 +1,100 @@
1
- # Temporary Holding Version
1
+ # `@craswitch/mcp-server` — EU CRA Article 14 & OpenVEX MCP Server
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Zero-dependency Model Context Protocol (MCP) server (JSON-RPC 2.0 over stdio) from [`theperipetycompany/cra-switch`](https://github.com/theperipetycompany/cra-switch) enabling AI coding assistants (Claude Code, Cursor, Antigravity), security engineers, and procurement bots to scan lockfiles with the **4-state CRA triage machine**, scaffold and update `.cra-vex.json` v2 attestations, draft **1:1 ENISA SRP manual web-form worksheets + Article 14(8) customer advisories**, and cryptographically verify Ed25519-signed OpenVEX documents.
4
+
5
+ ## Requirements
6
+
7
+ - Node.js `>= 22.0.0` (built-in `--experimental-strip-types`, `fetch`, and WebCrypto `Ed25519` — **zero external runtime dependencies**).
8
+
9
+ ## Exposed MCP Tools
10
+
11
+ ### CRA-Switch v2 Core Tools
12
+
13
+ | Tool | Description |
14
+ | --- | --- |
15
+ | `craswitch_scan_lockfile` | Scans a lockfile (`package-lock.json`, `pnpm-lock.yaml`, `Cargo.lock`, `go.sum`, `requirements.txt`, `poetry.lock`, `pom.xml`) via `POST /api/v1/scan` or local `@cra-switch/core` fallback. Returns CycloneDX PURL count, matched KEV/EUVD advisories, and **4-state triage status** (`triage_required` on raw matches — NEVER automatically starts a 24h statutory clock — or `clean`). |
16
+ | `craswitch_init_vex` | Scaffolds a valid `.cra-vex.json` v2 document (`version: "2"`, `securityContactEmail`, `coordinatorCsirt`, `euMemberStatesDistributed`, `suppressions: []`, `triageEvents: []`). |
17
+ | `craswitch_add_suppression` | Appends a spec-compliant OpenVEX `not_affected` suppression AND an auditable `triageEvents` timestamp entry to `.cra-vex.json` v2. |
18
+ | `craswitch_draft_enisa_srp` | Generates a **1:1 ENISA SRP manual web-form copy-paste worksheet** AND a parallel **Article 14(8) customer notification advisory** (`markdown`, `emailSubject`, `emailBody`, `ghsaPayload`). Never auto-submits to ENISA. |
19
+
20
+ ### Vendor Verification & Legacy Compatibility Tools
21
+
22
+ | Tool | Description |
23
+ | --- | --- |
24
+ | `check_vendor_cra_status` | Queries `GET /api/v1/x402/attest/:org/:repo`. Returns structured x402 payment challenge details on HTTP 402 or signed CRA posture on HTTP 200 with `paymentProof`. |
25
+ | `verify_vex_signature` | Fetches `GET /.well-known/vex.json?repo=<org>/<repo>` and cryptographically verifies its Ed25519 signature via WebCrypto (`crypto.subtle`). |
26
+ | `scan_lockfile_kev` | Legacy alias for lockfile KEV scanning (preserved for v1 compatibility). |
27
+
28
+ ## Client Setup
29
+
30
+ ### Claude Code
31
+
32
+ ```bash
33
+ claude mcp add craswitch -- npx -y @craswitch/mcp-server
34
+ ```
35
+
36
+ ### Cursor / Claude Desktop / Antigravity / MCP Registry
37
+
38
+ Add to `.cursor/mcp.json`, `claude_desktop_config.json`, or your MCP Registry client config:
39
+
40
+ ```json
41
+ {
42
+ "mcpServers": {
43
+ "craswitch": {
44
+ "command": "npx",
45
+ "args": ["-y", "@craswitch/mcp-server"],
46
+ "env": {
47
+ "CRA_SWITCH_URL": "https://craswitch.dev"
48
+ }
49
+ }
50
+ }
51
+ }
52
+ ```
53
+
54
+ ### Running Directly From the Monorepo Checkout
55
+
56
+ ```json
57
+ {
58
+ "mcpServers": {
59
+ "craswitch": {
60
+ "command": "node",
61
+ "args": [
62
+ "--experimental-strip-types",
63
+ "./packages/mcp/src/cli.ts"
64
+ ],
65
+ "env": {
66
+ "CRA_SWITCH_URL": "https://craswitch.dev"
67
+ }
68
+ }
69
+ }
70
+ }
71
+ ```
72
+
73
+ ## Publishing to npm & the Official MCP Registry
74
+
75
+ `packages/mcp/package.json` sets `"mcpName": "dev.craswitch/mcp-server"` and pairs with [`packages/mcp/server.json`](./server.json) for DNS-verified Official MCP Registry publication (Glama and downstream MCP directories auto-ingest from the Official MCP Registry).
76
+
77
+ 1. **Publish the npm package** (after bundling `@cra-switch/core` for standalone distribution):
78
+ ```bash
79
+ cd ./packages/mcp && npm publish --access public
80
+ ```
81
+ 2. **Verify domain ownership for `dev.craswitch` via DNS TXT** on `craswitch.dev` (`mcp-publisher init` / DNS TXT challenge), then publish the registry manifest:
82
+ ```bash
83
+ cd ./packages/mcp && mcp-publisher publish
84
+ ```
85
+ 3. **Directory auto-ingestion:** Once live in the Official MCP Registry (`dev.craswitch/mcp-server`), Glama and compatible MCP registries automatically index the listing from `server.json` — no manual duplicate form submission required.
86
+
87
+ > **Packaging note:** In the monorepo, `packages/mcp` imports `@cra-switch/core` via relative paths (`../../core/src/*.ts`). Run it directly from the `theperipetycompany/cra-switch` checkout, or bundle `packages/core` before running `npm publish --access public`.
88
+
89
+ ### Example JSON-RPC 2.0 Session
90
+
91
+ ```bash
92
+ printf '%s\n%s\n' \
93
+ '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2024-11-05","capabilities":{},"clientInfo":{"name":"demo","version":"2.0.0"}}}' \
94
+ '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \
95
+ | CRA_SWITCH_URL=https://craswitch.dev node --experimental-strip-types packages/mcp/src/cli.ts
96
+ ```
97
+
98
+ ## Legal Notice
99
+
100
+ > DRAFT COMPLIANCE AID ONLY — NOT LEGAL ADVICE. CRA-Switch aggregates public vulnerability feeds on a best-effort basis and NEVER auto-submits reports to ENISA. Raw dependency matches enter `triage_required` and never start the statutory 24-hour Article 14 clock until a vendor confirms active exploitation.
package/dist/cli.js ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env node
2
+ import { startStdioServer } from './server.js';
3
+
4
+ const defaultBaseUrl = process.env.CRA_SWITCH_URL || 'https://craswitch.dev';
5
+
6
+ startStdioServer({
7
+ defaultBaseUrl,
8
+ });
@@ -0,0 +1,156 @@
1
+ /**
2
+ * Self-contained, crisp SVG status badge renderer for CRA-Switch trust portals
3
+ * and repository README embeds (zero external dependencies).
4
+ */
5
+
6
+
7
+ import { escapeXml } from './enisa.js';
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
26
+ function resolveBadgeTheme(status ) {
27
+ switch (status) {
28
+ case 'clean':
29
+ case 'verified':
30
+ case 'compliant':
31
+ return {
32
+ rightText: 'verified',
33
+ color: '#059669',
34
+ dotColor: '#a7f3d0',
35
+ };
36
+ case 'not_affected':
37
+ return {
38
+ rightText: 'verified (vex)',
39
+ color: '#059669',
40
+ dotColor: '#a7f3d0',
41
+ };
42
+ case 'triage_required':
43
+ return {
44
+ rightText: 'under investigation',
45
+ color: '#d97706',
46
+ dotColor: '#fde68a',
47
+ };
48
+ case 'under_investigation':
49
+ return {
50
+ rightText: 'investigating',
51
+ color: '#d97706',
52
+ dotColor: '#fde68a',
53
+ };
54
+ case 'confirmed_exploited':
55
+ return {
56
+ rightText: 'active advisory',
57
+ color: '#dc2626',
58
+ dotColor: '#fecaca',
59
+ };
60
+ case 'alert_active':
61
+ case 'action_required_24h':
62
+ return {
63
+ rightText: '24h alert active',
64
+ color: '#dc2626',
65
+ dotColor: '#fecaca',
66
+ };
67
+ case 'unmonitored':
68
+ case 'unscanned':
69
+ return {
70
+ rightText: 'unmonitored',
71
+ color: '#64748b',
72
+ dotColor: '#cbd5e1',
73
+ };
74
+ }
75
+ }
76
+
77
+ function estimateTextWidth(text , bold = false) {
78
+ let width = 0;
79
+ for (let i = 0; i < text.length; i++) {
80
+ const ch = text[i] ?? '';
81
+ if ('ilIj1|.,:!;\'"'.includes(ch)) width += 4.3;
82
+ else if ('frt()[]'.includes(ch)) width += 5.0;
83
+ else if ('mwMW@%'.includes(ch)) width += 10.4;
84
+ else if (ch >= 'A' && ch <= 'Z') width += 8.2;
85
+ else width += 7.2;
86
+ }
87
+ return Math.ceil(bold ? width * 1.08 : width);
88
+ }
89
+
90
+ /**
91
+ * Renders a crisp, self-contained SVG badge for CRA Article 14 status.
92
+ * Supports `verified`, `alert_active`, `unmonitored`, and all `RepoStatusLevel` values.
93
+ * If `label` is a string, it customizes the left badge label; pass `{ left, right }`
94
+ * to customize either side.
95
+ */
96
+ export function renderStatusBadgeSvg(
97
+ status ,
98
+ label ,
99
+ ) {
100
+ const theme = resolveBadgeTheme(status);
101
+ const leftText =
102
+ typeof label === 'string'
103
+ ? label.trim() || 'EU CRA Art. 14'
104
+ : label?.left?.trim() || 'EU CRA Art. 14';
105
+ const rightText =
106
+ typeof label === 'object' && label?.right?.trim()
107
+ ? label.right.trim()
108
+ : theme.rightText;
109
+
110
+ const escapedLeft = escapeXml(leftText);
111
+ const escapedRight = escapeXml(rightText);
112
+ const ariaLabel = escapeXml(`${leftText}: ${rightText}`);
113
+
114
+ const leftPadding = 16;
115
+ const dotRadius = 3;
116
+ const dotLeftOffset = 10; // dot left edge at leftWidth + 7, right edge at leftWidth + 13
117
+ const dotToTextGap = 6; // guaranteed >= 6px breathing room between dot and text
118
+ const rightTrailingPadding = 10;
119
+
120
+ const leftTextWidth = estimateTextWidth(leftText, false);
121
+ const rightTextWidth = estimateTextWidth(rightText, true);
122
+
123
+ const leftWidth = Math.max(64, leftTextWidth + leftPadding);
124
+ const rightTextOffset = dotLeftOffset + dotRadius + dotToTextGap; // 19px from leftWidth
125
+ const rightWidth = Math.max(68, rightTextOffset + rightTextWidth + rightTrailingPadding);
126
+ const totalWidth = leftWidth + rightWidth;
127
+
128
+ const leftCenterX = Math.round(leftWidth / 2);
129
+ const dotX = leftWidth + dotLeftOffset;
130
+ const rightTextStartX = leftWidth + rightTextOffset;
131
+
132
+ return [
133
+ `<svg xmlns="http://www.w3.org/2000/svg" width="${totalWidth}" height="20" role="img" aria-label="${ariaLabel}">`,
134
+ ` <title>${ariaLabel}</title>`,
135
+ ' <linearGradient id="s" x2="0" y2="100%">',
136
+ ' <stop offset="0" stop-color="#fff" stop-opacity=".12"/>',
137
+ ' <stop offset="1" stop-opacity=".12"/>',
138
+ ' </linearGradient>',
139
+ ' <clipPath id="r">',
140
+ ` <rect width="${totalWidth}" height="20" rx="3" fill="#fff"/>`,
141
+ ' </clipPath>',
142
+ ' <g clip-path="url(#r)">',
143
+ ` <rect width="${leftWidth}" height="20" fill="#0f172a"/>`,
144
+ ` <rect x="${leftWidth}" width="${rightWidth}" height="20" fill="${theme.color}"/>`,
145
+ ` <rect width="${totalWidth}" height="20" fill="url(#s)"/>`,
146
+ ' </g>',
147
+ ` <circle cx="${dotX}" cy="10" r="${dotRadius}" fill="${theme.dotColor}"/>`,
148
+ ' <g fill="#fff" font-family="Verdana,Geneva,DejaVu Sans,sans-serif" text-rendering="geometricPrecision" font-size="11">',
149
+ ` <text aria-hidden="true" text-anchor="middle" x="${leftCenterX}" y="15" fill="#010101" fill-opacity=".3">${escapedLeft}</text>`,
150
+ ` <text text-anchor="middle" x="${leftCenterX}" y="14" fill="#f8fafc">${escapedLeft}</text>`,
151
+ ` <text aria-hidden="true" text-anchor="start" x="${rightTextStartX}" y="15" fill="#010101" fill-opacity=".3" font-weight="600">${escapedRight}</text>`,
152
+ ` <text text-anchor="start" x="${rightTextStartX}" y="14" fill="#ffffff" font-weight="600">${escapedRight}</text>`,
153
+ ' </g>',
154
+ '</svg>',
155
+ ].join('\n');
156
+ }
@@ -0,0 +1,199 @@
1
+ /**
2
+ * Zero-dependency encoding, canonical JSON, and pure-TS SHA-256 utilities.
3
+ * Runs identically on Cloudflare Workers and Node 22 (`--experimental-strip-types`).
4
+ */
5
+
6
+ const textEncoder = new TextEncoder();
7
+ const textDecoder = new TextDecoder();
8
+
9
+ export function utf8ToBytes(text ) {
10
+ return textEncoder.encode(text);
11
+ }
12
+
13
+ export function bytesToUtf8(bytes ) {
14
+ return textDecoder.decode(bytes);
15
+ }
16
+
17
+ export function bytesToBase64(bytes ) {
18
+ let binary = '';
19
+ const chunkSize = 0x8000;
20
+ for (let i = 0; i < bytes.length; i += chunkSize) {
21
+ const chunk = bytes.subarray(i, i + chunkSize);
22
+ binary += String.fromCharCode(...chunk);
23
+ }
24
+ return btoa(binary);
25
+ }
26
+
27
+ export function base64ToBytes(b64 ) {
28
+ const normalized = b64.replace(/-/g, '+').replace(/_/g, '/').replace(/\s+/g, '');
29
+ const padLen = (4 - (normalized.length % 4)) % 4;
30
+ const padded = normalized + '='.repeat(padLen);
31
+ const binary = atob(padded);
32
+ const bytes = new Uint8Array(binary.length);
33
+ for (let i = 0; i < binary.length; i++) {
34
+ bytes[i] = binary.charCodeAt(i);
35
+ }
36
+ return bytes;
37
+ }
38
+
39
+ export function bytesToBase64Url(bytes ) {
40
+ return bytesToBase64(bytes).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '');
41
+ }
42
+
43
+ export function base64UrlToBytes(b64u ) {
44
+ return base64ToBytes(b64u);
45
+ }
46
+
47
+ export function bytesToHex(bytes ) {
48
+ let out = '';
49
+ for (let i = 0; i < bytes.length; i++) {
50
+ out += (bytes[i] ?? 0).toString(16).padStart(2, '0');
51
+ }
52
+ return out;
53
+ }
54
+
55
+ /**
56
+ * Constant-time equality comparison for byte arrays or ASCII/UTF-8 strings.
57
+ */
58
+ export function constantTimeEqual(a , b ) {
59
+ const aBytes = typeof a === 'string' ? utf8ToBytes(a) : a;
60
+ const bBytes = typeof b === 'string' ? utf8ToBytes(b) : b;
61
+ const maxLen = Math.max(aBytes.length, bBytes.length);
62
+ let diff = aBytes.length ^ bBytes.length;
63
+ for (let i = 0; i < maxLen; i++) {
64
+ diff |= (aBytes[i] ?? 0) ^ (bBytes[i] ?? 0);
65
+ }
66
+ return diff === 0;
67
+ }
68
+
69
+ /**
70
+ * Deterministic canonical JSON serialization with recursively sorted object keys.
71
+ * Undefined object properties are omitted (matching JSON.stringify behavior).
72
+ */
73
+ export function canonicalJson(value ) {
74
+ if (value === null || typeof value !== 'object') {
75
+ return JSON.stringify(value);
76
+ }
77
+ if (Array.isArray(value)) {
78
+ return '[' + value.map((item) => (item === undefined ? 'null' : canonicalJson(item))).join(',') + ']';
79
+ }
80
+ const record = value ;
81
+ const keys = Object.keys(record).sort();
82
+ const pairs = [];
83
+ for (const key of keys) {
84
+ const val = record[key];
85
+ if (val === undefined) continue;
86
+ pairs.push(JSON.stringify(key) + ':' + canonicalJson(val));
87
+ }
88
+ return '{' + pairs.join(',') + '}';
89
+ }
90
+
91
+ // ---------------------------------------------------------------------------
92
+ // Pure-TypeScript Synchronous SHA-256 (FIPS 180-4)
93
+ // ---------------------------------------------------------------------------
94
+
95
+ const SHA256_K = new Uint32Array([
96
+ 0x428a2f98, 0x71374491, 0xb5c0fbcf, 0xe9b5dba5, 0x3956c25b, 0x59f111f1, 0x923f82a4, 0xab1c5ed5,
97
+ 0xd807aa98, 0x12835b01, 0x243185be, 0x550c7dc3, 0x72be5d74, 0x80deb1fe, 0x9bdc06a7, 0xc19bf174,
98
+ 0xe49b69c1, 0xefbe4786, 0x0fc19dc6, 0x240ca1cc, 0x2de92c6f, 0x4a7484aa, 0x5cb0a9dc, 0x76f988da,
99
+ 0x983e5152, 0xa831c66d, 0xb00327c8, 0xbf597fc7, 0xc6e00bf3, 0xd5a79147, 0x06ca6351, 0x14292967,
100
+ 0x27b70a85, 0x2e1b2138, 0x4d2c6dfc, 0x53380d13, 0x650a7354, 0x766a0abb, 0x81c2c92e, 0x92722c85,
101
+ 0xa2bfe8a1, 0xa81a664b, 0xc24b8b70, 0xc76c51a3, 0xd192e819, 0xd6990624, 0xf40e3585, 0x106aa070,
102
+ 0x19a4c116, 0x1e376c08, 0x2748774c, 0x34b0bcb5, 0x391c0cb3, 0x4ed8aa4a, 0x5b9cca4f, 0x682e6ff3,
103
+ 0x748f82ee, 0x78a5636f, 0x84c87814, 0x8cc70208, 0x90befffa, 0xa4506ceb, 0xbef9a3f7, 0xc67178f2,
104
+ ]);
105
+
106
+ function rotr(x , n ) {
107
+ return (x >>> n) | (x << (32 - n));
108
+ }
109
+
110
+ export function sha256Bytes(input ) {
111
+ const data = typeof input === 'string' ? utf8ToBytes(input) : input;
112
+ const bitLen = data.length * 8;
113
+ const paddedLen = Math.ceil((data.length + 9) / 64) * 64;
114
+ const padded = new Uint8Array(paddedLen);
115
+ padded.set(data);
116
+ padded[data.length] = 0x80;
117
+
118
+ const view = new DataView(padded.buffer);
119
+ const highBits = Math.floor(bitLen / 0x100000000);
120
+ const lowBits = bitLen >>> 0;
121
+ view.setUint32(paddedLen - 8, highBits, false);
122
+ view.setUint32(paddedLen - 4, lowBits, false);
123
+
124
+ let h0 = 0x6a09e667;
125
+ let h1 = 0xbb67ae85;
126
+ let h2 = 0x3c6ef372;
127
+ let h3 = 0xa54ff53a;
128
+ let h4 = 0x510e527f;
129
+ let h5 = 0x9b05688c;
130
+ let h6 = 0x1f83d9ab;
131
+ let h7 = 0x5be0cd19;
132
+
133
+ const w = new Uint32Array(64);
134
+
135
+ for (let offset = 0; offset < paddedLen; offset += 64) {
136
+ for (let i = 0; i < 16; i++) {
137
+ w[i] = view.getUint32(offset + i * 4, false);
138
+ }
139
+ for (let i = 16; i < 64; i++) {
140
+ const w15 = w[i - 15] ?? 0;
141
+ const w2 = w[i - 2] ?? 0;
142
+ const s0 = rotr(w15, 7) ^ rotr(w15, 18) ^ (w15 >>> 3);
143
+ const s1 = rotr(w2, 17) ^ rotr(w2, 19) ^ (w2 >>> 10);
144
+ w[i] = ((w[i - 16] ?? 0) + s0 + (w[i - 7] ?? 0) + s1) >>> 0;
145
+ }
146
+
147
+ let a = h0;
148
+ let b = h1;
149
+ let c = h2;
150
+ let d = h3;
151
+ let e = h4;
152
+ let f = h5;
153
+ let g = h6;
154
+ let h = h7;
155
+
156
+ for (let i = 0; i < 64; i++) {
157
+ const S1 = rotr(e, 6) ^ rotr(e, 11) ^ rotr(e, 25);
158
+ const ch = (e & f) ^ (~e & g);
159
+ const temp1 = (h + S1 + ch + (SHA256_K[i] ?? 0) + (w[i] ?? 0)) >>> 0;
160
+ const S0 = rotr(a, 2) ^ rotr(a, 13) ^ rotr(a, 22);
161
+ const maj = (a & b) ^ (a & c) ^ (b & c);
162
+ const temp2 = (S0 + maj) >>> 0;
163
+
164
+ h = g;
165
+ g = f;
166
+ f = e;
167
+ e = (d + temp1) >>> 0;
168
+ d = c;
169
+ c = b;
170
+ b = a;
171
+ a = (temp1 + temp2) >>> 0;
172
+ }
173
+
174
+ h0 = (h0 + a) >>> 0;
175
+ h1 = (h1 + b) >>> 0;
176
+ h2 = (h2 + c) >>> 0;
177
+ h3 = (h3 + d) >>> 0;
178
+ h4 = (h4 + e) >>> 0;
179
+ h5 = (h5 + f) >>> 0;
180
+ h6 = (h6 + g) >>> 0;
181
+ h7 = (h7 + h) >>> 0;
182
+ }
183
+
184
+ const out = new Uint8Array(32);
185
+ const outView = new DataView(out.buffer);
186
+ outView.setUint32(0, h0, false);
187
+ outView.setUint32(4, h1, false);
188
+ outView.setUint32(8, h2, false);
189
+ outView.setUint32(12, h3, false);
190
+ outView.setUint32(16, h4, false);
191
+ outView.setUint32(20, h5, false);
192
+ outView.setUint32(24, h6, false);
193
+ outView.setUint32(28, h7, false);
194
+ return out;
195
+ }
196
+
197
+ export function sha256Hex(input ) {
198
+ return bytesToHex(sha256Bytes(input));
199
+ }