Skip to main content
Glama
win4r
by win4r

execute_browser_task

Automate browser actions by executing tasks described in plain text, enabling web automation through the Browser-use MCP Server.

Instructions

执行浏览器自动化任务

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
taskYes要执行的任务描述

Implementation Reference

  • The core handler function that executes the browser task by running a shell command to activate a Python virtual environment and execute 'app.py --task "${task}"'. This is the exact implementation of the tool logic.
      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:60-91 (registration)
    Registers the CallToolRequestSchema handler, which validates the tool name 'execute_browser_task', extracts the 'task' argument, calls the core handler, and formats the response or error.
    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,
        };
      }
    });
  • src/index.ts:41-58 (registration)
    Registers the tool 'execute_browser_task' in the ListToolsRequestSchema response, including its description and input schema requiring a 'task' string.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: [
        {
          name: 'execute_browser_task',
          description: '执行浏览器自动化任务',
          inputSchema: {
            type: 'object',
            properties: {
              task: {
                type: 'string',
                description: '要执行的任务描述',
              },
            },
            required: ['task'],
          },
        },
      ],
    }));
  • Defines the input schema for the tool: an object with a required 'task' property of type string.
    inputSchema: {
      type: 'object',
      properties: {
        task: {
          type: 'string',
          description: '要执行的任务描述',
        },
      },
      required: ['task'],
    },
Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/win4r/browser-use-MCP-Server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server