OpenBrowser
Open a specific URL directly in a web browser using Astra DB MCP Server, enabling efficient navigation and interaction with linked resources.
Instructions
Open a web browser to a specific URL
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | The URL to open in the browser |
Input Schema (JSON Schema)
{
"properties": {
"url": {
"description": "The URL to open in the browser",
"type": "string"
}
},
"required": [
"url"
],
"type": "object"
}
Implementation Reference
- tools/OpenBrowser.ts:5-54 (handler)The core handler function for the OpenBrowser tool. Validates the URL (only http/https allowed), determines platform-specific command to open the browser, and executes it safely using execFile to prevent injection.export async function OpenBrowser(params: { url: string }) { const { url } = params; // Validate URL to prevent command injection let validatedUrl: string; try { // Validate URL format const parsedUrl = new URL(url); // Only allow http and https protocols if (!['http:', 'https:'].includes(parsedUrl.protocol)) { return { success: false, message: "Invalid URL protocol. Only http and https are supported.", }; } validatedUrl = parsedUrl.toString(); } catch (e) { return { success: false, message: `Invalid URL format: ${e instanceof Error ? e.message : String(e)}`, }; } // Determine the command based on platform const command = platform() === "darwin" ? "open" : platform() === "win32" ? "start" : "xdg-open"; return new Promise<{ success: boolean; message: string }>( (resolve) => { // Use execFile instead of exec to prevent command injection execFile(command, [validatedUrl], (error) => { if (error) { resolve({ success: false, message: `Failed to open browser: ${error.message}`, }); } else { resolve({ success: true, message: `Successfully opened ${validatedUrl} in default browser`, }); } }); } ); }
- tools.ts:428-437 (schema)JSON schema for OpenBrowser tool input, requiring a 'url' string parameter.inputSchema: { type: "object", properties: { url: { type: "string", description: "The URL to open in the browser", }, }, required: ["url"], },
- tools.ts:425-438 (registration)Registration of the OpenBrowser tool in the exported tools array used for MCP listTools capability.{ name: "OpenBrowser", description: "Open a web browser to a specific URL", inputSchema: { type: "object", properties: { url: { type: "string", description: "The URL to open in the browser", }, }, required: ["url"], }, },
- index.ts:348-359 (registration)MCP server request handler dispatches calls to the OpenBrowser tool function.case "OpenBrowser": const openBrowserResult = await OpenBrowser({ url: args.url as string, }); return { content: [ { type: "text", text: openBrowserResult.message, }, ], };