Creating an MCP Agent with Local/LAN DeepSeek Service for Browser Control

  liuyuancheng        2025-03-24 19:55:19       2,094        0          English  简体中文  繁体中文  ภาษาไทย  Tiếng Việt 

title16.png

在本文中,我們將探討如何構建一個 AI 驅動的 Model Context Protocol (MCP) 代理,該代理可以幫助使用者操作網路瀏覽器,以根據人類語言指令完成任務或產生網路流量。 這是透過強大的 browser-use 函式庫,並結合本地/LAN 配置的 DeepSeek LLM 模組服務來實現的。

我們將逐步介紹如何在本地 LAN 環境中設定 Ollama DeepSeek-R1 Service,將其與 MCP 代理連結,並與瀏覽器自動化整合。 由於 DeepSeek 模型在本地執行,因此您不必擔心「deepseek 服務繁忙」的問題和 token 費用。 此外,此設定允許測試各種模型或包含自定義微調的 DeepSeek 版本,以比較不同模型的效能。

本文將涵蓋以下章節:

  • Agent Test Scenario Introduction – 使用範例的用例概述。

  • Agent Operation Detailed Design – MCP 代理如何與瀏覽器互動的技術介紹。

  • Test Environment Setup – 配置本地 DeepSeek 服務和瀏覽器互動模組。

  • Test Result Summary and Conclusion – 評估效能、見解和潛在改進。

# Created:     2025/03/08
# version:     v_0.0.1
# Copyright:   Copyright (c) 2025 LiuYuancheng
# License:     MIT License

MCP Agent Task Scenarios

為了展示 MCP 代理的功能,我們透過兩個任務情境評估其效能。 在每種情況下,代理都會收到人類語言輸入字串,並自主地與網路瀏覽器互動,以檢索和總結相關資訊。 最終輸出是一個簡潔的文字摘要檔案。

Scenario 1: General Information Search & Summarization

在此情境中,代理執行網路搜尋、收集相關內容並產生結構化摘要。

Human Language Input string:

Use google search 'deepseek', go to its web and summarize the web contents in 300 words.

Agent Operation: 代理啟動搜尋查詢、從多個來源提取關鍵詳細資訊,並編譯摘要。 演示影片如下所示:

s_01.gif

Figure-01: Scenario 1: General Information Search & Summarization record, version v_0.0.1 (2025)

Scenario 2: Targeted Web Content Extraction & Summarization

在這裡,代理的任務是訪問特定的網站或專案儲存庫,提取關鍵詳細資訊(例如,README 檔案),並總結內容。

Human Language Input string:

Find the project “Deepseek_Local_LATA,” open the README file, and summarize the project in 100 words.

Agent Operation: 代理找到儲存庫、提取 README 內容,並產生簡潔的摘要。 演示影片如下所示:

s_021.gif

Figure-02: Scenario 2: Targeted Web Content Extraction & Summarization record, version v_0.0.1 (2025)

這些情境展示了 MCP 代理如何自主地瀏覽網路、檢索相關資訊並提供結構化摘要,所有這些都由本地/LAN DeepSeek AI 處理提供支援,以提高效率和控制。


MCP Agent Operation Detailed Design

在深入研究代理的詳細設計之前,讓我們先介紹一些關於 Model Context Protocol (MCP) 的背景知識。 MCP 是一個開放標準,可實現 AI 助理與各種資料來源之間的安全且標準化的連線。 它允許大型語言模型 (LLM) 直接訪問工具和資料集,從而提高它們檢索和處理資訊的能力。

Background: Model Context Protocol (MCP)

在 MCP 架構中,MCP Servers 充當輕量級程式,透過標準化協定公開特定功能。 MCP Service 充當中間層,將應用程式或工具與 LLM 服務橋接。 這些服務包括各種 MCP Agents,每個代理都提供工具、資源和提示範本,從而實現 AI 系統與客戶端之間的動態互動。

對於此專案,我們開發了一個簡單的 MCP Agent,它可以與網路瀏覽器互動。 此代理的工作流程如下所示:

s_049.png

Figure-03: simple workflow diagram of browser control MCP agent, version v_0.0.1 (2025)

透過使用基於 URI 的存取模式管理資源並支援功能協商,MCP Servers 在擴展 AI 系統的功能方面發揮著至關重要的作用,使它們能夠安全有效地執行操作或檢索資訊。

Agent Workflow Overview

代理工作流程非常簡單,如下所示,它分為三個主要步驟:

  • Step 1: Add Scenario Prompt & Generate a To-Do List.

  • Step 2: Interact with the Browser and analyze the page contents.

  • Step 3: Generate the Final Summary/Result and verify tasks finished.

s_036.png

Figure-04: detailed workflow diagram of browser control MCP agent, version v_0.0.1 (2025)

Step 1: Add Scenario Prompt & Generate a To-Do List

代理首先將使用者的輸入請求修改為結構化的 To-Do list。 此步驟確保代理了解如何系統地執行請求的任務。 以下是我們在使用者請求之前附加的範例提示:

Prompt: I am an AI agent program can simulate human actions as a beginner user to use browser, please create the TO-DO steps need to be simulated for the task:

當使用者輸入字串 Google search DeepSeek and summarize the product features in 300 words 時,傳送到 AI 的請求代理將修改為以下內容:

# Input to deepseekR1:8b model
Prompt: I am an AI agent program can simulate human actions as a beginner user to use browser, please create the TO-DO steps need to be simulated for the task: Using Google search to find DeepSeek and summarize its product features in 300 words.

The output should exactly follow the JSON format below:
{
  "initURL":"",
  "tasksList":[
      "1. ",
      "2. ",
      "3. ",
      "4. ",
      ...
  ]
}

然後,我們將請求傳送到 Deepseek 以取得以下 ToDo 清單:

# Output from deepseekR1:8b model
initURL = "https://www.google.com/"
tasksList = [
"1. Type in for 'deepseek' in the Google page's search bar",
"2. Click the first search result",
"3. Select the first deepseek link in the google search result page"
"4. Base on the web content in the link, summarize the contents in 300 words"
]
Step 2: Agent Interact with the Host's Browser

產生 To-Do list 後,代理會使用 Playwright 函式庫和 browser-use 互動模組自主執行這些步驟:

  1. 開啟 deepseek-r1:8b 模型給定的初始 URL(Google 搜尋頁面)。

  2. 從 To-Do list 執行循序動作(例如,輸入、點擊、導航)。

  3. 使用 browser-use 分析目前網頁的內容,並判斷其是否滿足步驟要求。

  4. 繼續執行下一步,直到完成所有任務。

每個步驟都會根據即時網頁分析進行評估,以確保準確執行。 如果無法完成某個步驟,代理會嘗試採取糾正措施或記錄錯誤。

參考:

Step3: Generate the Result Summary

完成 To-Do list 中的所有任務後,提取的內容將傳送到 DeepSeek LLM 進行摘要。 傳送到 LLM 的最終驗證提示:

The result content is: . 

Can this content fulfill the user's goal to Google search DeepSeek and summarize its product features in 300 words?

最終輸出包括:

  • 提取的內容摘要。

  • DeepSeek 對結果準確性的驗證。

  • 用於進一步評估的已歸檔測試結果。

 

可以進一步擴展此代理,以支援不同的雲端或本地 AI 模型、自定義瀏覽自動化以及基於使用者定義情境的多步驟推理任務。

 


Environment Introduction and Setup

Environment Over View

在此測試環境設定中,我們配置了一個區域網路 (LAN),其中至少有兩種機器:

  • 一個由 GPU 驅動的伺服器,用於託管 DeepSeek 服務。

  • 多個標準筆記型電腦,用於執行瀏覽器控制代理。

AI 代理將負責控制筆記型電腦上的瀏覽器,網路拓撲如下所示:

s_037.png

Figure-05: Test environment network connection configuration, version v_0.0.1 (2025)

為了建立此環境,我們需要執行以下設定,配置如下所示:

  • 在 GPU 伺服器上部署 DeepSeek 服務。

  • 在筆記型電腦上安裝和配置瀏覽器控制代理。

VM name IP address Hardware spec OS Program Human Language Requests
Local GPU server 192.168.50.12 Intel-i5, 32GB, RTX-3060 Windows- 11 Ollama [deepseek-r1:8b] N.A
Laptop01 192.168.50.112 Intel-i5, 16GB, RTX-1060 Windows- 11 Browser Control Agent Google search deepseek and summarize the product features in 300 words.
Laptop02 192.168.50.113 Intel-i5, 16GB, Intel UHD GPU Windows- 11 Browser Control Agent Find the project "Deepseek_Local_LATA" and open the readme file, summarize the project in 100 words.

Setting Up the DeepSeek Service on the GPU Node

GPU 伺服器需要使用 Ollama 執行 DeepSeek-R,並將服務連線公開給 LAN 節點。

Step 1 : Install Ollama LLM Service

從官方網站下載 Ollamahttps://ollama.com/download,然後選擇適合您作業系統的套件並安裝它。

Step 2 Download and Run DeepSeek-R

由於我們的 GPU 伺服器具有 RTX 3060 (12GB),因此我們使用 8B 模型。 執行以下命令以下載並啟動 DeepSeek-R1:8b 模型:

ollama run deepseek-r1:8b

若要檢查您的 GPU 節點可以執行的最大 deepseek 模型,您可以參考此連結:https://www.linkedin.com/pulse/deploying-deepseek-r1-locally-custom-rag-knowledge-data-yuancheng-liu-uzxwc

Step 3: Expose DeepSeek Service to LAN

在 Mac 上設定環境變數

如果 Ollama 作為 macOS 應用程式執行,則應使用 launchctl 設定環境變數:

  1. 對於每個環境變數,呼叫 launchctl setenv

launchctl setenv OLLAMA_HOST "0.0.0.0:11434"
  1. 重新啟動 Ollama 應用程式。

在 Linux 上設定環境變數

如果 Ollama 作為 systemd 服務執行,則應使用 systemctl 設定環境變數:

  1. 透過呼叫 systemctl edit ollama.service 來編輯 systemd 服務。 這將開啟一個編輯器。

  2. 對於每個環境變數,在 [Service] 區段下新增一行 Environment

    [Service]
    Environment="OLLAMA_HOST=0.0.0.0:11434"
  3. 儲存並退出。

  4. 重新載入 systemd 並重新啟動 Ollama:

    systemctl daemon-reload
    systemctl restart ollama

在 Windows 上設定環境變數

在 Windows 上,Ollama 會繼承您的使用者和系統環境變數。

  1. 首先,透過在工作列中點擊 Ollama 來退出 Ollama。

  2. 啟動設定 (Windows 11) 或控制台 (Windows 10) 應用程式,然後搜尋環境變數

  3. 點擊編輯您帳戶的環境變數

  4. 為您的使用者帳戶編輯或建立一個新的 OLLAMA_HOST 變數,將其值設定為 0.0.0.0

  5. 點擊確定/套用以儲存。

  6. 從 Windows 開始功能表啟動 Ollama 應用程式。

Reference : https://github.com/ollama/ollama/blob/main/docs/faq.md#how-do-i-configure-ollama-server

Configure the Agent on Operation Node

節點 GPU 節點已準備就緒,我們需要配置每個操作節點筆記型電腦。 操作節點需要:一個現代網路瀏覽器、Python 3.11 或更高版本、已安裝的必要 Python 函式庫。

Step 1 : Install Required Python Libraries

安裝 Ollama 和 LangChain 支援:

pip install ollama
pip install langchain-ollama

安裝 browser-use 自動化函式庫:

pip install browser-use

安裝 Playwright 以進行瀏覽器控制:

playwright install
Step 2: Configure Agent Parameters

每台筆記型電腦都執行一個與 DeepSeek 互動的瀏覽器控制代理,將檔案 dsBrowserCtrlAgent.pydsBrowserCtrlConfig.txtConfigLoader.py 下載到操作節點。

根據 GPU 節點和執行的模型設定 deepseek 服務配置 dsBrowserCtrlConfig.txt

# This is the config file template for the module 
# Setup the parameters with below format (every line follow : format, the
# key can not be changed):
#-----------------------------------------------------------------------------
# GPU node IP address which provide the ollama service.
OLLAMA_HOST_IP:192.168.50.12
#-----------------------------------------------------------------------------
# The deepseek model name we want to use.
DP_MODEL_NAME:deepseek-r1:8b
#-----------------------------------------------------------------------------
# The deepseek CTX number name we want to use, # for deepseek-r1:7b and 8b use
# 6000, for higher model use 32000
NUM_CTX:6000

然後將請求新增到 USER_REQUEST 參數,如下所示,然後啟動:

#-----------------------------------------------------------------------------
# the user request string such as Use google search 'deepseek', go to its web
# and summarize the web contents in 100 words
USER_REQUEST:Use google search 'deepseek', go to its web and summarize the web contents in 100 words
Step 3: Run the MCP Agent

然後使用以下命令執行代理並收集結果。

python dsBrowserCtrlAgent.py

代理將連線到執行 DeepSeek-R1 的 GPU 伺服器、執行瀏覽器互動(例如,搜尋、點擊、摘要),並根據請求傳回處理後的輸出。

程式碼連結:https://github.com/LiuYuancheng/Deepseek_Local_LATA/tree/main/Application/BrowserAgent


Test Result Summary and Conclusion

在評估期間,我們測試了四種不同的 DeepSeek 模型大小,以分析它們對任務完成和執行速度的影響。 測試涉及執行一系列基於瀏覽器的任務,包括搜尋特定專案、選擇相關連結、閱讀內容和總結資訊。

以下是情境 2 的任務結果:

Function \ Deepseek model deepseek-r1:1.5b deepseek-r1:7b deepseek-r1:8b deepseek-r1:14b
Generate Todo List Finished Finished Finished Finished
1. Click the search icon(magnifier) at the top of the page. Finished Finished Finished Finished
2. Type in 'Deepseek_Local_LATA' in th search bar. Failed Finished Finished Finished
3. Select the link Deepseek_Local_LATA in the result Failed Finished Finished Finished
4. Select README.md file link and scroll down Failed Failed Finished Finished
5. Base on the readme content in the link, summarize the contents in 100 words Failed Failed Finished Finished

在測試期間,有一些觀察結果:

  • 基本任務完成:所有模型,包括最小的模型 (1.5B),都成功執行了簡單的動作,例如產生待辦事項清單和點擊搜尋圖示。

  • 搜尋和導航:低於 7B 的模型難以執行關鍵字搜尋和選擇相關連結。

  • 內容處理:需要至少 8B 才能有效地閱讀和總結 README 檔案。

  • 效能擴展14B 模型表現出卓越的效能,成功完成了所有任務,並確保了更好的執行速度和準確性。

結論

測試結果突顯了模型大小顯著影響任務成功率和執行效率。8B model 是基本瀏覽任務的最低可行選項,而大於 14B 的模型建議用於處理更複雜、多步驟的流程,具有更高的準確性和可靠性。

此設計確保使用 MCP 驅動的 AI 代理執行基於瀏覽器的任務時,採用結構化、自動化和準確的方法。透過整合本地 DeepSeek LLM 處理,使用者可以受益於:

  • 與基於雲端的解決方案相比,更低的延遲

  • 透過消除對外部 API 的依賴,實現成本效益

  • 針對客製化 AI 驅動的自動化,提供客製化彈性

對於尋求更高準確性和穩健執行的使用者,建議投資更大的 DeepSeek 模型(14B 及以上),以最大限度地提高 AI 驅動的瀏覽器任務自動化的效能和可靠性。


感謝您花時間查看文章詳細資訊,如果您有任何問題和建議或發現任何程式錯誤,請隨時給我留言。非常感謝您能提供一些評論並分享任何改進建議,以便我們能夠改進我們的工作~


last edit by LiuYuancheng ([email protected]) by 18/03/2025 if you have any problem, please send me a message.

           

  RELATED


  0 COMMENT


No comment for this article.



  RANDOM FUN

Compilation without error in one shot


  SUPPORT US