LM Studio的SearXNG MCP服务器
一种模型上下文协议(MCP)服务器,使用以隐私为中心的本地SearXNG实例为LM Studio中运行的本地LLM提供web搜索功能。
特性
- 网页搜索:使用本地SearXNG实例搜索网络
- 并发搜索:同时执行多个搜索
- 结果缓存:具有可配置TTL的自动缓存,以减少API调用
- 高级过滤:按域筛选结果、重复数据消除和限制结果
- 隐私第一:所有搜索都通过您的本地SearXNG实例运行
- 高性能:使用TypeScript和async/await构建,以获得最佳性能
快速开始
1.安装和构建
# Clone the repository
git clone https://github.com/Pascalrjt/SearXNG-Websearch-MCP.git
cd SearXNG-Websearch-MCP
# Install dependencies and build
npm install
npm run build2.启动SearXNG
npm run docker:up通过访问验证SearXNG是否正在运行http://localhost:8080在您的浏览器中。
3.配置LM Studio
添加到LM Studio MCP配置文件中:
{
"mcpServers": {
"websearch-searxng": {
"command": "node",
"args": ["/path/to/SearXNG-Websearch-MCP/dist/index.js"],
"env": {}
}
}
}配置文件位置:
- macOS:
~/Library/Application Support/LM Studio/mcp_config.json - 视窗:
%APPDATA%\LM Studio\mcp_config.json - Linux:
~/.config/lm-studio/mcp_config.json
备注:替换 /path/to/SearXNG-Websearch-MCP 使用您的实际安装路径。
4.重新启动LM Studio
关闭并重新打开LM Studio,以便识别MCP服务器。
5.测试一下
试着问你的法学硕士:
Search for "quantum computing breakthroughs 2024" and summarize the top findings先决条件
- Node.js 18或更高版本
- Docker和Docker Compose
- LM工作室
系统提示
存储库包括 prompt.md,一个全面的系统提示,指导您的法学硕士有效地使用网络搜索工具。该提示教导法学硕士:
- 始终确定时间敏感查询的当前日期
- 跨多个来源验证事实
- 使用高级筛选(域、时间范围、类别)
- 处理复杂研究的并发搜索
- 正确管理搜索缓存
在LM Studio中使用系统提示
- 打开
prompt.md在存储库中 - 复制全部内容
- 在LM Studio中,请访问 设置→ 系统提示
- 粘贴提示
LLM现在将更有效地自动使用网络搜索工具,提供更好的研究和事实验证。
详细安装
1.克隆存储库
git clone
cd websearch-searXNG2.安装依赖项
npm install3.启动SearXNG Docker容器
npm run docker:up这将启动SearXNG http://localhost:8080。您可以通过在浏览器中访问此URL来验证它是否正在运行。
4.构建MCP服务器
npm run build可用工具
1. web_search
使用高级过滤选项执行单个网络搜索。
参数:
query(必填):搜索查询字符串maxResults(可选,默认值:10):返回的最大结果数language(可选):结果的语言代码(例如,“en”、“es”、“fr”)timeRange(可选):按时间筛选(“天”、“周”、“月”、“年”)categories(可选):类别数组(例如,\[“一般”、“新闻”\])includeDomains(可选):仅包含来自这些域的结果excludeDomains(可选):从这些域中排除结果deduplicateByDomain(可选,默认值:false):每个域只返回一个结果
2. multi_search
同时执行多个搜索以高效收集信息。
参数:
queries(必填):搜索查询对象数组
- 每个查询可以有: query, maxResults, language, timeRange, categories
globalFilters(可选):应用于所有结果的筛选器
- includeDomains, excludeDomains, deduplicateByDomain
3. clear_cache
清除搜索结果缓存以释放内存或强制刷新结果。
参数: 无
使用示例
基本搜索
Search for "climate change solutions" and summarize the findings时间筛选搜索
Search for news about "artificial intelligence" from the last week特定域搜索
Search for "TypeScript best practices" but only show results from
official documentation sites like typescriptlang.org and microsoft.com排除域
Search for recent news about "renewable energy" from the last month,
excluding results from social media domains多个并发搜索
I need to compare three topics. Search for:
1. "rust programming language advantages"
2. "golang performance benchmarks"
3. "python async programming"
Summarize the key differences between these languages.复杂研究查询
I need information on "quantum computing", "artificial intelligence ethics",
and "blockchain technology". Search for all three and compare their current state.Docker管理
启动SearXNG
npm run docker:up停止SearXNG
npm run docker:down查看SearXNG日志
npm run docker:logs访问SearXNG Web界面
打开浏览器并导航到:http://localhost:8080
发展
构建TypeScript
npm run build观看模式(用于开发)
npm run dev建筑
┌─────────────┐
│ LM Studio │
└──────┬──────┘
│ MCP Protocol
│
┌──────▼──────────────┐
│ MCP Server │
│ (index.ts) │
└──────┬──────────────┘
│
┌──────▼──────────────┐
│ SearXNG Client │
│ (searxng-client.ts)│
│ │
│ ┌───────────────┐ │
│ │ Cache System │ │
│ └───────────────┘ │
└──────┬──────────────┘
│ HTTP API
│
┌──────▼──────────────┐
│ SearXNG Instance │
│ (Docker Container) │
│ localhost:8080 │
└─────────────────────┘缓存行为
- 默认情况下,搜索结果缓存5分钟
- 缓存密钥由搜索参数生成
- 每分钟自动清理过期条目
- 使用
clear_cache手动清除缓存的工具
过滤能力
域名筛选
- 包含域名:仅显示指定域的结果
- 排除域:从指定域中筛选结果
结果限制
- 最大结果:限制返回的结果数量
- 按域进行重复数据删除:每个域只显示一个结果
时间范围过滤
- 日:过去24小时的结果
- 周:过去7天的结果
- 月:过去30天的结果
- 年:过去365天的结果
故障排除
LM Studio中的MCP服务器未连接
- 验证构建是否成功完成:
npm run build - 检查dist文件夹是否存在:
ls dist/index.js - 确保LM Studio配置中的路径是绝对正确的
- 完全重新启动LM Studio
搜索未返回任何结果
- 验证SearXNG是否正在运行:访问http://localhost:8080浏览器中
- 测试API:
curl "http://localhost:8080/search?q=test&format=json" - 使用清除缓存
clear_cache工具 - 检查Docker日志:
npm run docker:logs
SearXNG集装箱无法启动
# Check if port 8080 is already in use
lsof -i :8080
# View container logs
npm run docker:logs
# Restart the container
npm run docker:down && npm run docker:up缓存问题
使用 clear_cache LM Studio中的工具,或重新启动LM Studio以重新启动MCP服务器。
性能提示
- 使用缓存:结果将自动缓存5分钟
- 并发搜索:使用
multi_search用于多个查询而不是顺序搜索 - 早期筛选:使用
maxResults限制结果并减少处理 - 域名筛选:按域筛选以更快地获得更相关的结果
- 系统提示:使用随附的
prompt.md教授你的法学硕士最佳搜索策略
安全与隐私
- 所有搜索都通过您的本地SearXNG实例运行
- 未向外部MCP提供商发送数据
- SearXNG可以配置为使用特定的搜索引擎
- 完全控制搜索隐私设置
贡献
欢迎投稿!请随时提交问题或拉取请求。
支持
如果您遇到问题:
- 检查上面的故障排除部分
- 查看SearXNG日志:
npm run docker:logs - 验证你的Node.js版本:
node --version(应该是18+) - 确保Docker正常运行
- 检查LM Studio配置中的路径是否正确且绝对
