brave-real-browser-mcp-server 2.8.3 → 2.8.5

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.
@@ -67,18 +67,11 @@ export async function handleSmartSelectorGenerator(args) {
67
67
  totalCandidates: scores.length
68
68
  };
69
69
  }, description, context || '');
70
- return {
71
- success: true,
72
- data: result,
73
- description,
74
- context
75
- };
70
+ const resultText = `? Smart Selector Generated\n\nBest Match: ${JSON.stringify(result.bestMatch, null, 2)}\nAlternatives: ${JSON.stringify(result.alternatives, null, 2)}\nTotal Candidates: ${result.totalCandidates}`;
71
+ return { content: [{ type: 'text', text: resultText }] };
76
72
  }
77
73
  catch (error) {
78
- return {
79
- success: false,
80
- error: error.message
81
- };
74
+ return { content: [{ type: 'text', text: `? Error: ${error.message}` }], isError: true };
82
75
  }
83
76
  }
84
77
  /**
@@ -127,18 +120,17 @@ export async function handleContentClassification(args) {
127
120
  return { category: cat.name, score };
128
121
  });
129
122
  scores.sort((a, b) => b.score - a.score);
123
+ const confidence = scores[0].score / (scores.reduce((sum, s) => sum + s.score, 0) || 1);
124
+ const resultText = `✅ Content Classification\n\nPrimary Category: ${scores[0].category} (Score: ${scores[0].score})\nConfidence: ${(confidence * 100).toFixed(2)}%\n\nAll Categories:\n${JSON.stringify(scores.slice(0, 5), null, 2)}`;
130
125
  return {
131
- success: true,
132
- primaryCategory: scores[0],
133
- allScores: scores,
134
- confidence: scores[0].score / (scores.reduce((sum, s) => sum + s.score, 0) || 1)
126
+ content: [{
127
+ type: 'text',
128
+ text: resultText
129
+ }]
135
130
  };
136
131
  }
137
132
  catch (error) {
138
- return {
139
- success: false,
140
- error: error.message
141
- };
133
+ return { content: [{ type: 'text', text: `? Error: ${error.message}` }], isError: true };
142
134
  }
143
135
  }
144
136
  /**
@@ -183,30 +175,22 @@ export async function handleSentimentAnalysis(args) {
183
175
  sentiment: s.score > 0 ? 'positive' : s.score < 0 ? 'negative' : 'neutral'
184
176
  };
185
177
  });
178
+ const stats = {
179
+ totalSentences: sentences.length,
180
+ positiveSentences: sentenceSentiments.filter(s => s.sentiment === 'positive').length,
181
+ negativeSentences: sentenceSentiments.filter(s => s.sentiment === 'negative').length,
182
+ neutralSentences: sentenceSentiments.filter(s => s.sentiment === 'neutral').length
183
+ };
184
+ const resultText = `✅ Sentiment Analysis\n\nOverall Sentiment: ${result.score > 0 ? 'Positive' : result.score < 0 ? 'Negative' : 'Neutral'}\nScore: ${result.score}\nComparative: ${result.comparative.toFixed(4)}\n\nStatistics:\n- Total Sentences: ${stats.totalSentences}\n- Positive: ${stats.positiveSentences}\n- Negative: ${stats.negativeSentences}\n- Neutral: ${stats.neutralSentences}\n\nPositive Words: ${result.positive.join(', ')}\nNegative Words: ${result.negative.join(', ')}`;
186
185
  return {
187
- success: true,
188
- overall: {
189
- score: result.score,
190
- comparative: result.comparative,
191
- sentiment: result.score > 0 ? 'positive' : result.score < 0 ? 'negative' : 'neutral',
192
- tokens: result.tokens.length,
193
- positive: result.positive,
194
- negative: result.negative
195
- },
196
- sentences: sentenceSentiments,
197
- statistics: {
198
- totalSentences: sentences.length,
199
- positiveSentences: sentenceSentiments.filter(s => s.sentiment === 'positive').length,
200
- negativeSentences: sentenceSentiments.filter(s => s.sentiment === 'negative').length,
201
- neutralSentences: sentenceSentiments.filter(s => s.sentiment === 'neutral').length
202
- }
186
+ content: [{
187
+ type: 'text',
188
+ text: resultText
189
+ }]
203
190
  };
204
191
  }
205
192
  catch (error) {
206
- return {
207
- success: false,
208
- error: error.message
209
- };
193
+ return { content: [{ type: 'text', text: `? Error: ${error.message}` }], isError: true };
210
194
  }
211
195
  }
212
196
  /**
@@ -267,27 +251,17 @@ export async function handleSummaryGenerator(args) {
267
251
  // Sort by original order
268
252
  topSentences.sort((a, b) => a.index - b.index);
269
253
  const summary = topSentences.map(s => s.sentence).join(' ');
254
+ const compressionRatio = (summary.length / content.length * 100).toFixed(2);
255
+ const resultText = `✅ Summary Generated\n\nSummary:\n${summary}\n\nStatistics:\n- Original Length: ${content.length} characters\n- Summary Length: ${summary.length} characters\n- Compression Ratio: ${compressionRatio}%\n- Original Sentences: ${sentences.length}\n- Summary Sentences: ${topSentences.length}`;
270
256
  return {
271
- success: true,
272
- summary,
273
- originalLength: content.length,
274
- summaryLength: summary.length,
275
- compressionRatio: (summary.length / content.length * 100).toFixed(2) + '%',
276
- sentenceCount: {
277
- original: sentences.length,
278
- summary: topSentences.length
279
- },
280
- topScoredSentences: topSentences.map(s => ({
281
- sentence: s.sentence,
282
- score: s.score.toFixed(2)
283
- }))
257
+ content: [{
258
+ type: 'text',
259
+ text: resultText
260
+ }]
284
261
  };
285
262
  }
286
263
  catch (error) {
287
- return {
288
- success: false,
289
- error: error.message
290
- };
264
+ return { content: [{ type: 'text', text: `? Error: ${error.message}` }], isError: true };
291
265
  }
292
266
  }
293
267
  /**
@@ -344,24 +318,16 @@ export async function handleTranslationSupport(args) {
344
318
  const keyPhrases = tfidf.listTerms(0)
345
319
  .slice(0, 10)
346
320
  .map(term => term.term);
321
+ const needsTranslation = detectedLang !== targetLanguage && detectedLang !== 'und';
322
+ const resultText = `✅ Translation Support\n\nDetected Language: ${languageName} (${detectedLang})\nTarget Language: ${targetLanguage}\nNeeds Translation: ${needsTranslation ? 'Yes' : 'No'}\n\nContent Length: ${contentToTranslate.length} characters\nContent Preview: ${contentToTranslate.substring(0, 200)}...\n\nKey Phrases: ${keyPhrases.join(', ')}\n\nNote: Use external translation API (Google Translate, DeepL) for actual translation`;
347
323
  return {
348
- success: true,
349
- detectedLanguage: {
350
- code: detectedLang,
351
- name: languageName
352
- },
353
- targetLanguage,
354
- needsTranslation: detectedLang !== targetLanguage && detectedLang !== 'und',
355
- contentPreview: contentToTranslate.substring(0, 200),
356
- contentLength: contentToTranslate.length,
357
- keyPhrases,
358
- translationNote: 'Use external translation API (Google Translate, DeepL) for actual translation'
324
+ content: [{
325
+ type: 'text',
326
+ text: resultText
327
+ }]
359
328
  };
360
329
  }
361
330
  catch (error) {
362
- return {
363
- success: false,
364
- error: error.message
365
- };
331
+ return { content: [{ type: 'text', text: `? Error: ${error.message}` }], isError: true };
366
332
  }
367
333
  }
@@ -203,16 +203,25 @@ export async function handleXPathSupport(args) {
203
203
  elements
204
204
  };
205
205
  }, xpath, returnType);
206
+ const resultText = `✅ XPath Query Results\n\nXPath: ${xpath}\nElements Found: ${results.count}\n\nElements:\n${JSON.stringify(results.elements, null, 2)}`;
206
207
  return {
207
- success: true,
208
- xpath,
209
- ...results
208
+ content: [
209
+ {
210
+ type: 'text',
211
+ text: resultText,
212
+ },
213
+ ],
210
214
  };
211
215
  }
212
216
  catch (error) {
213
217
  return {
214
- success: false,
215
- error: error.message
218
+ content: [
219
+ {
220
+ type: 'text',
221
+ text: `❌ XPath query failed: ${error.message}`,
222
+ },
223
+ ],
224
+ isError: true,
216
225
  };
217
226
  }
218
227
  }
@@ -274,17 +283,25 @@ export async function handleAdvancedCSSSelectors(args) {
274
283
  elements: results
275
284
  };
276
285
  }, selector, operation, returnType);
286
+ const resultText = `✅ Advanced CSS Selector Results\n\nSelector: ${selector}\nOperation: ${operation}\nElements Found: ${results.count}\n\nElements (first 10):\n${JSON.stringify(results.elements.slice(0, 10), null, 2)}`;
277
287
  return {
278
- success: true,
279
- selector,
280
- operation,
281
- ...results
288
+ content: [
289
+ {
290
+ type: 'text',
291
+ text: resultText,
292
+ },
293
+ ],
282
294
  };
283
295
  }
284
296
  catch (error) {
285
297
  return {
286
- success: false,
287
- error: error.message
298
+ content: [
299
+ {
300
+ type: 'text',
301
+ text: `❌ CSS selector query failed: ${error.message}`,
302
+ },
303
+ ],
304
+ isError: true,
288
305
  };
289
306
  }
290
307
  }
@@ -400,16 +417,25 @@ export async function handleVisualElementFinder(args) {
400
417
  topMatches: matches.slice(0, 20)
401
418
  };
402
419
  }, criteria);
420
+ const resultText = `✅ Visual Element Finder Results\n\nCriteria: ${JSON.stringify(criteria, null, 2)}\nTotal Matches: ${results.totalMatches}\n\nTop Matches:\n${JSON.stringify(results.topMatches, null, 2)}`;
403
421
  return {
404
- success: true,
405
- criteria,
406
- ...results
422
+ content: [
423
+ {
424
+ type: 'text',
425
+ text: resultText,
426
+ },
427
+ ],
407
428
  };
408
429
  }
409
430
  catch (error) {
410
431
  return {
411
- success: false,
412
- error: error.message
432
+ content: [
433
+ {
434
+ type: 'text',
435
+ text: `❌ Visual element finder failed: ${error.message}`,
436
+ },
437
+ ],
438
+ isError: true,
413
439
  };
414
440
  }
415
441
  }
@@ -127,22 +127,25 @@ export async function handleElementScreenshot(args) {
127
127
  const stats = await fs.stat(outputPath);
128
128
  fileSize = stats.size;
129
129
  }
130
+ const resultText = `✅ Element screenshot captured successfully\n\nPath: ${outputPath}\nSelector: ${selector}\nFormat: ${format}\nPadding: ${padding}px\nElement: ${elementInfo?.tagName || 'unknown'}\nFile Size: ${(fileSize / 1024).toFixed(2)} KB\nTimestamp: ${new Date().toISOString()}`;
130
131
  return {
131
- success: true,
132
- path: outputPath,
133
- selector,
134
- format,
135
- padding,
136
- element: elementInfo,
137
- fileSize,
138
- fileSizeKB: (fileSize / 1024).toFixed(2),
139
- timestamp: new Date().toISOString()
132
+ content: [
133
+ {
134
+ type: 'text',
135
+ text: resultText,
136
+ },
137
+ ],
140
138
  };
141
139
  }
142
140
  catch (error) {
143
141
  return {
144
- success: false,
145
- error: error.message
142
+ content: [
143
+ {
144
+ type: 'text',
145
+ text: `❌ Element screenshot failed: ${error.message}`,
146
+ },
147
+ ],
148
+ isError: true,
146
149
  };
147
150
  }
148
151
  }
@@ -180,21 +183,25 @@ export async function handlePDFGeneration(args) {
180
183
  const stats = await fs.stat(outputPath);
181
184
  fileSize = stats.size;
182
185
  }
186
+ const resultText = `✅ PDF generated successfully\n\nPath: ${outputPath}\nFormat: ${format}\nLandscape: ${landscape}\nFile Size: ${(fileSize / 1024).toFixed(2)} KB (${(fileSize / (1024 * 1024)).toFixed(2)} MB)\nTimestamp: ${new Date().toISOString()}`;
183
187
  return {
184
- success: true,
185
- path: outputPath,
186
- format,
187
- landscape,
188
- fileSize,
189
- fileSizeKB: (fileSize / 1024).toFixed(2),
190
- fileSizeMB: (fileSize / (1024 * 1024)).toFixed(2),
191
- timestamp: new Date().toISOString()
188
+ content: [
189
+ {
190
+ type: 'text',
191
+ text: resultText,
192
+ },
193
+ ],
192
194
  };
193
195
  }
194
196
  catch (error) {
195
197
  return {
196
- success: false,
197
- error: error.message
198
+ content: [
199
+ {
200
+ type: 'text',
201
+ text: `❌ PDF generation failed: ${error.message}`,
202
+ },
203
+ ],
204
+ isError: true,
198
205
  };
199
206
  }
200
207
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "brave-real-browser-mcp-server",
3
- "version": "2.8.3",
3
+ "version": "2.8.5",
4
4
  "description": "MCP server for brave-real-browser",
5
5
  "type": "module",
6
6
  "main": "dist/index.js",