Skip to content

Commit 7702a3a

Browse files
committed
fixed network and console log parsing; consolidated mcp endpoints
1 parent 8d98b9a commit 7702a3a

File tree

2 files changed

+42
-8
lines changed

2 files changed

+42
-8
lines changed

browser-tools-mcp/mcp-server.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22

33
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
44
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
5-
import path from "path";
6-
// import { z } from "zod";
7-
// import fs from "fs";
85

96
// Create the MCP server
107
const server = new McpServer({
@@ -60,7 +57,7 @@ server.tool(
6057
);
6158

6259
// Return all HTTP errors (4xx/5xx)
63-
server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
60+
server.tool("getNetworkErrorLogs", "Check our network ERROR logs", async () => {
6461
const response = await fetch(`http://127.0.0.1:${PORT}/network-errors`);
6562
const json = await response.json();
6663
return {
@@ -74,6 +71,7 @@ server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
7471
});
7572

7673
// // Return all XHR/fetch requests
74+
// // DEPRECATED: Use getNetworkSuccessLogs and getNetworkErrorLogs instead
7775
// server.tool("getNetworkSuccess", "Check our network SUCCESS logs", async () => {
7876
// const response = await fetch(`http://127.0.0.1:${PORT}/all-xhr`);
7977
// const json = await response.json();
@@ -88,8 +86,8 @@ server.tool("getNetworkErrors", "Check our network ERROR logs", async () => {
8886
// });
8987

9088
// Return all XHR/fetch requests
91-
server.tool("getNetworkLogs", "Check ALL our network logs", async () => {
92-
const response = await fetch(`http://127.0.0.1:${PORT}/all-xhr`);
89+
server.tool("getNetworkSuccessLogs", "Check ALL our network logs", async () => {
90+
const response = await fetch(`http://127.0.0.1:${PORT}/network-success`);
9391
const json = await response.json();
9492
return {
9593
content: [
@@ -117,6 +115,7 @@ server.tool(
117115
const result = await response.json();
118116

119117
if (response.ok) {
118+
// Removed path due to bug... will change later anyways
120119
// const message = `Screenshot saved to: ${
121120
// result.path
122121
// }\nFilename: ${path.basename(result.path)}`;

chrome-extension/devtools.js

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,9 @@ const consoleMessageListener = (source, method, params) => {
433433
if (method === "Runtime.exceptionThrown") {
434434
const entry = {
435435
type: "console-error",
436-
message: params.exceptionDetails.exception?.description || JSON.stringify(params.exceptionDetails),
436+
message:
437+
params.exceptionDetails.exception?.description ||
438+
JSON.stringify(params.exceptionDetails),
437439
level: "error",
438440
timestamp: Date.now(),
439441
};
@@ -442,10 +444,43 @@ const consoleMessageListener = (source, method, params) => {
442444
}
443445

444446
if (method === "Runtime.consoleAPICalled") {
447+
// Process all arguments from the console call
448+
let formattedMessage = "";
449+
const args = params.args || [];
450+
451+
// Extract all arguments and combine them
452+
if (args.length > 0) {
453+
// Try to build a meaningful representation of all arguments
454+
try {
455+
formattedMessage = args
456+
.map((arg) => {
457+
// Handle different types of arguments
458+
if (arg.type === "string") {
459+
return arg.value;
460+
} else if (arg.type === "object" && arg.preview) {
461+
// For objects, include their preview or description
462+
return JSON.stringify(arg.preview);
463+
} else if (arg.description) {
464+
// Some objects have descriptions
465+
return arg.description;
466+
} else {
467+
// Fallback for other types
468+
return arg.value || arg.description || JSON.stringify(arg);
469+
}
470+
})
471+
.join(" ");
472+
} catch (e) {
473+
// Fallback if processing fails
474+
console.error("Failed to process console arguments:", e);
475+
formattedMessage =
476+
args[0]?.value || "Unable to process console arguments";
477+
}
478+
}
479+
445480
const entry = {
446481
type: params.type === "error" ? "console-error" : "console-log",
447482
level: params.type,
448-
message: params.args[0].value,
483+
message: formattedMessage,
449484
timestamp: Date.now(),
450485
};
451486
console.log("Sending console entry:", entry);

0 commit comments

Comments
 (0)