Skip to content
Open
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
97 changes: 96 additions & 1 deletion src/lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -444,6 +444,101 @@ server.tool(
}
);

// Alert/Modal Handling Tools
server.tool(
"accept_alert",
"accepts a browser alert, confirmation, or prompt dialog",
{
timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds")
},
async ({ timeout = 10000 }) => {
try {
const driver = getDriver();
await driver.wait(until.alertIsPresent(), timeout);
const alert = await driver.switchTo().alert();
await alert.accept();
return {
content: [{ type: 'text', text: 'Alert accepted' }]
};
} catch (e) {
return {
content: [{ type: 'text', text: `Error accepting alert: ${e.message}` }]
};
}
}
);

server.tool(
"dismiss_alert",
"dismisses/cancels a browser alert, confirmation, or prompt dialog",
{
timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds")
},
async ({ timeout = 10000 }) => {
try {
const driver = getDriver();
await driver.wait(until.alertIsPresent(), timeout);
const alert = await driver.switchTo().alert();
await alert.dismiss();
return {
content: [{ type: 'text', text: 'Alert dismissed' }]
};
} catch (e) {
return {
content: [{ type: 'text', text: `Error dismissing alert: ${e.message}` }]
};
}
}
);

server.tool(
"get_alert_text",
"gets the text content from a browser alert, confirmation, or prompt dialog",
{
timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds")
},
async ({ timeout = 10000 }) => {
try {
const driver = getDriver();
await driver.wait(until.alertIsPresent(), timeout);
const alert = await driver.switchTo().alert();
const text = await alert.getText();
return {
content: [{ type: 'text', text }]
};
} catch (e) {
return {
content: [{ type: 'text', text: `Error getting alert text: ${e.message}` }]
};
}
}
);

server.tool(
"send_alert_text",
"sends text to a browser prompt dialog",
{
text: z.string().describe("Text to send to the prompt dialog"),
timeout: z.number().optional().describe("Maximum time to wait for alert in milliseconds")
},
async ({ text, timeout = 10000 }) => {
try {
const driver = getDriver();
await driver.wait(until.alertIsPresent(), timeout);
const alert = await driver.switchTo().alert();
await alert.sendKeys(text);
await alert.accept();
return {
content: [{ type: 'text', text: `Text "${text}" sent to alert and accepted` }]
};
} catch (e) {
return {
content: [{ type: 'text', text: `Error sending text to alert: ${e.message}` }]
};
}
}
);

// Resources
server.resource(
"browser-status",
Expand Down Expand Up @@ -477,4 +572,4 @@ process.on('SIGINT', cleanup);

// Start the server
const transport = new StdioServerTransport();
await server.connect(transport);
await server.connect(transport);