UNPKG

@adeu/mcp-server

Version:

[![GitHub Repo stars](https://img.shields.io/github/stars/dealfluence/adeu?style=social)](https://github.com/dealfluence/adeu) [![MCP Compatible](https://img.shields.io/badge/MCP-Compatible-green.svg)](https://modelcontextprotocol.io/) [![License: MIT](ht

801 lines (703 loc) • 27.5 kB
<!-- FILE: src/adeu/templates/markdown_ui.html --> <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Adeu Markdown UI</title> <meta name="color-scheme" content="light dark"> <link rel="preconnect" href="https://fonts.googleapis.com"> <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin> <link href="https://fonts.googleapis.com/css2?family=Jost:wght@400;500;600&family=Lora:ital,wght@0,600;1,600&display=swap" rel="stylesheet"> <style> :root { --brand-sand: #e8c0a1; --brand-sand-light: #f2d9c7; --brand-sand-dark: #d4a882; --brand-mint: #e6f3f0; --brand-mint-dark: #c9e4de; --brand-navy: #1a2a2c; --brand-navy-light: #2a3a3c; --brand-mauve: #dacad2; --neutral-50: #fafafa; --neutral-100: #f5f5f5; --neutral-200: #e5e5e5; --neutral-300: #d9d9d9; --neutral-600: #555969; --neutral-800: #1e2028; --neutral-900: #171717; --font-lora: 'Lora', Georgia, serif; --font-jost: 'Jost', system-ui, -apple-system, BlinkMacSystemFont, sans-serif; --bg-body: var(--neutral-50); --bg-card: #ffffff; --border-card: var(--neutral-200); --text-main: var(--neutral-600); --text-heading: var(--brand-navy); --bg-blockquote: rgba(232, 192, 161, 0.15); /* Dedicated skeleton stops. Do NOT derive these from --neutral-100 and --border-card: in dark mode both resolve to --brand-navy-light, the gradient collapses to one flat colour, and the shimmer sweeps invisibly. */ --skeleton-base: var(--neutral-100); --skeleton-sheen: #dcdcdc; } @media (prefers-color-scheme: dark) { :root { --bg-body: var(--neutral-900); --bg-card: var(--brand-navy); --border-card: var(--brand-navy-light); --text-main: rgba(255, 255, 255, 0.85); --text-heading: #ffffff; --bg-blockquote: rgba(232, 192, 161, 0.1); --neutral-100: var(--brand-navy-light); --skeleton-base: var(--brand-navy-light); --skeleton-sheen: #3f5559; } } html, body { margin: 0; padding: 0; box-sizing: border-box; background-color: transparent; } body { font-family: var(--font-jost); color: var(--text-main); line-height: 1.6; -webkit-font-smoothing: antialiased; padding: 16px; } .adeu-card { background-color: var(--bg-card); border: 1px solid var(--border-card); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; } .navbar { flex-shrink: 0; background-color: var(--bg-card); padding: 16px 32px; border-bottom: 1px solid var(--border-card); display: flex; align-items: center; justify-content: space-between; position: relative; } .logo-container { display: flex; align-items: center; flex: 1; } .nav-title { position: absolute; left: 50%; transform: translateX(-50%); font-family: var(--font-lora); font-weight: 600; color: var(--text-heading); font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 40%; text-align: center; } .nav-actions { display: flex; align-items: center; justify-content: flex-end; flex: 1; } #copy-btn { display: none; align-items: center; gap: 6px; background: transparent; border: none; color: var(--text-main); font-family: var(--font-jost); font-size: 0.85rem; font-weight: 500; cursor: pointer; padding: 8px; border-radius: 6px; transition: all 0.2s ease; } #copy-btn:hover { color: var(--text-heading); background: var(--neutral-100); } #open-btn { display: none; align-items: center; gap: 6px; background: transparent; border: none; color: var(--text-main); font-family: var(--font-jost); font-size: 0.85rem; font-weight: 500; cursor: pointer; padding: 8px; border-radius: 6px; transition: all 0.2s ease; } #open-btn:hover { color: var(--text-heading); background: var(--neutral-100); } @media (prefers-color-scheme: dark) { #copy-btn:hover { background: var(--brand-navy-light); } #open-btn:hover { background: var(--brand-navy-light); } } .logo-container svg { max-width: 80px; height: auto; } .logo-container svg path, .logo-container svg rect, .logo-container svg polygon, .logo-container svg circle { transition: fill 0.2s ease; } @media (prefers-color-scheme: dark) { .logo-container svg path, .logo-container svg rect, .logo-container svg polygon, .logo-container svg circle, .logo-container svg { fill: #ffffff !important; } } .content-wrapper { position: relative; } .content-wrapper::-webkit-scrollbar { width: 6px; } .content-wrapper::-webkit-scrollbar-track { background: transparent; } .content-wrapper::-webkit-scrollbar-thumb { background-color: var(--border-card); border-radius: 4px; } #app { padding: 32px; display: flow-root; } .fade-overlay { position: absolute; bottom: 0; left: 0; right: 0; height: 80px; background: linear-gradient(to bottom, rgba(255, 255, 255, 0), var(--bg-card)); pointer-events: none; display: none; } @media (prefers-color-scheme: dark) { .fade-overlay { background: linear-gradient(to bottom, rgba(26, 42, 44, 0), var(--bg-card)); } } .toggle-container { flex-shrink: 0; display: none; justify-content: center; align-items: center; padding: 12px; border-top: 1px solid var(--border-card); background-color: var(--bg-card); } #toggle-btn { background: transparent; border: none; color: var(--brand-sand-dark); font-family: var(--font-jost); font-weight: 600; font-size: 0.95rem; cursor: pointer; display: flex; align-items: center; gap: 6px; padding: 8px 16px; border-radius: 6px; transition: all 0.2s ease; } #toggle-btn:hover { color: var(--text-heading); background: var(--neutral-100); } @media (prefers-color-scheme: dark) { #toggle-btn:hover { background: var(--brand-navy-light); } } #toggle-icon { transition: transform 0.3s ease; } h1, h2, h3, h4 { font-family: var(--font-lora); color: var(--text-heading); font-weight: 600; letter-spacing: -0.02em; margin-top: 1.5em; margin-bottom: 0.5em; } h1 { font-size: 2.25rem; border-bottom: 1px solid var(--border-card); padding-bottom: 0.3em; margin-top: 0; } h2 { font-size: 1.75rem; } h3 { font-size: 1.25rem; } a { color: var(--brand-sand-dark); text-decoration: none; border-bottom: 1px solid transparent; transition: border 0.2s ease; } a:hover { border-bottom-color: var(--brand-sand-dark); } strong { font-weight: 600; color: var(--text-heading); } ul, ol { padding-left: 1.5rem; margin-bottom: 1rem; } li { margin-bottom: 0.5rem; } blockquote { border-left: 4px solid var(--brand-sand); padding: 12px 20px; margin: 24px 0; color: var(--text-main); background: var(--bg-blockquote); border-radius: 0 8px 8px 0; font-style: italic; } code { font-family: ui-monospace, SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace; font-size: 0.85em; background: var(--neutral-100); color: var(--brand-sand-dark); padding: 0.2em 0.4em; border-radius: 4px; } pre code { display: block; padding: 16px; background: var(--neutral-900); color: #e5e5e5; border-radius: 8px; overflow-x: auto; } .skeleton { background: linear-gradient(90deg, var(--skeleton-base) 25%, var(--skeleton-sheen) 50%, var(--skeleton-base) 75%); background-size: 200% 100%; animation: skeleton 1.5s ease-in-out infinite; border-radius: 4px; } @keyframes skeleton { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } } .alert { padding: 16px; border-radius: 8px; margin-bottom: 20px; display: flex; flex-direction: column; gap: 8px; background-color: #fef2f2; border: 1px solid #fecaca; color: #991b1b; } @media (prefers-color-scheme: dark) { .alert { background-color: rgba(127, 29, 29, 0.2); border-color: rgba(248, 113, 113, 0.3); color: #fca5a5; } } .alert-title { font-weight: 600; font-size: 1.1em; margin: 0; display: flex; align-items: center; gap: 8px; font-family: var(--font-lora); } .alert-body { margin: 0; font-size: 0.95em; } .alert-details { background: rgba(0, 0, 0, 0.05); padding: 12px; border-radius: 6px; font-family: ui-monospace, Consolas, monospace; font-size: 0.85em; white-space: pre-wrap; word-break: break-all; margin-top: 8px; border: 1px solid rgba(0, 0, 0, 0.1); } </style> <script id="marked-script">[[marked_js_code | safe]]</script> </head> <body> <div class="adeu-card"> <nav class="navbar"> <div class="logo-container"> [[ adeu_svg_code ]] </div> <div class="nav-title" id="nav-title"></div> <div class="nav-actions"> <button id="copy-btn" title="Copy Markdown"> <svg id="copy-icon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <rect x="9" y="9" width="13" height="13" rx="2" ry="2"></rect> <path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path> </svg> <span id="copy-text" style="display: none;"></span> </button> <button id="open-btn" title="Open in Native App"> <svg id="open-icon" width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"></path> <polyline points="15 3 21 3 21 9"></polyline> <line x1="10" y1="14" x2="21" y2="3"></line> </svg> <span id="open-text" style="display: none;"></span> </button> </div> </nav> <div class="content-wrapper" id="content-wrapper"> <div id="app"> <div class="skeleton" style="height: 36px; width: 40%; margin-bottom: 24px;"></div> <div class="skeleton" style="height: 16px; width: 100%; margin-bottom: 12px;"></div> <div class="skeleton" style="height: 16px; width: 95%; margin-bottom: 12px;"></div> <div class="skeleton" style="height: 16px; width: 90%; margin-bottom: 24px;"></div> <div class="skeleton" style="height: 16px; width: 80%; margin-bottom: 12px;"></div> </div> <div class="fade-overlay" id="fade-overlay"></div> </div> <div class="toggle-container" id="toggle-container"> <button id="toggle-btn"> <span id="toggle-text">Show More</span> <svg id="toggle-icon" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" style="transform: rotate(0deg);"> <polyline points="6 9 12 15 18 9"></polyline> </svg> </button> </div> </div> <script> const appDiv = document.getElementById('app'); const INIT_ID = 1; let isExpanded = false; // START COLLAPSED BY DEFAULT! let rawMarkdownText = ""; let currentFilePath = null; const navTitle = document.getElementById('nav-title'); const copyBtn = document.getElementById('copy-btn'); const copyIcon = document.getElementById('copy-icon'); const copyText = document.getElementById('copy-text'); const openBtn = document.getElementById('open-btn'); const openText = document.getElementById('open-text'); function fallbackCopyTextToClipboard(text) { return new Promise((resolve, reject) => { const textArea = document.createElement("textarea"); textArea.value = text; textArea.style.top = "0"; textArea.style.left = "0"; textArea.style.position = "fixed"; textArea.style.opacity = "0"; document.body.appendChild(textArea); textArea.focus(); textArea.select(); try { const successful = document.execCommand('copy'); if (successful) { resolve(); } else { reject(new Error("execCommand returned false")); } } catch (err) { reject(err); } finally { document.body.removeChild(textArea); } }); } copyBtn.addEventListener('click', async () => { try { if (navigator.clipboard && window.isSecureContext) { try { await navigator.clipboard.writeText(rawMarkdownText); } catch (e) { await fallbackCopyTextToClipboard(rawMarkdownText); } } else { await fallbackCopyTextToClipboard(rawMarkdownText); } const originalSvg = copyIcon.innerHTML; copyIcon.innerHTML = `<polyline points="20 6 9 17 4 12"></polyline>`; copyText.textContent = "Copied!"; copyText.style.display = "inline"; copyBtn.style.color = "#10b981"; setTimeout(() => { copyIcon.innerHTML = originalSvg; copyText.textContent = ""; copyText.style.display = "none"; copyBtn.style.color = ""; }, 2000); } catch (err) { console.error('Failed to copy text: ', err); copyText.textContent = "Failed"; copyText.style.display = "inline"; copyBtn.title = err.toString(); setTimeout(() => { copyText.textContent = ""; copyText.style.display = "none"; copyBtn.title = "Copy Markdown"; }, 3000); } }); openBtn.addEventListener('click', () => { if (!currentFilePath) return; const reqId = Date.now(); window.parent.postMessage({ jsonrpc: "2.0", id: reqId, method: "tools/call", params: { name: "open_local_file", arguments: { file_path: currentFilePath } } }, "*"); openText.textContent = "Opening..."; openText.style.display = "inline"; setTimeout(() => { openText.style.display = "none"; openText.textContent = ""; }, 2000); }); function escapeHtml(unsafe) { return (unsafe || "").toString() .replace(/&/g, "&amp;") .replace(/</g, "&lt;") .replace(/>/g, "&gt;") .replace(/"/g, "&quot;") .replace(/'/g, "&#039;"); } function showError(title, message, details = null) { let html = ` <div class="alert"> <div class="alert-title"> <svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="10"></circle><line x1="12" y1="8" x2="12" y2="12"></line><line x1="12" y1="16" x2="12.01" y2="16"></line></svg> ${escapeHtml(title)} </div> <div class="alert-body">${escapeHtml(message)}</div> `; if (details) { html += `<div class="alert-details">${escapeHtml(details)}</div>`; } html += `</div>`; appDiv.innerHTML = html; } // Hosts forward `structuredContent` only when the tool declares an // outputSchema, and not every host does even then — Claude Desktop was // observed handing the app `{content, isError}` alone, which used to // blank the viewer. Prefer the structured payload, fall back to the // text content block so a stripped result still renders. const FILE_PATH_BANNER = /^>\s*\*\*File Path:\*\*\s*`([^`]+)`/m; function readToolResult(result) { const sc = result.structuredContent || {}; if (sc.markdown) { return { markdown: sc.markdown, title: sc.title, file_path: sc.file_path, status: sc.status }; } const textBlock = (result.content || []).find( (b) => b && b.type === "text" && b.text ); if (!textBlock) return { status: sc.status }; const match = textBlock.text.match(FILE_PATH_BANNER); const filePath = sc.file_path || (match ? match[1] : null); return { markdown: textBlock.text, title: sc.title || (filePath ? filePath.split(/[\\/]/).pop() : null), file_path: filePath, status: sc.status, }; } function setHidden(hidden) { if (hidden) { document.documentElement.style.display = 'none'; window.parent.postMessage({ jsonrpc: "2.0", method: "ui/notifications/size-changed", params: { height: 0, width: 0 } }, "*"); } else { document.documentElement.style.display = ''; } } function checkCollapsible() { const wrapper = document.getElementById('content-wrapper'); const toggleContainer = document.getElementById('toggle-container'); const fadeOverlay = document.getElementById('fade-overlay'); const toggleIcon = document.getElementById('toggle-icon'); const toggleText = document.getElementById('toggle-text'); // 1. If no markdown, we are showing the skeleton. Do not collapse! if (!rawMarkdownText) { toggleContainer.style.display = 'none'; wrapper.style.maxHeight = 'none'; wrapper.style.overflowY = 'visible'; fadeOverlay.style.display = 'none'; triggerResize(); return; } // 2. Data is loaded const realHeight = appDiv.scrollHeight; const COLLAPSE_THRESHOLD = 300; const COLLAPSED_HEIGHT = 150; const EXPANDED_MAX_HEIGHT = 500; if (realHeight > COLLAPSE_THRESHOLD) { toggleContainer.style.display = 'flex'; if (isExpanded) { // Open view! Scroll inside max 500px window wrapper.style.maxHeight = EXPANDED_MAX_HEIGHT + 'px'; wrapper.style.overflowY = 'auto'; fadeOverlay.style.display = 'none'; toggleIcon.style.transform = 'rotate(180deg)'; toggleText.textContent = 'Show Less'; } else { // Collapsed View wrapper.style.maxHeight = COLLAPSED_HEIGHT + 'px'; wrapper.style.overflowY = 'hidden'; fadeOverlay.style.display = 'block'; toggleIcon.style.transform = 'rotate(0deg)'; toggleText.textContent = 'Show More'; } } else { toggleContainer.style.display = 'none'; wrapper.style.maxHeight = 'none'; wrapper.style.overflowY = 'visible'; fadeOverlay.style.display = 'none'; } triggerResize(); } document.getElementById('toggle-btn').addEventListener('click', () => { isExpanded = !isExpanded; checkCollapsible(); }); function triggerResize() { // Measure the exact unconstrained height of the outer card const card = document.querySelector('.adeu-card'); const containerChrome = 34; // 16px padding top/bottom + 2px borders const requestedHeight = card.offsetHeight + containerChrome; window.parent.postMessage({ jsonrpc: "2.0", method: "ui/notifications/size-changed", params: { height: Math.ceil(requestedHeight), width: 600 } }, "*"); } window.addEventListener("message", (event) => { try { if (!event.data || event.data.jsonrpc !== "2.0") return; const msg = event.data; if (msg.id === INIT_ID) { window.parent.postMessage({ jsonrpc: "2.0", method: "ui/notifications/initialized", params: {} }, "*"); return; } if (msg.method === "ui/notifications/tool-result") { if (window.__MARKED_ERROR || typeof marked === 'undefined') { showError("Missing Dependency", "The Markdown renderer failed to load.", window.__MARKED_ERROR || "marked is undefined."); return; } const result = msg.params || {}; const view = readToolResult(result); // If the state is pending, or nothing renderable came back, // hide the UI. Reversible: a later result can bring it back. if (view.status === "pending" || !view.markdown) { setHidden(true); return; } setHidden(false); // Render Markdown rawMarkdownText = view.markdown; if (view.file_path) { currentFilePath = view.file_path; openBtn.style.display = 'flex'; } else { currentFilePath = null; openBtn.style.display = 'none'; } appDiv.innerHTML = marked.parse(rawMarkdownText); copyBtn.style.display = 'flex'; if (view.title) { navTitle.textContent = view.title; navTitle.title = view.title; } // Never rely solely on the ResizeObserver to report height: // if it does not fire, the host is left with no size at all. checkCollapsible(); } } catch (error) { showError("Rendering Engine Error", "An unexpected error occurred.", error.toString() + "\n" + error.stack); } }); const observer = new ResizeObserver(() => { checkCollapsible(); }); observer.observe(appDiv); // The ResizeObserver is not a guaranteed trigger — if it never fires, // the host is left with no height for the frame at all. Report ours // explicitly a few times after boot as a floor. [50, 400, 1500].forEach((ms) => setTimeout(checkCollapsible, ms)); window.parent.postMessage({ jsonrpc: "2.0", id: INIT_ID, method: "ui/initialize", params: { appInfo: { name: "Adeu Markdown UI", version: "1.1.0" }, appCapabilities: {}, protocolVersion: "2025-11-21" } }, "*"); </script> </body> </html>