Spaces:
Running
Running
Download index.html from JTRSHM/MCP-Guard-Studio: direct link, hf CLI and curl.
- Browser
- Download file 13.5 kB
-
https://huggingface.co/spaces/JTRSHM/MCP-Guard-Studio/resolve/main/index.html
- Command line
-
hf download hf://spaces/JTRSHM/MCP-Guard-Studio/index.html
-
curl -L -o index.html https://huggingface.co/spaces/JTRSHM/MCP-Guard-Studio/resolve/main/index.html
13.5 kB
| <html lang="en"> | |
| <head> | |
| <meta charset="utf-8" /> | |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | |
| <title>MCP-Guard & Studio</title> | |
| <style> | |
| :root { --bg:#090d16; --panel:#111827; --border:#1f2937; --text:#f3f4f6; --muted:#9ca3af; --accent:#38bdf8; } | |
| * { box-sizing:border-box; } | |
| body { margin:0; padding:24px; font-family:system-ui,-apple-system,Segoe UI,Roboto,sans-serif; background:var(--bg); color:var(--text); } | |
| .wrap { max-width:1280px; margin:0 auto; } | |
| .topbar { display:flex; flex-wrap:wrap; justify-content:space-between; align-items:flex-end; gap:12px; margin-bottom:20px; border-bottom:1px solid var(--border); padding-bottom:16px; } | |
| h1 { margin:0 0 6px 0; font-size:28px; } | |
| .sub { color:var(--muted); font-size:14px; } | |
| .links { display:flex; gap:10px; flex-wrap:wrap; } | |
| .pill { display:inline-block; padding:6px 12px; border-radius:999px; background:#1e293b; color:#7dd3fc; text-decoration:none; font-size:12px; font-weight:600; border:1px solid #334155; } | |
| .tabs { display:flex; gap:8px; margin-bottom:16px; flex-wrap:wrap; } | |
| .tab-btn { padding:9px 16px; border-radius:8px; border:1px solid var(--border); background:var(--panel); color:var(--muted); cursor:pointer; font-weight:600; font-size:13px; } | |
| .tab-btn.active { background:#0284c7; border-color:#0284c7; color:#fff; } | |
| .tab-pane { display:none; } | |
| .tab-pane.active { display:block; } | |
| .grid { display:grid; grid-template-columns:1fr 1fr; gap:18px; } | |
| @media (max-width:920px) { .grid { grid-template-columns:1fr; } } | |
| .card { background:var(--panel); border:1px solid var(--border); border-radius:12px; padding:16px; } | |
| textarea { width:100%; height:360px; background:#030712; color:#e5e7eb; border:1px solid var(--border); border-radius:8px; padding:12px; font-family:ui-monospace,Consolas,monospace; font-size:12px; line-height:1.45; } | |
| select, input, button { padding:8px 12px; border-radius:8px; border:1px solid var(--border); background:#030712; color:var(--text); font-size:13px; } | |
| button.primary { background:#0284c7; border-color:#0284c7; font-weight:600; cursor:pointer; color:#fff; } | |
| button.primary:hover { background:#0369a1; } | |
| button.secondary { background:#1e293b; border-color:#334155; cursor:pointer; } | |
| .row { display:flex; gap:10px; flex-wrap:wrap; align-items:center; margin-bottom:12px; } | |
| .score { font-size:30px; font-weight:800; } | |
| pre { background:#030712; border:1px solid var(--border); border-radius:8px; padding:12px; overflow:auto; max-height:280px; font-size:12px; } | |
| .badge { display:inline-block; padding:2px 8px; border-radius:999px; font-size:11px; font-weight:700; margin-right:6px; } | |
| .CRITICAL { background:#7f1d1d; color:#fecaca; } | |
| .HIGH { background:#7c2d12; color:#fed7aa; } | |
| .MEDIUM { background:#78350f; color:#fde68a; } | |
| .LOW { background:#0c4a6e; color:#bae6fd; } | |
| .PASS { background:#064e3b; color:#a7f3d0; } | |
| table { width:100%; border-collapse:collapse; font-size:13px; } | |
| th, td { text-align:left; padding:8px 10px; border-bottom:1px solid var(--border); } | |
| th { color:var(--muted); } | |
| code { background:#030712; padding:2px 6px; border-radius:4px; color:#38bdf8; font-size:12px; } | |
| </style> | |
| </head> | |
| <body> | |
| <div class="wrap"> | |
| <div class="topbar"> | |
| <div> | |
| <h1>MCP-Guard & Studio</h1> | |
| <div class="sub">100% Client-Side MCP Tool Poisoning Scanner, JSON Schema Contract Validator & Chaos Fault Simulator</div> | |
| </div> | |
| <div class="links"> | |
| <a class="pill" href="https://github.com/NPLMSHJTR/mcp-guard" target="_blank" rel="noopener">GitHub Repo</a> | |
| <a class="pill" href="https://huggingface.co/datasets/JTRSHM/MCP-Guard-Bench" target="_blank" rel="noopener">HF Dataset: MCP-Guard-Bench</a> | |
| </div> | |
| </div> | |
| <div class="tabs"> | |
| <button class="tab-btn active" onclick="switchTab('audit', this)">Security & Schema Audit</button> | |
| <button class="tab-btn" onclick="switchTab('bench', this)">Live 50-Sample Benchmark</button> | |
| <button class="tab-btn" onclick="switchTab('chaos', this)">Chaos Fault Simulator</button> | |
| <button class="tab-btn" onclick="switchTab('rules', this)">20 Built-in Rules</button> | |
| </div> | |
| <div id="tab-audit" class="tab-pane active"> | |
| <div class="grid"> | |
| <div class="card"> | |
| <div class="row"> | |
| <label for="presetSel"><strong>Preset:</strong></label> | |
| <select id="presetSel" onchange="loadPreset()"></select> | |
| <button class="primary" onclick="runAudit()">Run Scan</button> | |
| </div> | |
| <textarea id="toolInput" spellcheck="false"></textarea> | |
| </div> | |
| <div class="card"> | |
| <div class="row" style="justify-content:space-between;"> | |
| <div><strong>Security Score:</strong> <span id="scoreVal" class="score">--</span></div> | |
| <div id="countsVal" style="color:var(--muted);font-size:13px;"></div> | |
| </div> | |
| <div id="findingsList" style="max-height:220px;overflow:auto;margin-bottom:12px;"></div> | |
| <div class="row" style="justify-content:space-between;margin-bottom:6px;"> | |
| <strong>SARIF 2.1.0 Output</strong> | |
| <button class="secondary" onclick="downloadSarif()">Download .sarif</button> | |
| </div> | |
| <pre id="sarifOut">Click "Run Scan" to inspect findings.</pre> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="tab-bench" class="tab-pane"> | |
| <div class="card"> | |
| <div class="row" style="justify-content:space-between;"> | |
| <div> | |
| <strong>MCP-Guard-Bench (50 Synthetic Tools: 25 Benign + 25 Poisoned)</strong> | |
| <div id="benchStats" style="color:var(--muted);font-size:13px;margin-top:4px;">Click "Run Full Benchmark" to evaluate all 50 samples in-browser.</div> | |
| </div> | |
| <button class="primary" onclick="runBenchmark()">Run Full Benchmark</button> | |
| </div> | |
| <div style="max-height:440px;overflow:auto;"> | |
| <table> | |
| <thead><tr><th>ID</th><th>Group</th><th>Attack Type</th><th>Expected Rules</th><th>Detected Rules</th><th>Result</th><th>Action</th></tr></thead> | |
| <tbody id="benchBody"></tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| <div id="tab-chaos" class="tab-pane"> | |
| <div class="card"> | |
| <div class="row"> | |
| <strong>Chaos Fault Proxy Simulator</strong> | |
| <input id="chaosTool" value="get_weather_forecast" placeholder="Tool name" /> | |
| <select id="chaosFault"> | |
| <option value="rate_limit_429">rate_limit_429</option> | |
| <option value="timeout">timeout</option> | |
| <option value="internal_error_500">internal_error_500</option> | |
| <option value="malformed_json">malformed_json</option> | |
| <option value="schema_drift">schema_drift</option> | |
| <option value="empty_result">empty_result</option> | |
| </select> | |
| <button class="primary" onclick="runChaos()">Simulate Fault Injection</button> | |
| </div> | |
| <pre id="chaosOut">Select a fault mode to inspect injected JSON-RPC payload or timeout behavior.</pre> | |
| </div> | |
| </div> | |
| <div id="tab-rules" class="tab-pane"> | |
| <div class="card" style="max-height:520px;overflow:auto;"> | |
| <table> | |
| <thead><tr><th>Rule ID</th><th>Severity</th><th>Category</th><th>Title & Remediation</th></tr></thead> | |
| <tbody id="rulesBody"></tbody> | |
| </table> | |
| </div> | |
| </div> | |
| </div> | |
| <script src="data.js"></script> | |
| <script src="engine.js"></script> | |
| <script> | |
| function esc(s) { | |
| return String(s).replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,"""); | |
| } | |
| function switchTab(id, btn) { | |
| document.querySelectorAll(".tab-pane").forEach((p) => p.classList.remove("active")); | |
| document.querySelectorAll(".tab-btn").forEach((b) => b.classList.remove("active")); | |
| document.getElementById("tab-" + id).classList.add("active"); | |
| btn.classList.add("active"); | |
| } | |
| let latestSarif = null; | |
| const presetSel = document.getElementById("presetSel"); | |
| const presetKeys = Object.keys(window.MCP_PRESETS || {}); | |
| presetKeys.forEach((k) => { | |
| const o = document.createElement("option"); | |
| o.value = k; o.textContent = k; | |
| presetSel.appendChild(o); | |
| }); | |
| if (presetKeys.length > 2) presetSel.selectedIndex = 2; | |
| function loadPreset() { | |
| document.getElementById("toolInput").value = JSON.stringify(window.MCP_PRESETS[presetSel.value], null, 2); | |
| runAudit(); | |
| } | |
| function runAudit() { | |
| try { | |
| const res = window.MCPGuardEngine.auditTools(document.getElementById("toolInput").value, true); | |
| latestSarif = res.sarif; | |
| const scoreEl = document.getElementById("scoreVal"); | |
| scoreEl.textContent = res.security_score + " / 100"; | |
| scoreEl.style.color = res.security_score >= 85 ? "#10b981" : (res.security_score >= 60 ? "#f59e0b" : "#ef4444"); | |
| document.getElementById("countsVal").textContent = `Tools: ${res.tools_scanned} | Findings: ${res.findings.length}`; | |
| const list = document.getElementById("findingsList"); | |
| if (!res.findings.length) { | |
| list.innerHTML = "<div style='color:#34d399;padding:8px;'>[PASS] Zero security or schema violations detected.</div>"; | |
| } else { | |
| list.innerHTML = res.findings.map((f) => | |
| `<div style='border-bottom:1px solid #1f2937;padding:7px 0;'> | |
| <span class='badge ${esc(f.severity)}'>${esc(f.severity)}</span> | |
| <code>${esc(f.rule_id)}</code> <strong>${esc(f.tool_name)}</strong> | |
| <div style='color:#d1d5db;font-size:12px;margin-top:3px;'>${esc(f.message)}</div> | |
| </div>` | |
| ).join(""); | |
| } | |
| document.getElementById("sarifOut").textContent = JSON.stringify(res.sarif, null, 2); | |
| } catch (err) { | |
| document.getElementById("findingsList").innerHTML = `<div style='color:#f87171;'>JSON Parse Error: ${esc(err.message)}</div>`; | |
| } | |
| } | |
| function downloadSarif() { | |
| if (!latestSarif) return; | |
| const blob = new Blob([JSON.stringify(latestSarif, null, 2)], { type: "application/sarif+json" }); | |
| const a = document.createElement("a"); | |
| a.href = URL.createObjectURL(blob); | |
| a.download = "mcp-guard-audit.sarif"; | |
| a.click(); | |
| } | |
| function loadSampleIntoEditor(idx) { | |
| const rec = window.MCP_BENCHMARK[idx]; | |
| const payload = rec.tools ? { tools: rec.tools } : { tools: [rec.tool] }; | |
| document.getElementById("toolInput").value = JSON.stringify(payload, null, 2); | |
| switchTab("audit", document.querySelector(".tab-btn")); | |
| runAudit(); | |
| } | |
| function runBenchmark() { | |
| const rows = window.MCP_BENCHMARK || []; | |
| let tp = 0, fp = 0, tn = 0, fn = 0; | |
| const htmlRows = rows.map((rec, idx) => { | |
| const payload = rec.tools ? { tools: rec.tools } : { tools: [rec.tool] }; | |
| const res = window.MCPGuardEngine.auditTools(JSON.stringify(payload), false); | |
| const triggered = [...new Set(res.findings.map((f) => f.rule_id))]; | |
| const expected = rec.expected_rule_ids || []; | |
| let ok = false; | |
| if (rec.split_group === "benign") { | |
| ok = triggered.length === 0; | |
| if (ok) tn++; else fp++; | |
| } else { | |
| ok = expected.every((id) => triggered.includes(id)) && triggered.length > 0; | |
| if (ok) tp++; else fn++; | |
| } | |
| return `<tr> | |
| <td><code>${esc(rec.id)}</code></td> | |
| <td>${esc(rec.split_group)}</td> | |
| <td>${esc(rec.attack_type || "benign")}</td> | |
| <td>${esc(expected.join(", ") || "-")}</td> | |
| <td>${esc(triggered.join(", ") || "-")}</td> | |
| <td><span class='badge ${ok ? "PASS" : "CRITICAL"}'>${ok ? "PASS" : "MISS"}</span></td> | |
| <td><button class='secondary' onclick='loadSampleIntoEditor(${idx})'>Inspect</button></td> | |
| </tr>`; | |
| }); | |
| const prec = tp / Math.max(1, tp + fp); | |
| const recScore = tp / Math.max(1, tp + fn); | |
| document.getElementById("benchStats").innerHTML = | |
| `Precision: <strong>${(prec * 100).toFixed(1)}%</strong> | Recall: <strong>${(recScore * 100).toFixed(1)}%</strong> | False Positives: <strong>${fp}</strong>`; | |
| document.getElementById("benchBody").innerHTML = htmlRows.join(""); | |
| } | |
| function runChaos() { | |
| const t = document.getElementById("chaosTool").value; | |
| const f = document.getElementById("chaosFault").value; | |
| document.getElementById("chaosOut").textContent = JSON.stringify(window.MCPGuardEngine.simulateChaos(t, f, "{}"), null, 2); | |
| } | |
| document.getElementById("rulesBody").innerHTML = (window.MCP_RULES || []).map((r) => | |
| `<tr> | |
| <td><code>${esc(r.rule_id)}</code></td> | |
| <td><span class='badge ${esc(r.severity)}'>${esc(r.severity)}</span></td> | |
| <td>${esc(r.category)}</td> | |
| <td><strong>${esc(r.title)}</strong><div style='color:#9ca3af;font-size:12px;'>${esc(r.description)}</div></td> | |
| </tr>` | |
| ).join(""); | |
| loadPreset(); | |
| </script> | |
| </body> | |
| </html> | |