返回市场
搜索引擎-mcp

搜索引擎-mcp

作者:tisDDM26 星标更新:2025-03-31

项目介绍

SearXNG MCP 服务器

<p align="center"> <img src="logo.png" alt="SearXNG MCP Logo" width="200" height="200"> </p>

这是一个模型上下文协议(MCP)服务器,它使AI助手能够使用隐私保护的元搜索引擎SearXNG执行网络搜索。该服务器通过自动从SearX.space选择一个随机实例,无需额外部署即可立即工作,同时也支持带有基本身份验证的私有实例。

功能

  • 零配置设置:通过使用来自SearX.space的一个随机公共实例立即工作。
  • 私有实例支持:连接到您自己的SearXNG实例,可选地使用基本身份验证。
  • 使用可定制参数执行网络搜索。
  • 支持多个搜索引擎。
  • 隐私聚焦的搜索结果。
  • Markdown格式的搜索结果。
  • 所有参数都有合理的默认值。

注意 - 公共实例可能不可用,并返回“请求失败,状态码429”

安装

先决条件

  • Node.js(v16或更高版本)
  • npm(v7或更高版本)
  • 访问SearXNG实例(自托管或公共)

从源代码安装

# 克隆仓库
git clone https://github.com/tisDDM/searxng-mcp.git
cd searxng-mcp

# 安装依赖
npm install

# 构建项目
npm run build

配置

SearXNG MCP服务器可以通过以下环境变量进行配置:

  • SEARXNG_URL(可选):您的SearXNG实例的URL(例如,https://searx.example.com)。如果没有提供,将自动选择来自SearX.space的一个随机公共实例,使得服务器可以在没有额外部署的情况下使用。
  • USE_RANDOM_INSTANCE(可选):当未提供URL时,设置为"false"以禁用随机实例选择。默认是"true"。
  • SEARXNG_USERNAME(可选):连接到私有实例时的基本身份验证用户名。
  • SEARXNG_PASSWORD(可选):连接到私有实例时的基本身份验证密码。

您可以在项目的根目录中的.env文件中设置这些环境变量:

SEARXNG_URL=https://searx.example.com
SEARXNG_USERNAME=your_username
SEARXNG_PASSWORD=your_password

使用方法

运行服务器

# 如果全局安装
searxngmcp

# 如果从源代码安装
node build/index.js

与Claude Desktop集成

  1. 打开Claude Desktop
  2. 前往设置 > MCP服务器
  3. 添加一个新的MCP服务器,配置如下:
    {
      "mcpServers": {
        "searxngmcp": {
          "command": "searxngmcp",
          "env": {
            // 可选:如果未提供,将使用随机公共实例
            "SEARXNG_URL": "https://searx.example.com",
            // 可选:仅在需要身份验证的私有实例时需要
            "SEARXNG_USERNAME": "your_username",
            "SEARXNG_PASSWORD": "your_password"
          },
          "disabled": false,
          "autoApprove": []
        }
      }
    }
    

与VSCode中的Claude集成

  1. 打开VSCode
  2. 前往设置 > 扩展 > Claude > MCP设置
  3. 添加一个新的MCP服务器,配置如下:
    {
      "mcpServers": {
        "searxngmcp": {
          "command": "node",
          "args": ["/path/to/searxng-mcp/build/index.js"],
          "env": {
            // 可选:如果未提供,将使用随机公共实例
            "SEARXNG_URL": "https://searx.example.com",
            // 可选:仅在需要身份验证的私有实例时需要
            "SEARXNG_USERNAME": "your_username",
            "SEARXNG_PASSWORD": "your_password"
          },
          "disabled": false,
          "autoApprove": []
        }
      }
    }
    

与Smolagents一起使用

SearXNG MCP可以轻松集成到Smolagents中,这是一个用于构建AI代理的轻量级框架。这允许您创建强大的研究代理,它们可以搜索网络并处理结果:

from smolagents import CodeAgent, LiteLLMModel, ToolCollection
from mcp import StdioServerParameters

# 配置SearXNG MCP服务器
server_parameters = StdioServerParameters(
    command="node",
    args=["path/to/searxng-mcp/build/index.js"],
    env={
        "SEARXNG_URL": "https://your-searxng-instance.com",
        "SEARXNG_USERNAME": "your_username",  # 可选
        "SEARXNG_PASSWORD": "your_password"   # 可选
    }
)

# 从MCP服务器创建工具集合
with ToolCollection.from_mcp(server_parameters) as tool_collection:
    # 初始化您的LLM模型
    model = LiteLLMModel(
        model_id="your-model-id",
        api_key="your-api-key",
        temperature=0.7
    )
    
    # 创建具有搜索工具的代理
    search_agent = CodeAgent(
        name="search_agent",
        tools=tool_collection.tools,
        model=model
    )
    
    # 使用搜索提示运行代理
    result = search_agent.run(
        "执行关于'气候变化解决方案'的搜索,并总结前5个结果。"
    )
    
    print(result)

可用工具

searxngsearch

使用SearXNG(一种尊重隐私的元搜索引擎)执行网络搜索。返回相关网络内容,具有可定制参数。

参数

参数名类型描述默认值必需
query字符串搜索查询-
language字符串搜索结果的语言代码(例如,'en','de','fr')'en'
time_range字符串搜索结果的时间范围。选项:'day','week','month','year'null
categories字符串数组要搜索的类别(例如,'general','images','news')null
engines字符串数组要使用的特定搜索引擎null
safesearch数字安全搜索级别:0(关闭),1(适度),2(严格)1
pageno数字结果的页数。必须至少为11
max_results数字返回的最大搜索结果数量。范围:1-5010

示例

// 示例请求
const result = await client.callTool('searxngsearch', {
  query: '气候变化解决方案',
  language: 'en',
  time_range: 'year',
  categories: ['general', 'news'],
  safesearch: 1,
  max_results: 5
});

开发

设置

# 克隆仓库
git clone https://github.com/tisDDM/searxng-mcp.git
cd searxng-mcp

# 安装依赖
npm install

构建

npm run build

监视模式(开发用途)

npm run watch

使用MCP Inspector测试

npm run inspector

许可证

MIT