Skip to content
Source
Sign inSign up
Open History to see the last commit

mcpOAuthHtml.ts

41 lines1.3 KB

1const escapeHtml = (value: string) =>
2 value.replace(
3 /[&<>"']/gu,
4 (character) =>
5 ({ "&": "&amp;", "<": "&lt;", ">": "&gt;", '"': "&quot;", "'": "&#39;" })[character]!,
6 );
7​
8const STYLES = `
9 :root { color-scheme: light dark; font-family: ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
10 body { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; background: #f6f7f9; color: #17191f; }
11 main { width: min(100%, 440px); }
12 h1 { margin: 0 0 8px; font-size: 20px; }
13 p { margin: 0 0 12px; line-height: 1.5; color: #4b5060; }
14 @media (prefers-color-scheme: dark) {
15 body { background: #0f1115; color: #e6e8ee; }
16 p { color: #a0a6b4; }
17 }
18`;
19​
20const shell = (title: string, body: string) => `<!doctype html>
21<html lang="en">
22 <head>
23 <meta charset="utf-8" />
24 <meta name="viewport" content="width=device-width, initial-scale=1" />
25 <meta name="color-scheme" content="light dark" />
26 <title>${escapeHtml(title)}</title>
27 <style>${STYLES}</style>
28 </head>
29 <body>
30 <main>${body}</main>
31 </body>
32</html>`;
33​
34export function renderErrorPage(description: string): string {
35 return shell(
36 "Sign-in failed",
37 `<h1>This sign-in cannot continue</h1>
38 <p>${escapeHtml(description)}</p>
39 <p>Close this page and start the sign-in again from your agent.</p>`,
40 );