通過 MCP 給 Cherry Studio 增加聯網搜索能力

前言

最近 MCP 很火,火到 OpenAI 都已經宣佈要支持了。老蘇也抽空玩了一下,先後用過 ClineHyperChat 、DeepChatCherry Studio 這些 AI 助手。從使用體驗上看, Cline 最好,HyperChat 次之。

Cherry Studio 現在在 MCP 上還差點意思,但進步挺快的。加上 Cherry Studio 豐富的功能,所以還是作爲主力工具在使用。

Cherry Studio  本身已經支持聯網搜索功能,但都需要 API Key,像 tavily 就有 1000 次 / 月的限制。所以老蘇打算用 MCP 來增強 Cherry Studio 的聯網搜索能力,經過一番搜索,老蘇找到了 Google Search Tool 這個項目。

在開始前,有必做個簡單的介紹

什麼是 MCP ?

MCP 是一種開放協議,它標準化了應用程序向 LLM 提供上下文的方式。可以將 MCP 視爲 AI 應用程序的 USB-C 端口。正如 USB-C 提供了一種將設備連接到各種外圍設備和配件的標準化方式一樣,MCP 提供了一種將 AI 模型連接到不同數據源和工具的標準化方式。

MCP 支持兩種類型,目前似乎主要以 STDIO 爲主

什麼是 Google Search Tool ?

Google Search Tool 是基於 Playwright 的 Node.js 工具,能夠繞過搜索引擎的反爬蟲機制,執行 Google 搜索並提取結果。

雖然有很多優勢,但因爲使用 Google 搜索,所以需要自己解決網絡問題

安裝

下面以 Windows 環境爲例,簡單介紹安裝流程

Node.js

因爲 Google Search Tool 是 Node.js 開發的工具,所以首先需要在本機上安裝 Node.js 環境

在 https://nodejs.org/zh-cn 下載 LTS版本

安裝完成後,需要在 CMD 下進行驗證

# 檢查 Node.js 的版本號
node --version

# 檢查 npm 的版本
npm --version

源碼安裝

Google Search Tool 支持 npx 和 node 兩種安裝方式,老蘇嘗試了 npx 安裝,但是顯示了錯誤

添加服務器失敗:Error invoking remote method 'mcp:add-server':McpError: MCP error -32080:Connection closed

所以只能採用源碼安裝方式。先要安裝 git,下載地址: https://git-scm.com/downloads,選擇對應的平臺

安裝完成後,可以在 CMD 下進行驗證

如果沒問題的話,就繼續可以依次執行下面的命令,完成對源代碼的編譯

# 從源碼安裝
git clone https://github.com/web-agent-master/google-search.git

# 通過代理
git clone https://gh-proxy.com/github.com/web-agent-master/google-search.git

# 進入目錄
cd google-search

# 安裝依賴
npm install

# 編譯 TypeScript 代碼
npm run build

編譯完成後,需要找到 mcp-server.js 所在的完整路徑,後面設置時會用到

老蘇的是  C:\Users\Administrator\Downloads\mcp\google-search\dist\src\mcp-server.js,在 windows 上寫入配置時,要將 \ 改爲 /,所以最終的完整路徑是 : C:/Users/Administrator/Downloads/mcp/google-search/dist/src/mcp-server.js

設置

在 Cherry Studio 中找到 MCP 服務器,添加 MCP服務器有兩種方式

更簡單的方式是直接編輯 json 文件

{
  "mcpServers": {
    "google-search": {
      "command""cmd",
      "args": ["/c""node""C:/Users/Administrator/Downloads/mcp/google-search/dist/src/mcp-server.js"]
    }
  }
}

具體到 Cherry Studio 還要增加 description 和 isActive

    "google-search": {
      "description""基於 Playwright 的 Node.js 工具,能夠繞過搜索引擎的反爬蟲機制,執行 Google 搜索並提取結果。",
      "isActive": true,
      "command""cmd",
      "args": [
        "/c",
        "node",
        "C:/Users/Administrator/Downloads/mcp/google-search/dist/src/mcp-server.js"
      ]
    }

如果是 Cline 增需要增加 autoApprove 和 disabled

{
  "mcpServers": {
    "google-search": {
      "command""cmd",
      "args": [
        "/c",
        "node",
        "C:/Users/Administrator/Downloads/mcp/google-search/dist/src/mcp-server.js"
      ],
      "disabled": false,
      "autoApprove": [
        "google-search"
      ]
    }
  }
}

運行

在 Cherry Studio 中,似乎對模型有要求,查了些資料,有說法是需要大語言模型支持函數調用,但老蘇覺得不準確

HyperChat 直接限定了必須要支持函數調用的大語言模型纔行,但有自己的測試流程

因爲老蘇測試了代理的 gemini 模型,並不能支持 MCP 調用。老蘇不確定是不是 Cherry Studio  的原因

提問前,別忘了啓用 MCP 服務器

同樣的問題在 Cline 中是可以的

不僅有結果,也顯示了詳細的過程

老蘇選擇了未聯網的火山模型,雖然大語言模型沒有顯示支持函數調用

但是確實首先執行了 google-search

過程沒有任何渲染,只是一個 json 體

小結

MCP 確實是好東西,但是 Windows 上環境安裝是個大問題,明明老蘇已經安裝了 uv

但是 Cherry Studio 不僅沒檢查到,而且使用界面上的安裝還總是不成功

而在 HyperChat 中就能檢測到 npx 和 uv 的版本

原本只要簡單修改 json 配置文件就可以,現在變成了回回都要從源碼下載開始,無形中增加了很多工作量,也容易對大部分人產生困擾,畢竟不是人人都像老蘇這麼有閒愛折騰。

所以從這個角度看,也許 MacOS 和 Linux 比 Windows 更適合運行 MCP 服務,尤其是 Linux,直接運行 Docker 類型的 MCP 服務會更簡單

參考文檔

  1. web-agent-master/google-search: A Playwright-based Node.js tool that bypasses search engine anti-scraping mechanisms to execute Google searches. Local alternative to SERP APIs with MCP server integration.
    地址:https://github.com/web-agent-master/google-search

  2. MCP | CherryStudio
    地址:https://docs.cherry-ai.com/cherrystudio/preview/mcp

  3. Introduction - Model Context Protocol
    地址:https://modelcontextprotocol.io/introduction

  4. Windows 環境下安裝與配置 Node.js - RioTian
    地址:https://www.cnblogs.com/RioTian/p/17128654.html

  5. Windows 系統 Git 安裝教程(詳解 Git 安裝過程) - 學爲所用 - 博客園
    地址:https://www.cnblogs.com/xueweisuoyong/p/11914045.html

本文由 Readfog 進行 AMP 轉碼,版權歸原作者所有。
來源https://mp.weixin.qq.com/s/tWgoUJyN1FQ8hJqImAgc8g