ScuttleBot

scuttlebot / tests / e2e / node_modules / playwright / lib / mcp / browser / browserServerBackend.js
Source Blame History 84 lines
f7eb47b… lmata 1 "use strict";
f7eb47b… lmata 2 var __defProp = Object.defineProperty;
f7eb47b… lmata 3 var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
f7eb47b… lmata 4 var __getOwnPropNames = Object.getOwnPropertyNames;
f7eb47b… lmata 5 var __hasOwnProp = Object.prototype.hasOwnProperty;
f7eb47b… lmata 6 var __export = (target, all) => {
f7eb47b… lmata 7 for (var name in all)
f7eb47b… lmata 8 __defProp(target, name, { get: all[name], enumerable: true });
f7eb47b… lmata 9 };
f7eb47b… lmata 10 var __copyProps = (to, from, except, desc) => {
f7eb47b… lmata 11 if (from && typeof from === "object" || typeof from === "function") {
f7eb47b… lmata 12 for (let key of __getOwnPropNames(from))
f7eb47b… lmata 13 if (!__hasOwnProp.call(to, key) && key !== except)
f7eb47b… lmata 14 __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
f7eb47b… lmata 15 }
f7eb47b… lmata 16 return to;
f7eb47b… lmata 17 };
f7eb47b… lmata 18 var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
f7eb47b… lmata 19 var browserServerBackend_exports = {};
f7eb47b… lmata 20 __export(browserServerBackend_exports, {
f7eb47b… lmata 21 BrowserServerBackend: () => BrowserServerBackend
f7eb47b… lmata 22 });
f7eb47b… lmata 23 module.exports = __toCommonJS(browserServerBackend_exports);
f7eb47b… lmata 24 var import_context = require("./context");
f7eb47b… lmata 25 var import_log = require("../log");
f7eb47b… lmata 26 var import_response = require("./response");
f7eb47b… lmata 27 var import_sessionLog = require("./sessionLog");
f7eb47b… lmata 28 var import_tools = require("./tools");
f7eb47b… lmata 29 var import_tool = require("../sdk/tool");
f7eb47b… lmata 30 class BrowserServerBackend {
f7eb47b… lmata 31 constructor(config, factory) {
f7eb47b… lmata 32 this._config = config;
f7eb47b… lmata 33 this._browserContextFactory = factory;
f7eb47b… lmata 34 this._tools = (0, import_tools.filteredTools)(config);
f7eb47b… lmata 35 }
f7eb47b… lmata 36 async initialize(clientInfo) {
f7eb47b… lmata 37 this._sessionLog = this._config.saveSession ? await import_sessionLog.SessionLog.create(this._config, clientInfo) : void 0;
f7eb47b… lmata 38 this._context = new import_context.Context({
f7eb47b… lmata 39 config: this._config,
f7eb47b… lmata 40 browserContextFactory: this._browserContextFactory,
f7eb47b… lmata 41 sessionLog: this._sessionLog,
f7eb47b… lmata 42 clientInfo
f7eb47b… lmata 43 });
f7eb47b… lmata 44 }
f7eb47b… lmata 45 async listTools() {
f7eb47b… lmata 46 return this._tools.map((tool) => (0, import_tool.toMcpTool)(tool.schema));
f7eb47b… lmata 47 }
f7eb47b… lmata 48 async callTool(name, rawArguments) {
f7eb47b… lmata 49 const tool = this._tools.find((tool2) => tool2.schema.name === name);
f7eb47b… lmata 50 if (!tool) {
f7eb47b… lmata 51 return {
f7eb47b… lmata 52 content: [{ type: "text", text: `### Error
f7eb47b… lmata 53 Tool "${name}" not found` }],
f7eb47b… lmata 54 isError: true
f7eb47b… lmata 55 };
f7eb47b… lmata 56 }
f7eb47b… lmata 57 const parsedArguments = tool.schema.inputSchema.parse(rawArguments || {});
f7eb47b… lmata 58 const context = this._context;
f7eb47b… lmata 59 const response = import_response.Response.create(context, name, parsedArguments);
f7eb47b… lmata 60 context.setRunningTool(name);
f7eb47b… lmata 61 let responseObject;
f7eb47b… lmata 62 try {
f7eb47b… lmata 63 await tool.handle(context, parsedArguments, response);
f7eb47b… lmata 64 responseObject = await response.build();
f7eb47b… lmata 65 this._sessionLog?.logResponse(name, parsedArguments, responseObject);
f7eb47b… lmata 66 } catch (error) {
f7eb47b… lmata 67 return {
f7eb47b… lmata 68 content: [{ type: "text", text: `### Error
f7eb47b… lmata 69 ${String(error)}` }],
f7eb47b… lmata 70 isError: true
f7eb47b… lmata 71 };
f7eb47b… lmata 72 } finally {
f7eb47b… lmata 73 context.setRunningTool(void 0);
f7eb47b… lmata 74 }
f7eb47b… lmata 75 return responseObject;
f7eb47b… lmata 76 }
f7eb47b… lmata 77 serverClosed() {
f7eb47b… lmata 78 void this._context?.dispose().catch(import_log.logUnhandledError);
f7eb47b… lmata 79 }
f7eb47b… lmata 80 }
f7eb47b… lmata 81 // Annotate the CommonJS export names for ESM import in node:
f7eb47b… lmata 82 0 && (module.exports = {
f7eb47b… lmata 83 BrowserServerBackend
f7eb47b… lmata 84 });

Keyboard Shortcuts

Open search /
Next entry (timeline) j
Previous entry (timeline) k
Open focused entry Enter
Show this help ?
Toggle theme Top nav button