LLM Researcher 是一款轻量级的 MCP(模型上下文协议)服务器,专为大语言模型编排设计,具备高效的网页内容搜索与提取能力。借助这款 CLI 工具,大语言模型可在 DuckDuckGo 上进行搜索,并从网页中提取简洁、适配大语言模型的内容。
项目采用 TypeScript、tsup 和 vitest 构建,带来现代化的开发体验。
# 克隆或下载项目
cd light-research-mcp
# 安装依赖(使用 pnpm)
pnpm install
# 构建项目
pnpm build
# 安装 Playwright 浏览器
pnpm install-browsers
# 可选:全局链接,以便在系统范围内使用
pnpm link --global
作为模型上下文协议服务器,为大语言模型提供搜索和内容提取工具:
# 启动 MCP 服务器(标准输入输出传输)
llmresearcher --mcp
# 服务器为 MCP 客户端提供以下工具:
# - github_code_search: 在 GitHub 仓库中搜索代码
# - duckduckgo_web_search: 使用 DuckDuckGo 进行网页搜索
# - extract_content: 从 URL 中提取详细内容
# 将其作为 MCP 服务器添加到 Claude Code
claude mcp add light-research-mcp /path/to/light-research-mcp/dist/bin/llmresearcher.js --mcp
# 或者使用项目范围进行团队共享
claude mcp add light-research-mcp -s project /path/to/light-research-mcp/dist/bin/llmresearcher.js --mcp
# 列出已配置的服务器
claude mcp list
# 检查服务器状态
claude mcp get light-research-mcp
配置完成后,可在 Claude 中使用这些工具:
> 在 GitHub 上搜索 React 钩子示例
Tool: github_code_search
Query: "useState useEffect hooks language:javascript"
> 搜索 TypeScript 最佳实践
Tool: duckduckgo_web_search
Query: "TypeScript best practices 2024"
Locale: us-en (或 wt-wt 表示无区域限制)
> 从搜索结果中提取内容
Tool: extract_content
URL: https://example.com/article-from-search-results
# 搜索模式 - 使用 DuckDuckGo 搜索并交互式浏览结果
llmresearcher "machine learning transformers"
# GitHub 代码搜索模式 - 在 GitHub 上搜索代码
llmresearcher -g "useState hooks language:typescript"
# 直接 URL 模式 - 从特定 URL 提取内容
llmresearcher -u https://example.com/article
# 交互模式 - 进入交互式搜索会话
llmresearcher
# 详细日志模式 - 查看详细操作日志
llmresearcher -v "search query"
# MCP 服务器模式 - 作为模型上下文协议服务器启动
llmresearcher --mcp
# 构建项目
pnpm build
# 开发模式下的构建(监听文件变化)
pnpm dev
# 运行测试
pnpm test
# 在 CI 模式下运行测试(单次运行)
pnpm test:run
# 运行测试并生成覆盖率报告
pnpm test -- --coverage
# 类型检查
pnpm type-check
# 清理构建产物
pnpm clean
# 安装 Playwright 浏览器
pnpm install-browsers
在搜索结果视图中:
在查看内容时:
在项目根目录下创建 .env 文件:
USER_AGENT=Mozilla/5.0 (compatible; LLMResearcher/1.0)
TIMEOUT=30000
MAX_RETRIES=3
RATE_LIMIT_DELAY=1000
CACHE_ENABLED=true
MAX_RESULTS=10
在主目录下创建 ~/.llmresearcherrc 文件:
{
"userAgent": "Mozilla/5.0 (compatible; LLMResearcher/1.0)",
"timeout": 30000,
"maxRetries": 3,
"rateLimitDelay": 1000,
"cacheEnabled": true,
"maxResults": 10
}
| 选项 | 默认值 | 描述 |
|---|---|---|
userAgent |
Mozilla/5.0 (compatible; LLMResearcher/1.0) |
HTTP 请求的用户代理 |
timeout |
30000 |
请求超时时间(毫秒) |
maxRetries |
3 |
失败请求的最大重试次数 |
rateLimitDelay |
1000 |
请求间隔时间(毫秒) |
cacheEnabled |
true |
启用/禁用本地缓存 |
maxResults |
10 |
显示的最大搜索结果数 |
src/mcp-server.ts)
src/search.ts)
/l/?uddg= 格式的链接进行 URL 解码。src/github-code-search.ts)
src/extractor.ts)
src/cli.ts)
src/config.ts)
你: "查找用于状态管理的 React 钩子示例"
Claude 使用 github_code_search 工具:
{
"query": "useState useReducer state management language:javascript",
"results": [
{
"title": "facebook/react/packages/react/src/ReactHooks.js",
"url": "https://raw.githubusercontent.com/facebook/react/main/packages/react/src/ReactHooks.js",
"snippet": "function useState(initialState) {\n return dispatcher.useState(initialState);\n}"
}
],
"pagination": {
"currentPage": 1,
"hasNextPage": true,
"nextPageToken": "2"
}
}
你: "搜索日语的 Vue.js 教程"
Claude 使用 duckduckgo_web_search 工具:
{
"query": "Vue.js チュートリアル 入門",
"locale": "jp-jp",
"results": [
{
"title": "Vue.js入門ガイド",
"url": "https://example.com/vue-tutorial",
"snippet": "Vue.jsの基本的な使い方を学ぶチュートリアル..."
}
]
}
你: "从那个 Vue.js 教程中提取完整内容"
Claude 使用 extract_content 工具:
{
"url": "https://example.com/vue-tutorial",
"title": "Vue.js入門ガイド",
"extractedAt": "2024-01-15T10:30:00.000Z",
"content": "# Vue.js入門ガイド\n\nVue.jsは...\n\n## インストール\n\n..."
}
$ llmresearcher "python web scraping"
🔍 搜索结果:
══════════════════════════════════════════════════
1. Python Web Scraping Tutorial
URL: https://realpython.com/python-web-scraping-practical-introduction/
完整的使用 Python 和 requests、Beautiful Soup 进行网页抓取的教程...
2. Web Scraping with Python - BeautifulSoup and requests
URL: https://www.dataquest.io/blog/web-scraping-python-tutorial/
学习如何使用 Python、Beautiful Soup 和 requests 进行网页抓取...
══════════════════════════════════════════════════
命令: [1-10] 选择结果 | b) 返回 | q) 退出 | open ) 在浏览器中打开
> 1
📥 正在从 "Python Web Scraping Tutorial" 提取内容
📄 内容:
══════════════════════════════════════════════════
**Python Web Scraping Tutorial**
来源: https://realpython.com/python-web-scraping-practical-introduction/
提取时间: 2024-01-15T10:30:00.000Z
──────────────────────────────────────────────────
# Python Web Scraping: A Practical Introduction
网页抓取是从网页收集和解析原始数据的过程...
## What Is Web Scraping?
网页抓取是一种自动访问和提取大量网页数据的技术...
══════════════════════════════════════════════════
命令: b) 返回结果 | /) 在文本中搜索 | q) 退出 | open) 在浏览器中打开
> /beautiful soup
🔍 找到 3 个与 "beautiful soup" 匹配的结果:
──────────────────────────────────────────────────
第 15 行: Beautiful Soup is a Python library for parsing HTML and XML documents.
第 42 行: from bs4 import BeautifulSoup
第 67 行: soup = BeautifulSoup(html_content, 'html.parser')
$ llmresearcher -u https://docs.python.org/3/tutorial/
📄 内容:
══════════════════════════════════════════════════
**The Python Tutorial**
来源: https://docs.python.org/3/tutorial/
提取时间: 2024-01-15T10:35:00.000Z
──────────────────────────────────────────────────
# The Python Tutorial
Python 是一种易于学习、功能强大的编程语言...
## An Informal Introduction to Python
在以下示例中,输入和输出是有区别的...
$ llmresearcher -v "nodejs tutorial"
[详细信息] 正在搜索: https://duckduckgo.com/html/?q=nodejs%20tutorial&kl=us-en
[详细信息] 响应状态码: 200,耗时 847ms
[详细信息] 解析了 10 个结果
[详细信息] 正在启动浏览器...
[详细信息] 阻止资源: https://example.com/style.css
[详细信息] 阻止资源: https://example.com/image.png
[详细信息] 正在导航到页面...
[详细信息] 页面加载完成,耗时 1243ms
[详细信息] 正在使用 Readability 处理内容...
[详细信息] Readability 提取成功
[详细信息] 正在关闭浏览器...
# 在监听模式下运行测试
pnpm test
# 单次运行测试(CI 模式)
pnpm test:run
# 运行测试并生成覆盖率报告
pnpm test -- --coverage
测试套件包括:
search.test.ts:测试 DuckDuckGo 搜索功能、URL 解码和速率限制。extractor.test.ts:测试内容提取、Markdown 转换和资源管理。config.test.ts:测试配置验证和环境处理。integration.test.ts:测试完整的搜索到提取工作流、错误处理和清理操作。“未找到浏览器” 错误
pnpm install-browsers
速率限制问题
内容提取失败
-v) 查看详细错误信息。权限拒绝(Unix/Linux)
chmod +x bin/llmresearcher.js
该工具针对速度进行了优化:
light-research-mcp/
├── dist/ # 构建生成的 JavaScript 文件
│ ├── bin/
│ │ └── llmresearcher.js # CLI 入口点(可执行文件)
│ └── *.js # 编译后的 TypeScript 模块
├── src/ # TypeScript 源代码文件
│ ├── bin.ts # CLI 入口点
│ ├── index.ts # 主要的 LLMResearcher 类
│ ├── mcp-server.ts # MCP 服务器实现
│ ├── search.ts # DuckDuckGo 搜索实现
│ ├── github-code-search.ts # GitHub 代码搜索实现
│ ├── extractor.ts # 使用 Playwright 进行内容提取
│ ├── cli.ts # 交互式 CLI 界面
│ ├── config.ts # 配置管理
│ └── types.ts # TypeScript 类型定义
├── test/ # 测试文件(使用 vitest)
│ ├── search.test.ts # 搜索功能测试
│ ├── extractor.test.ts # 内容提取测试
│ ├── config.test.ts # 配置测试
│ ├── mcp-locale.test.ts # MCP 地区功能测试
│ ├── mcp-content-extractor.test.ts # MCP 内容提取器测试
│ └── integration.test.ts # 端到端集成测试
├── tsconfig.json # TypeScript 配置文件
├── tsup.config.ts # 构建配置文件
├── vitest.config.ts # 测试配置文件
├── package.json
└── README.md
本项目采用 MIT 许可证,详情请查看 LICENSE 文件。