SearXNG模型上下文协议添加福利群:解决AI开发者的「MCP实战痛点」
一个模型上下文协议(MCP)服务器,使AI助手能够使用SearXNG(一种尊重隐私的元搜索引擎)进行网络搜索。通过自动从SearX.space中选择一个随机实例来实现开箱即用,无需额外部署,同时也支持带有基本身份验证的私有实例。
注意 - 公共实例可能无法用于此目的,并返回“请求失败,状态码429”
# Clone the repository
git clone https://github.com/tisDDM/searxng-mcp.git
cd searxng-mcp
# Install dependencies
npm install
# Build the project
npm run build

SearXNG MCP 服务器可以通过以下环境变量进行配置:
SEARXNG_URL(可选):您的SearXNG实例的URL(例如,https://searx.example.com)。如果未提供,则会自动从SearX.space中选择一个随机公共实例,从而使服务器在没有额外部署的情况下即可使用。USE_RANDOM_INSTANCE(可选):设置为 "false" 以禁用在未提供URL时的随机实例选择。默认值为 "true"。SEARXNG_USERNAME(可选):连接到私有实例时的基本身份验证用户名SEARXNG_PASSWORD(可选):连接到私有实例时的基本身份验证密码您可以在项目的根目录下的 .env 文件中设置这些环境变量:
SEARXNG_URL=https://searx.example.com SEARXNG_USERNAME=your_username SEARXNG_PASSWORD=your_password
# If installed globally
searxngmcp
# If installed from source
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
# Configure the SearXNG MCP server
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", # Optional
"SEARXNG_PASSWORD": "your_password" # Optional
}
)
# Create a tool collection from the MCP server
with ToolCollection.from_mcp(server_parameters) as tool_collection:
# Initialize your LLM model
model = LiteLLMModel(
model_id="your-model-id",
api_key="your-api-key",
temperature=0.7
)
# Create an agent with the search tools
search_agent = CodeAgent(
name="search_agent",
tools=tool_collection.tools,
model=model
)
# Run the agent with a search prompt
result = search_agent.run(
"Perform a search about: 'climate change solutions' and summarize the top 5 results."
)
print(result)

使用 SearXNG(一种尊重隐私的元搜索引擎)执行网络搜索。返回具有可自定义参数的相关网页内容。
| 参数 | 类型 | 描述 | 默认值 | 是否必填 |
|---|---|---|---|---|
| query | string | 搜索查询 | - | 是 |
| language | string | 搜索结果的语言代码(例如 'en', 'de', 'fr') | 'en' | 否 |
| time_range | string | 搜索结果的时间范围。选项:'day', 'week', 'month', 'year' | null | 否 |
| categories | 字符串数组 | 搜索的类别(例如 'general', 'images', 'news') | null | 否 |
| engines | 字符串数组 | 使用的具体搜索引擎 | null | 否 |
| safesearch | number | 安全搜索级别:0(关闭),1(适中),2(严格) | 1 | 否 |
| pageno | number | 结果页码。必须至少为 1 | 1 | 否 |
| max_results | number | 返回的最大搜索结果数。范围:1-50 | 10 | 否 |
// Example request
const result = await client.callTool('searxngsearch', {
query: 'climate change solutions',
language: 'en',
time_range: 'year',
categories: ['general', 'news'],
safesearch: 1,
max_results: 5
});

# Clone the repository
git clone https://github.com/tisDDM/searxng-mcp.git
cd searxng-mcp
# Install dependencies
npm install

npm run build
npm run watch
npm run inspector
MIT