@mseep/hyperbrowser-mcp
Version:
Hyperbrowser Model Context Protocol Server
52 lines (51 loc) • 2.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.deleteProfileToolDescription = exports.deleteProfileToolName = exports.deleteProfileTool = void 0;
const utils_js_1 = require("../utils.js"); // Import getClient
const sdk_1 = require("@hyperbrowser/sdk"); // Import SDK error type
// The handler function receives parsed parameters
async function deleteProfileTool(params) {
const { profileId } = params; // Destructure validated profileId
try {
const client = await (0, utils_js_1.getClient)(); // Get client instance
// Call the SDK delete method
await client.profiles.delete(profileId);
// Return success
return {
content: [
{
type: 'text',
text: `Successfully deleted profile with ID: ${profileId}`,
},
],
isError: false,
};
}
catch (error) {
let errorMessage = `An unknown error occurred while deleting profile ${profileId}.`;
let isError = true;
// Check if it's a specific Hyperbrowser SDK error
if (error instanceof sdk_1.HyperbrowserError) {
if (error.statusCode === 404) {
errorMessage = `Profile with ID ${profileId} not found.`;
// Optionally, you might decide this isn't a true 'error' state for the tool
// isError = false; // Depending on desired behavior
}
else {
errorMessage = `Failed to delete profile ${profileId}: ${error.message} (Status: ${error.statusCode || 'N/A'})`;
}
}
else if (error instanceof Error) {
errorMessage = `Failed to delete profile ${profileId}: ${error.message}`;
}
// Return error result
return {
content: [{ type: 'text', text: errorMessage }],
isError: isError,
};
}
}
exports.deleteProfileTool = deleteProfileTool;
// Export name and description separately for registration
exports.deleteProfileToolName = 'delete_profile';
exports.deleteProfileToolDescription = 'Deletes an existing persistent Hyperbrowser profile.';