Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 32 additions & 5 deletions bin/mcp-server.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ import path from 'path'
import crypto from 'crypto'
import { spawn } from 'child_process'
import { createRequire } from 'module'
import { existsSync, readdirSync } from 'fs'
import { existsSync, readdirSync, writeFileSync } from 'fs'
import { mkdirp } from 'mkdirp'

const require = createRequire(import.meta.url)

Expand Down Expand Up @@ -439,12 +440,38 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
const helper = Object.values(helpers)[0]
if (helper) {
try {
if (helper.grabAriaSnapshot) result.artifacts.aria = await helper.grabAriaSnapshot()
if (helper.grabCurrentUrl) result.artifacts.url = await helper.grabCurrentUrl()
if (helper.grabBrowserLogs) result.artifacts.consoleLogs = (await helper.grabBrowserLogs()) || []
const traceDir = getTraceDir('mcp', 'run_code')
mkdirp.sync(traceDir)

if (helper.grabAriaSnapshot) {
const aria = await helper.grabAriaSnapshot()
const ariaFile = path.join(traceDir, 'aria.txt')
writeFileSync(ariaFile, aria)
result.artifacts.aria = `file://${ariaFile}`
}

if (helper.grabCurrentUrl) {
result.artifacts.url = await helper.grabCurrentUrl()
}

if (helper.grabBrowserLogs) {
const logs = (await helper.grabBrowserLogs()) || []
const logsFile = path.join(traceDir, 'console.json')
writeFileSync(logsFile, JSON.stringify(logs, null, 2))
result.artifacts.consoleLogs = `file://${logsFile}`
}

if (helper.grabSource) {
const html = await helper.grabSource()
result.artifacts.html = html.substring(0, 10000) + '...'
const htmlFile = path.join(traceDir, 'page.html')
writeFileSync(htmlFile, html)
result.artifacts.html = `file://${htmlFile}`
}

if (helper.saveScreenshot) {
const screenshotFile = path.join(traceDir, 'screenshot.png')
await helper.saveScreenshot(screenshotFile)
result.artifacts.screenshot = `file://${screenshotFile}`
}
} catch (e) {
result.output += ` (Warning: ${e.message})`
Expand Down
2 changes: 1 addition & 1 deletion lib/helper/Playwright.js
Original file line number Diff line number Diff line change
Expand Up @@ -2933,7 +2933,7 @@ class Playwright extends Helper {
const els = await this._locate(matchedLocator)
assertElementExists(els, locator)
const snapshot = await els[0].ariaSnapshot()
this.debugSection('Aria Snapshot', snapshot)
this.debugSection('Aria Snapshot', `${snapshot.split('\n').length} lines`)
return snapshot
}

Expand Down