execute_browser_task
Automate browser tasks by describing the desired action, enabling efficient execution of web-based workflows through the Browser-use MCP Server.
Instructions
执行浏览器自动化任务
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task | Yes | 要执行的任务描述 |
Input Schema (JSON Schema)
{
"properties": {
"task": {
"description": "要执行的任务描述",
"type": "string"
}
},
"required": [
"task"
],
"type": "object"
}
Implementation Reference
- src/index.ts:94-108 (handler)The core handler function that executes the browser task by constructing and running a shell command to activate a Python virtual environment and invoke app.py with the provided task argument.private async executeBrowserTask(task: string): Promise<string> { const command = `cd /Users/charlesqin/PycharmProjects/PythonProject && \ source /Users/charlesqin/PycharmProjects/PythonProject/.venv/bin/activate && \ python app.py --task "${task}"`; try { const { stdout, stderr } = await execAsync(command); if (stderr) { console.error('执行命令时出现警告:', stderr); } return stdout || '任务执行完成,但没有输出结果'; } catch (error: any) { throw new Error(`执行命令失败: ${error?.message || '未知错误'}`); } }
- src/index.ts:46-55 (schema)Input schema for the execute_browser_task tool, defining a required 'task' property as a string describing the task to execute.inputSchema: { type: 'object', properties: { task: { type: 'string', description: '要执行的任务描述', }, }, required: ['task'], },
- src/index.ts:41-58 (registration)Registration of the execute_browser_task tool in the ListToolsRequestSchema handler, including name, description, and input schema.this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: [ { name: 'execute_browser_task', description: '执行浏览器自动化任务', inputSchema: { type: 'object', properties: { task: { type: 'string', description: '要执行的任务描述', }, }, required: ['task'], }, }, ], }));
- src/index.ts:60-91 (registration)Registration of the CallToolRequestSchema handler that specifically handles calls to 'execute_browser_task', validates the name, extracts the task argument, invokes the executeBrowserTask method, and returns the result or error response.this.server.setRequestHandler(CallToolRequestSchema, async (request) => { if (request.params.name !== 'execute_browser_task') { throw new McpError( ErrorCode.MethodNotFound, `未知工具: ${request.params.name}` ); } const { task } = request.params.arguments as { task: string }; try { const result = await this.executeBrowserTask(task); return { content: [ { type: 'text', text: result, }, ], }; } catch (error: any) { return { content: [ { type: 'text', text: `执行出错: ${error?.message || '未知错误'}`, }, ], isError: true, }; } });