add reset as tool

This commit is contained in:
Tommy D. Rossi
2025-11-25 09:57:38 +01:00
parent 81695342c5
commit 9219912d35
5 changed files with 46 additions and 3 deletions
+1
View File
@@ -42,6 +42,7 @@
"devtools-protocol": "^0.0.1543509",
"hono": "^4.10.6",
"playwright-core": "^1.56.1",
"string-dedent": "^3.0.2",
"user-agents": "^1.1.669",
"ws": "^8.18.3",
"zod": "^3"
+34
View File
@@ -620,6 +620,40 @@ server.tool(
},
)
server.tool(
'reset',
`Recreates the CDP connection and resets the browser/page/context. Use this when the MCP stops responding, you get connection errors, assertion failures, page closed, or timeout issues.
After calling this tool, the page and context variables are automatically updated in the execution environment.
IMPORTANT: this completely resets the execution context, removing any custom properties you may have added to the global scope AND clearing all keys from the \`state\` object. Only \`page\`, \`context\`, \`state\` (empty), \`console\`, and utility functions will remain.`,
{},
async () => {
try {
const { page, context } = await resetConnection()
const pagesCount = context.pages().length
return {
content: [
{
type: 'text',
text: `Connection reset successfully. ${pagesCount} page(s) available. Current page URL: ${page.url()}`,
},
],
}
} catch (error: any) {
return {
content: [
{
type: 'text',
text: `Failed to reset connection: ${error.message}`,
},
],
isError: true,
}
}
},
)
// Start the server
async function main() {
await ensureRelayServer()
-1
View File
@@ -76,7 +76,6 @@ you have access to some functions in addition to playwright methods:
- `page`: the page object to snapshot
- `searchString`: (optional) a string or regex to filter the snapshot. If provided, returns the first 10 matches with surrounding context
- `contextLines`: (optional) number of lines of context to show around each match (default: 10)
- `async resetPlaywright()`: recreates the CDP connection and resets the browser/page/context. Use this when the MCP stops responding, you get connection errors, assertion failures, page closed, or timeout issues. After calling this, the page and context variables are automatically updated in the execution environment. IMPORTANT: this completely resets the execution context, removing any custom properties you may have added to the global scope AND clearing all keys from the `state` object. Only `page`, `context`, `state` (empty), `console`, and utility functions will remain
- `getLatestLogs({ page, count, searchFilter })`: retrieves browser console logs. The system automatically captures and stores up to 5000 logs per page. Logs are cleared when a page reloads or navigates.
- `page`: (optional) filter logs by a specific page instance. Only returns logs from that page
- `count`: (optional) limit number of logs to return. If not specified, returns all available logs
@@ -28,10 +28,10 @@ Return value:
- generic [ref=e21]:
- generic: ⌘
- generic: K
- link "100.6k" [ref=e22] [cursor=pointer]:
- link "100.7k" [ref=e22] [cursor=pointer]:
- /url: https://github.com/shadcn-ui/ui
- img
- generic [ref=e23]: 100.6k
- generic [ref=e23]: 100.7k
- button "Toggle theme" [ref=e24]:
- img
- generic [ref=e25]: Toggle theme
+9
View File
@@ -81,6 +81,9 @@ importers:
playwright-core:
specifier: ^1.56.1
version: 1.56.1
string-dedent:
specifier: ^3.0.2
version: 3.0.2
user-agents:
specifier: ^1.1.669
version: 1.1.669
@@ -1575,6 +1578,10 @@ packages:
std-env@3.10.0:
resolution: {integrity: sha512-5GS12FdOZNliM5mAOxFRg7Ir0pWz8MdpYm6AY6VPkGpbA7ZzmbzNcBJQ0GPvvyWgcY7QAhCgf9Uy89I03faLkg==}
string-dedent@3.0.2:
resolution: {integrity: sha512-M4q+HpHCtGXlbyzYDOcOo7V185dlq6YXvGUPcWZqL4vttCX9gFYoWIOxcPd7v5CAYcTJsGLs3ZJCAH2TXONF/g==}
engines: {node: '>=0.12.0'}
string-width@4.2.3:
resolution: {integrity: sha512-wKyQRQpjJ0sIp62ErSZdGsjMJWsap5oRNihHhu6G7JVO/9jIB6UyevL+tXuOqrng8j/cxKTWyWUwvSTriiZz/g==}
engines: {node: '>=8'}
@@ -3343,6 +3350,8 @@ snapshots:
std-env@3.10.0: {}
string-dedent@3.0.2: {}
string-width@4.2.3:
dependencies:
emoji-regex: 8.0.0