Skip to content
Merged
Show file tree
Hide file tree
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
23 changes: 22 additions & 1 deletion server/mcp_server_vefaas_browser_use/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ veFaaS Browser-Use MCP server 可以让用户仅输入检索任务,就可以

| | |
|------|------|
| 版本 | v0.0.2 |
| 版本 | v0.0.3 |
| 描述 | veFaaS Browser-Use MCP server 自动化你的浏览器操作任务 |
| 分类 | 容器与中间件 |
| 标签 | veFaaS,函数服务,Browser-Use,浏览器 |
Expand Down Expand Up @@ -33,6 +33,27 @@ veFaaS Browser-Use MCP server 可以让用户仅输入检索任务,就可以
查看今日北京天气
```

### Tool 2: get_browser_use_task_status

#### 类型

查询

#### 详细描述

查询浏览器操作任务的执行状态和结果。

输出:

- 返回任务当前状态(如进行中、已完成、失败等)
- 如已完成,返回任务结果

#### 最容易被唤起的 Prompt示例

```
查询刚才浏览器任务的执行状态
```

## 可适配平台

Python, Cursor, Claude macOS App, Cline
Expand Down
2 changes: 1 addition & 1 deletion server/mcp_server_vefaas_browser_use/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ description = "MCP server for automating browser operations"
readme = "README.md"
requires-python = ">=3.12"
dependencies = [
"mcp==1.3.0",
"mcp>=1.9.0",
"requests==2.32.3"
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,25 @@

mcp = FastMCP("VeFaaS Browser Use")

HEADERS = {
"X-Faas-Event-Type": "http",
"Content-Type": "application/json"
}

@mcp.tool(description="""Creates a browser use task which can automatically browse the web.
Use this when you need to create a browser use task with specific messages.
The endpoint is read from the environment variable BROWSER_USE_ENDPOINT.
The tool will display progress updates during task execution and return the final result.
After this tool is called, automatically call tool get_browser_use_task_result to get the result.
""")
def create_browser_use_task(task: str):
def create_browser_use_task(task: str) -> str:
"""
Args:
task (str): The task description for the browser to execute. For example: "check the weather in beijing."
The task should be a clear instruction of what you want the browser to do.

Returns:
str: The task ID that can be used to retrieve results later.
"""
# check required environment variables and parameters
endpoint = os.getenv("BROWSER_USE_ENDPOINT")

Expand All @@ -40,34 +53,53 @@ def create_browser_use_task(task: str):
]
}

headers = {
"X-Faas-Event-Type": "http",
"Content-Type": "application/json"
}

try:
# 1. create a new task
response = requests.post(url, headers=headers, json=payload)
response = requests.post(url, headers=HEADERS, json=payload)

response.raise_for_status()

response_json = response.json() if response.content else None

task_id = response_json.get("task_id") if response_json else None

print(f"Task ID: {task_id}")

return task_id

# Return early if task creation failed or no task_id was returned
if not task_id:
return {
"status_code": response.status_code,
"response": response_json,
"error": "No task_id returned from task creation"
}
except requests.exceptions.RequestException as e:
error_message = f"Error in browser use task: {str(e)}"
raise ValueError(error_message)

@mcp.tool(description="""Retrieves the result of a browser use task.
The endpoint is read from the environment variable BROWSER_USE_ENDPOINT.
""")
def get_browser_use_task_result(task_id: str):
"""
Args:
task_id (str): The ID of the browser use task to retrieve results for.
This is the ID returned by create_browser_use_task.

Returns:
str: The final result from the browser task, including any choices or completion data.
"""
# check required environment variables and parameters
endpoint = os.getenv("BROWSER_USE_ENDPOINT")

if not endpoint:
raise ValueError("BROWSER_USE_ENDPOINT is not set")

if not task_id:
raise ValueError("Task ID is required")

if not endpoint.startswith("http://") and not endpoint.startswith("https://"):
endpoint = f"http://{endpoint}"

try:

# 2. stream the response
# stream the response
url = f"{endpoint}/tasks/{task_id}/stream"
response = requests.get(url, stream=True)
response = requests.get(url, headers=HEADERS, stream=True)

response.raise_for_status()

Expand All @@ -77,12 +109,12 @@ def create_browser_use_task(task: str):
if line:
if "choices" in line:
return line
break

except requests.exceptions.RequestException as e:
error_message = f"Error in browser use task: {str(e)}"
raise ValueError(error_message)


def main():
logger.info("Starting veFaaS browser use MCP Server")

Expand Down