这是一个模型上下文协议(MCP)服务器,它使AI助手能够使用隐私保护的元搜索引擎SearXNG执行网络搜索。该服务器通过自动从SearX.space选择一个随机实例,无需额外部署即可立即工作,同时也支持带有基本身份验证的私有实例。
注意 - 公共实例可能不可用,并返回“请求失败,状态码429”
# 克隆仓库
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
{
"mcpServers": {
"searxngmcp": {
"command": "searxngmcp",
"env": {
// 可选:如果未提供,将使用随机公共实例
"SEARXNG_URL": "https://searx.example.com",
// 可选:仅在需要身份验证的私有实例时需要
"SEARXNG_USERNAME": "your_username",
"SEARXNG_PASSWORD": "your_password"
},
"disabled": false,
"autoApprove": []
}
}
}
{
"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": []
}
}
}
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)
使用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 | 数字 | 结果的页数。必须至少为1 | 1 | 否 |
| max_results | 数字 | 返回的最大搜索结果数量。范围:1-50 | 10 | 否 |
// 示例请求
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
npm run inspector
MIT