cache-overflow-mcp 0.3.4 → 0.3.6

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.
Files changed (43) hide show
  1. package/.env.example +3 -3
  2. package/AGENTS.md +24 -3
  3. package/README.md +59 -0
  4. package/TROUBLESHOOTING.md +219 -0
  5. package/dist/cli.js +13 -1
  6. package/dist/cli.js.map +1 -1
  7. package/dist/client.d.ts.map +1 -1
  8. package/dist/client.js +65 -10
  9. package/dist/client.js.map +1 -1
  10. package/dist/config.d.ts +3 -0
  11. package/dist/config.d.ts.map +1 -1
  12. package/dist/config.js +5 -0
  13. package/dist/config.js.map +1 -1
  14. package/dist/logger.d.ts +16 -0
  15. package/dist/logger.d.ts.map +1 -0
  16. package/dist/logger.js +127 -0
  17. package/dist/logger.js.map +1 -0
  18. package/dist/server.d.ts.map +1 -1
  19. package/dist/server.js +50 -7
  20. package/dist/server.js.map +1 -1
  21. package/dist/testing/mock-data.js +40 -40
  22. package/dist/ui/verification-dialog.d.ts.map +1 -1
  23. package/dist/ui/verification-dialog.js +307 -268
  24. package/dist/ui/verification-dialog.js.map +1 -1
  25. package/package.json +3 -2
  26. package/scripts/view-logs.js +125 -0
  27. package/src/cli.ts +23 -10
  28. package/src/client.test.ts +116 -116
  29. package/src/client.ts +138 -76
  30. package/src/config.ts +14 -9
  31. package/src/index.ts +3 -3
  32. package/src/logger.ts +150 -0
  33. package/src/server.ts +49 -7
  34. package/src/testing/mock-data.ts +142 -142
  35. package/src/testing/mock-server.ts +176 -176
  36. package/src/tools/index.ts +23 -23
  37. package/src/types.ts +39 -39
  38. package/src/ui/verification-dialog.ts +382 -342
  39. package/tsconfig.json +20 -20
  40. package/dist/tools/get-balance.d.ts +0 -3
  41. package/dist/tools/get-balance.d.ts.map +0 -1
  42. package/dist/tools/get-balance.js +0 -34
  43. package/dist/tools/get-balance.js.map +0 -1
@@ -1,342 +1,382 @@
1
- import http from 'http';
2
- import open from 'open';
3
-
4
- const generateHTML = (title: string, body?: string): string => `
5
- <!DOCTYPE html>
6
- <html lang="en">
7
- <head>
8
- <meta charset="UTF-8">
9
- <meta name="viewport" content="width=device-width, initial-scale=1.0">
10
- <title>Verify Solution | cache.overflow</title>
11
- <link rel="preconnect" href="https://fonts.googleapis.com">
12
- <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
13
- <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
14
- <style>
15
- * {
16
- margin: 0;
17
- padding: 0;
18
- box-sizing: border-box;
19
- }
20
-
21
- body {
22
- font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
23
- background: #0A0A0B;
24
- min-height: 100vh;
25
- display: flex;
26
- align-items: center;
27
- justify-content: center;
28
- padding: 24px;
29
- color: #fff;
30
- }
31
-
32
- .card {
33
- background: linear-gradient(145deg, rgba(30, 30, 32, 0.9), rgba(20, 20, 22, 0.95));
34
- border: 1px solid rgba(255, 255, 255, 0.06);
35
- border-radius: 20px;
36
- padding: 48px;
37
- max-width: 800px;
38
- width: 100%;
39
- backdrop-filter: blur(20px);
40
- box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
41
- }
42
-
43
- .badge {
44
- display: inline-flex;
45
- align-items: center;
46
- gap: 8px;
47
- background: rgba(139, 92, 246, 0.15);
48
- border: 1px solid rgba(139, 92, 246, 0.3);
49
- color: #A78BFA;
50
- font-size: 13px;
51
- font-weight: 500;
52
- text-transform: uppercase;
53
- letter-spacing: 0.5px;
54
- padding: 10px 18px;
55
- border-radius: 24px;
56
- margin-bottom: 28px;
57
- }
58
-
59
- .badge::before {
60
- content: "";
61
- width: 6px;
62
- height: 6px;
63
- background: #8B5CF6;
64
- border-radius: 50%;
65
- animation: pulse 2s ease-in-out infinite;
66
- }
67
-
68
- @keyframes pulse {
69
- 0%, 100% { opacity: 1; transform: scale(1); }
70
- 50% { opacity: 0.5; transform: scale(1.2); }
71
- }
72
-
73
- h1 {
74
- font-size: 32px;
75
- font-weight: 600;
76
- color: #fff;
77
- margin-bottom: 12px;
78
- letter-spacing: -0.5px;
79
- }
80
-
81
- .subtitle {
82
- font-size: 18px;
83
- color: rgba(255, 255, 255, 0.5);
84
- margin-bottom: 32px;
85
- line-height: 1.5;
86
- }
87
-
88
- .solution-card {
89
- background: rgba(255, 255, 255, 0.03);
90
- border: 1px solid rgba(255, 255, 255, 0.06);
91
- border-radius: 16px;
92
- padding: 28px;
93
- margin-bottom: 36px;
94
- }
95
-
96
- .solution-title {
97
- font-size: 20px;
98
- font-weight: 500;
99
- color: #fff;
100
- margin-bottom: 16px;
101
- line-height: 1.4;
102
- }
103
-
104
- .solution-body {
105
- font-size: 16px;
106
- line-height: 1.8;
107
- color: rgba(255, 255, 255, 0.6);
108
- max-height: 280px;
109
- overflow-y: auto;
110
- white-space: pre-wrap;
111
- word-wrap: break-word;
112
- }
113
-
114
- .solution-body::-webkit-scrollbar {
115
- width: 4px;
116
- }
117
-
118
- .solution-body::-webkit-scrollbar-track {
119
- background: transparent;
120
- }
121
-
122
- .solution-body::-webkit-scrollbar-thumb {
123
- background: rgba(255, 255, 255, 0.1);
124
- border-radius: 2px;
125
- }
126
-
127
- .buttons {
128
- display: flex;
129
- gap: 16px;
130
- }
131
-
132
- .btn {
133
- flex: 1;
134
- padding: 22px 36px;
135
- border: none;
136
- border-radius: 14px;
137
- font-family: inherit;
138
- font-size: 20px;
139
- font-weight: 600;
140
- cursor: pointer;
141
- transition: all 0.2s ease;
142
- position: relative;
143
- overflow: hidden;
144
- }
145
-
146
- .btn-safe {
147
- background: linear-gradient(135deg, #00FF41 0%, #00CC33 100%);
148
- color: #000;
149
- }
150
-
151
- .btn-safe:hover {
152
- transform: translateY(-2px);
153
- box-shadow: 0 8px 24px rgba(0, 255, 65, 0.35);
154
- }
155
-
156
- .btn-safe:active {
157
- transform: translateY(0);
158
- }
159
-
160
- .btn-unsafe {
161
- background: linear-gradient(135deg, #FF4444 0%, #CC2233 100%);
162
- color: #fff;
163
- }
164
-
165
- .btn-unsafe:hover {
166
- transform: translateY(-2px);
167
- box-shadow: 0 8px 24px rgba(255, 51, 51, 0.35);
168
- }
169
-
170
- .btn-unsafe:active {
171
- transform: translateY(0);
172
- }
173
-
174
- .hint {
175
- text-align: center;
176
- margin-top: 28px;
177
- font-size: 15px;
178
- color: rgba(255, 255, 255, 0.3);
179
- }
180
-
181
- .hint kbd {
182
- background: rgba(255, 255, 255, 0.1);
183
- padding: 4px 10px;
184
- border-radius: 6px;
185
- font-family: inherit;
186
- font-size: 14px;
187
- }
188
-
189
- .completed {
190
- text-align: center;
191
- padding: 60px 20px;
192
- }
193
-
194
- .completed-icon {
195
- width: 88px;
196
- height: 88px;
197
- border-radius: 50%;
198
- display: flex;
199
- align-items: center;
200
- justify-content: center;
201
- margin: 0 auto 28px;
202
- font-size: 40px;
203
- }
204
-
205
- .completed-icon.safe {
206
- background: linear-gradient(135deg, rgba(0, 255, 65, 0.2), rgba(0, 204, 51, 0.1));
207
- border: 2px solid rgba(0, 255, 65, 0.5);
208
- box-shadow: 0 0 32px rgba(0, 255, 65, 0.2);
209
- }
210
-
211
- .completed-icon.unsafe {
212
- background: linear-gradient(135deg, rgba(255, 68, 68, 0.2), rgba(204, 34, 51, 0.1));
213
- border: 2px solid rgba(255, 68, 68, 0.5);
214
- box-shadow: 0 0 32px rgba(255, 68, 68, 0.2);
215
- }
216
-
217
- .completed h2 {
218
- font-size: 28px;
219
- font-weight: 600;
220
- margin-bottom: 12px;
221
- }
222
-
223
- .completed p {
224
- font-size: 18px;
225
- color: rgba(255, 255, 255, 0.5);
226
- }
227
- </style>
228
- </head>
229
- <body>
230
- <div class="card" id="main-card">
231
- <div class="badge">Verification Required</div>
232
-
233
- <h1>Is this solution safe?</h1>
234
- <p class="subtitle">Review the code below and verify it's safe to use</p>
235
-
236
- <div class="solution-card">
237
- <div class="solution-title">${escapeHtml(title)}</div>
238
- <div class="solution-body">${body ? escapeHtml(body) : 'Solution body not available.\nUnlock to view full content.'}</div>
239
- </div>
240
-
241
- <div class="buttons">
242
- <button class="btn btn-safe" onclick="submit('safe')">Safe</button>
243
- <button class="btn btn-unsafe" onclick="submit('unsafe')">Unsafe</button>
244
- </div>
245
-
246
- <div class="hint">
247
- Press <kbd>S</kbd> for Safe or <kbd>U</kbd> for Unsafe
248
- </div>
249
- </div>
250
-
251
- <script>
252
- function submit(result) {
253
- const isSafe = result === 'safe';
254
- document.getElementById('main-card').innerHTML = \`
255
- <div class="completed">
256
- <div class="completed-icon \${result}">\${isSafe ? '&#10003;' : '&#10005;'}</div>
257
- <h2>\${isSafe ? 'Marked as Safe' : 'Marked as Unsafe'}</h2>
258
- <p>You can close this tab now</p>
259
- </div>
260
- \`;
261
- fetch('/result?value=' + result).catch(() => {});
262
- }
263
-
264
- document.addEventListener('keydown', (e) => {
265
- if (e.key === 's' || e.key === 'S') submit('safe');
266
- if (e.key === 'u' || e.key === 'U') submit('unsafe');
267
- });
268
- </script>
269
- </body>
270
- </html>
271
- `;
272
-
273
- function escapeHtml(text: string): string {
274
- return text
275
- .replace(/&/g, '&amp;')
276
- .replace(/</g, '&lt;')
277
- .replace(/>/g, '&gt;')
278
- .replace(/"/g, '&quot;')
279
- .replace(/'/g, '&#039;');
280
- }
281
-
282
- /**
283
- * Shows a modern verification dialog in the browser.
284
- * @param title The solution's query title
285
- * @param body The solution body (if available/unlocked)
286
- * @returns true if user clicked "Safe", false if "Unsafe", null if cancelled
287
- */
288
- export async function showVerificationDialog(
289
- title: string,
290
- body?: string
291
- ): Promise<boolean | null> {
292
- return new Promise((resolve) => {
293
- const html = generateHTML(title, body);
294
- let resolved = false;
295
-
296
- const server = http.createServer((req, res) => {
297
- const url = new URL(req.url || '/', `http://localhost`);
298
-
299
- if (url.pathname === '/result') {
300
- const value = url.searchParams.get('value');
301
- res.writeHead(200, { 'Content-Type': 'text/plain', 'Access-Control-Allow-Origin': '*' });
302
- res.end('OK');
303
-
304
- if (!resolved) {
305
- resolved = true;
306
- server.close();
307
-
308
- switch (value) {
309
- case 'safe':
310
- resolve(true);
311
- break;
312
- case 'unsafe':
313
- resolve(false);
314
- break;
315
- default:
316
- resolve(null);
317
- }
318
- }
319
- } else {
320
- res.writeHead(200, { 'Content-Type': 'text/html' });
321
- res.end(html);
322
- }
323
- });
324
-
325
- server.listen(0, 'localhost', () => {
326
- const address = server.address();
327
- if (address && typeof address === 'object') {
328
- const url = `http://localhost:${address.port}`;
329
- open(url);
330
-
331
- // Timeout after 55 seconds (within MCP client default 60s limit)
332
- setTimeout(() => {
333
- if (!resolved) {
334
- resolved = true;
335
- server.close();
336
- resolve(null);
337
- }
338
- }, 55 * 1000);
339
- }
340
- });
341
- });
342
- }
1
+ import http from 'http';
2
+ import open from 'open';
3
+ import { logger } from '../logger.js';
4
+
5
+ const generateHTML = (title: string, body?: string): string => `
6
+ <!DOCTYPE html>
7
+ <html lang="en">
8
+ <head>
9
+ <meta charset="UTF-8">
10
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
11
+ <title>Verify Solution | cache.overflow</title>
12
+ <link rel="preconnect" href="https://fonts.googleapis.com">
13
+ <link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
14
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap" rel="stylesheet">
15
+ <style>
16
+ * {
17
+ margin: 0;
18
+ padding: 0;
19
+ box-sizing: border-box;
20
+ }
21
+
22
+ body {
23
+ font-family: "Inter", -apple-system, BlinkMacSystemFont, sans-serif;
24
+ background: #0A0A0B;
25
+ min-height: 100vh;
26
+ display: flex;
27
+ align-items: center;
28
+ justify-content: center;
29
+ padding: 24px;
30
+ color: #fff;
31
+ }
32
+
33
+ .card {
34
+ background: linear-gradient(145deg, rgba(30, 30, 32, 0.9), rgba(20, 20, 22, 0.95));
35
+ border: 1px solid rgba(255, 255, 255, 0.06);
36
+ border-radius: 20px;
37
+ padding: 48px;
38
+ max-width: 800px;
39
+ width: 100%;
40
+ backdrop-filter: blur(20px);
41
+ box-shadow: 0 24px 48px rgba(0, 0, 0, 0.4);
42
+ }
43
+
44
+ .badge {
45
+ display: inline-flex;
46
+ align-items: center;
47
+ gap: 8px;
48
+ background: rgba(139, 92, 246, 0.15);
49
+ border: 1px solid rgba(139, 92, 246, 0.3);
50
+ color: #A78BFA;
51
+ font-size: 13px;
52
+ font-weight: 500;
53
+ text-transform: uppercase;
54
+ letter-spacing: 0.5px;
55
+ padding: 10px 18px;
56
+ border-radius: 24px;
57
+ margin-bottom: 28px;
58
+ }
59
+
60
+ .badge::before {
61
+ content: "";
62
+ width: 6px;
63
+ height: 6px;
64
+ background: #8B5CF6;
65
+ border-radius: 50%;
66
+ animation: pulse 2s ease-in-out infinite;
67
+ }
68
+
69
+ @keyframes pulse {
70
+ 0%, 100% { opacity: 1; transform: scale(1); }
71
+ 50% { opacity: 0.5; transform: scale(1.2); }
72
+ }
73
+
74
+ h1 {
75
+ font-size: 32px;
76
+ font-weight: 600;
77
+ color: #fff;
78
+ margin-bottom: 12px;
79
+ letter-spacing: -0.5px;
80
+ }
81
+
82
+ .subtitle {
83
+ font-size: 18px;
84
+ color: rgba(255, 255, 255, 0.5);
85
+ margin-bottom: 32px;
86
+ line-height: 1.5;
87
+ }
88
+
89
+ .solution-card {
90
+ background: rgba(255, 255, 255, 0.03);
91
+ border: 1px solid rgba(255, 255, 255, 0.06);
92
+ border-radius: 16px;
93
+ padding: 28px;
94
+ margin-bottom: 36px;
95
+ }
96
+
97
+ .solution-title {
98
+ font-size: 20px;
99
+ font-weight: 500;
100
+ color: #fff;
101
+ margin-bottom: 16px;
102
+ line-height: 1.4;
103
+ }
104
+
105
+ .solution-body {
106
+ font-size: 16px;
107
+ line-height: 1.8;
108
+ color: rgba(255, 255, 255, 0.6);
109
+ max-height: 280px;
110
+ overflow-y: auto;
111
+ white-space: pre-wrap;
112
+ word-wrap: break-word;
113
+ }
114
+
115
+ .solution-body::-webkit-scrollbar {
116
+ width: 4px;
117
+ }
118
+
119
+ .solution-body::-webkit-scrollbar-track {
120
+ background: transparent;
121
+ }
122
+
123
+ .solution-body::-webkit-scrollbar-thumb {
124
+ background: rgba(255, 255, 255, 0.1);
125
+ border-radius: 2px;
126
+ }
127
+
128
+ .buttons {
129
+ display: flex;
130
+ gap: 16px;
131
+ }
132
+
133
+ .btn {
134
+ flex: 1;
135
+ padding: 22px 36px;
136
+ border: none;
137
+ border-radius: 14px;
138
+ font-family: inherit;
139
+ font-size: 20px;
140
+ font-weight: 600;
141
+ cursor: pointer;
142
+ transition: all 0.2s ease;
143
+ position: relative;
144
+ overflow: hidden;
145
+ }
146
+
147
+ .btn-safe {
148
+ background: linear-gradient(135deg, #00FF41 0%, #00CC33 100%);
149
+ color: #000;
150
+ }
151
+
152
+ .btn-safe:hover {
153
+ transform: translateY(-2px);
154
+ box-shadow: 0 8px 24px rgba(0, 255, 65, 0.35);
155
+ }
156
+
157
+ .btn-safe:active {
158
+ transform: translateY(0);
159
+ }
160
+
161
+ .btn-unsafe {
162
+ background: linear-gradient(135deg, #FF4444 0%, #CC2233 100%);
163
+ color: #fff;
164
+ }
165
+
166
+ .btn-unsafe:hover {
167
+ transform: translateY(-2px);
168
+ box-shadow: 0 8px 24px rgba(255, 51, 51, 0.35);
169
+ }
170
+
171
+ .btn-unsafe:active {
172
+ transform: translateY(0);
173
+ }
174
+
175
+ .hint {
176
+ text-align: center;
177
+ margin-top: 28px;
178
+ font-size: 15px;
179
+ color: rgba(255, 255, 255, 0.3);
180
+ }
181
+
182
+ .hint kbd {
183
+ background: rgba(255, 255, 255, 0.1);
184
+ padding: 4px 10px;
185
+ border-radius: 6px;
186
+ font-family: inherit;
187
+ font-size: 14px;
188
+ }
189
+
190
+ .completed {
191
+ text-align: center;
192
+ padding: 60px 20px;
193
+ }
194
+
195
+ .completed-icon {
196
+ width: 88px;
197
+ height: 88px;
198
+ border-radius: 50%;
199
+ display: flex;
200
+ align-items: center;
201
+ justify-content: center;
202
+ margin: 0 auto 28px;
203
+ font-size: 40px;
204
+ }
205
+
206
+ .completed-icon.safe {
207
+ background: linear-gradient(135deg, rgba(0, 255, 65, 0.2), rgba(0, 204, 51, 0.1));
208
+ border: 2px solid rgba(0, 255, 65, 0.5);
209
+ box-shadow: 0 0 32px rgba(0, 255, 65, 0.2);
210
+ }
211
+
212
+ .completed-icon.unsafe {
213
+ background: linear-gradient(135deg, rgba(255, 68, 68, 0.2), rgba(204, 34, 51, 0.1));
214
+ border: 2px solid rgba(255, 68, 68, 0.5);
215
+ box-shadow: 0 0 32px rgba(255, 68, 68, 0.2);
216
+ }
217
+
218
+ .completed h2 {
219
+ font-size: 28px;
220
+ font-weight: 600;
221
+ margin-bottom: 12px;
222
+ }
223
+
224
+ .completed p {
225
+ font-size: 18px;
226
+ color: rgba(255, 255, 255, 0.5);
227
+ }
228
+ </style>
229
+ </head>
230
+ <body>
231
+ <div class="card" id="main-card">
232
+ <div class="badge">Verification Required</div>
233
+
234
+ <h1>Is this solution safe?</h1>
235
+ <p class="subtitle">Review the code below and verify it's safe to use</p>
236
+
237
+ <div class="solution-card">
238
+ <div class="solution-title">${escapeHtml(title)}</div>
239
+ <div class="solution-body">${body ? escapeHtml(body) : 'Solution body not available.\nUnlock to view full content.'}</div>
240
+ </div>
241
+
242
+ <div class="buttons">
243
+ <button class="btn btn-safe" onclick="submit('safe')">Safe</button>
244
+ <button class="btn btn-unsafe" onclick="submit('unsafe')">Unsafe</button>
245
+ </div>
246
+
247
+ <div class="hint">
248
+ Press <kbd>S</kbd> for Safe or <kbd>U</kbd> for Unsafe
249
+ </div>
250
+ </div>
251
+
252
+ <script>
253
+ function submit(result) {
254
+ const isSafe = result === 'safe';
255
+ document.getElementById('main-card').innerHTML = \`
256
+ <div class="completed">
257
+ <div class="completed-icon \${result}">\${isSafe ? '&#10003;' : '&#10005;'}</div>
258
+ <h2>\${isSafe ? 'Marked as Safe' : 'Marked as Unsafe'}</h2>
259
+ <p>You can close this tab now</p>
260
+ </div>
261
+ \`;
262
+ fetch('/result?value=' + result).catch(() => {});
263
+ }
264
+
265
+ document.addEventListener('keydown', (e) => {
266
+ if (e.key === 's' || e.key === 'S') submit('safe');
267
+ if (e.key === 'u' || e.key === 'U') submit('unsafe');
268
+ });
269
+ </script>
270
+ </body>
271
+ </html>
272
+ `;
273
+
274
+ function escapeHtml(text: string): string {
275
+ return text
276
+ .replace(/&/g, '&amp;')
277
+ .replace(/</g, '&lt;')
278
+ .replace(/>/g, '&gt;')
279
+ .replace(/"/g, '&quot;')
280
+ .replace(/'/g, '&#039;');
281
+ }
282
+
283
+ /**
284
+ * Shows a modern verification dialog in the browser.
285
+ * @param title The solution's query title
286
+ * @param body The solution body (if available/unlocked)
287
+ * @returns true if user clicked "Safe", false if "Unsafe", null if cancelled
288
+ */
289
+ export async function showVerificationDialog(
290
+ title: string,
291
+ body?: string
292
+ ): Promise<boolean | null> {
293
+ return new Promise((resolve) => {
294
+ const html = generateHTML(title, body);
295
+ let resolved = false;
296
+
297
+ const server = http.createServer((req, res) => {
298
+ const url = new URL(req.url || '/', `http://localhost`);
299
+
300
+ if (url.pathname === '/result') {
301
+ const value = url.searchParams.get('value');
302
+ res.writeHead(200, { 'Content-Type': 'text/plain', 'Access-Control-Allow-Origin': '*' });
303
+ res.end('OK');
304
+
305
+ if (!resolved) {
306
+ resolved = true;
307
+ server.close();
308
+
309
+ switch (value) {
310
+ case 'safe':
311
+ logger.info('User verified solution as safe', { solutionTitle: title });
312
+ resolve(true);
313
+ break;
314
+ case 'unsafe':
315
+ logger.info('User verified solution as unsafe', { solutionTitle: title });
316
+ resolve(false);
317
+ break;
318
+ default:
319
+ logger.warn('User verification dialog closed with unknown result', {
320
+ value,
321
+ solutionTitle: title
322
+ });
323
+ resolve(null);
324
+ }
325
+ }
326
+ } else {
327
+ res.writeHead(200, { 'Content-Type': 'text/html' });
328
+ res.end(html);
329
+ }
330
+ });
331
+
332
+ server.on('error', (error) => {
333
+ logger.error('Verification dialog HTTP server error', error, {
334
+ solutionTitle: title,
335
+ errorType: 'VERIFICATION_DIALOG_ERROR',
336
+ });
337
+ if (!resolved) {
338
+ resolved = true;
339
+ resolve(null);
340
+ }
341
+ });
342
+
343
+ server.listen(0, 'localhost', () => {
344
+ const address = server.address();
345
+ if (address && typeof address === 'object') {
346
+ const url = `http://localhost:${address.port}`;
347
+ logger.info('Verification dialog opened', {
348
+ port: address.port,
349
+ solutionTitle: title
350
+ });
351
+
352
+ open(url).catch((error) => {
353
+ logger.error('Failed to open verification dialog in browser', error, {
354
+ url,
355
+ solutionTitle: title,
356
+ errorType: 'BROWSER_OPEN_FAILURE',
357
+ });
358
+ });
359
+
360
+ // Timeout after 55 seconds (within MCP client default 60s limit)
361
+ setTimeout(() => {
362
+ if (!resolved) {
363
+ resolved = true;
364
+ server.close();
365
+ logger.warn('Verification dialog timed out', { solutionTitle: title });
366
+ resolve(null);
367
+ }
368
+ }, 55 * 1000);
369
+ } else {
370
+ logger.error('Failed to get server address for verification dialog', undefined, {
371
+ address,
372
+ solutionTitle: title,
373
+ errorType: 'SERVER_ADDRESS_ERROR',
374
+ });
375
+ if (!resolved) {
376
+ resolved = true;
377
+ resolve(null);
378
+ }
379
+ }
380
+ });
381
+ });
382
+ }