使用说明
🌐 MCP浏览器搜索服务器
一个全面的模型上下文协议(MCP)服务器,提供高级网络搜索和内容提取功能。专为AI应用程序、Claude Desktop和任何兼容MCP的客户端而构建。
✨ 主要特点
🎯 三个服务器版本
- 🚀 增强型服务器 -具有缓存、批量操作和域分析的高级功能
- 🔧 完整浏览器服务器 -为JavaScript密集型网站提供完整的Playwright自动化
- ⚡ 后备服务器 -基于curl的轻量级版本,实现最大兼容性
🔍 搜索功能
- 多个搜索引擎:谷歌、必应、DuckDuckGo、Searx、首页
- 新闻搜索:最近发表的带有来源归属的文章
- 批量搜索:跨多个查询的并行搜索
- 智能缓存:可配置的结果缓存以提高性能
📄 内容提取
- 智能解析:文章内容、元数据、链接和图像
- 多种格式:完整HTML、纯文本或纯文章提取
- 领域分析:端点发现和基本站点信息
- 链接发现:提取和分析页面关系
🚀 快速开始
安装
# Clone and set up locally
git clone https://github.com/devopsexpertlearning/mcp-search-server/tree/main
cd mcp-browser-search
# Install dependencies
npm install
# Build the project
npm run build
# Start the server
npm start
基本用法
# Start Enhanced Server (recommended)
npm run start:enhanced
# Start Fallback Server (maximum compatibility)
npm run start:fallback
# Start Full Browser Server (default)
npm start
# Start Ollama-powered Server
npm run start:ollama
🛠️ 发展
先决条件
- Node.js>=18
- npm或纱线
- Git
从源代码构建
# Clone the repository
git clone https://github.com/your-repo/mcp-browser-search.git
cd mcp-browser-search
# Install dependencies
npm install
# Build TypeScript code
npm run build
# Test the build
npm start
发展模式
# Watch mode for development
npm run dev
# Build specific server
npm run build:enhanced
npm run build:fallback
npm run build:ollama
🐳 部署
Docker部署
基本Docker设置
# Build Docker image
docker build -t mcp-browser-search .
# Run with Enhanced Server
docker run -p 3000:3000 mcp-browser-search
# Run with environment variables
docker run -e MCP_SERVER_TYPE=enhanced -e CACHE_ENABLED=true mcp-browser-search
Docker Compose
version: '3.8'
services:
mcp-browser-search:
build: .
environment:
- MCP_SERVER_TYPE=enhanced
- CACHE_ENABLED=true
- REDIS_URL=redis://redis:6379
ports:
- "3000:3000"
depends_on:
- redis
redis:
image: redis:alpine
ports:
- "6379:6379"
Kubernetes部署
apiVersion: apps/v1
kind: Deployment
metadata:
name: mcp-browser-search
spec:
replicas: 3
selector:
matchLabels:
app: mcp-browser-search
template:
metadata:
labels:
app: mcp-browser-search
spec:
containers:
- name: mcp-browser-search
image: mcp-browser-search:latest
ports:
- containerPort: 3000
env:
- name: MCP_SERVER_TYPE
value: "enhanced"
🔧 整合
克劳德桌面
添加到您的Claude Desktop配置中:
{
"mcpServers": {
"browser-search": {
"command": "node",
"args": ["/path/to/mcp-browser-search/dist/index.js"],
"env": {
"MCP_SERVER_TYPE": "enhanced"
}
}
}
}
通用MCP客户端
服务器实现了标准的MCP协议,可以与任何兼容MCP的客户端一起使用。
🛠️ 可用工具
🔍 search_web
使用各种搜索引擎搜索网络。
参数:
query(string):搜索查询engine(字符串,可选):搜索引擎(谷歌、必应、duckduckgo)max_results(数字,可选):返回的最大结果
📄 visit_page
从特定网页提取内容。
参数:
url(string):要访问的URLextraction_type(字符串,可选):提取类型(文章、完整、干净)
📰 search_news
搜索最近的新闻文章。
参数:
query(string):新闻搜索查询max_results(数字,可选):返回的最大结果
🔍 bulk_search
并行执行多个搜索。
参数:
queries(array):搜索查询数组engine(字符串,可选):要使用的搜索引擎
🌐 analyze_domain
分析域的端点和基本信息。
参数:
domain(string):要分析的域
🔗 extract_links
从网页中提取链接。
参数:
url(string):从中提取链接的URL
⚙️ 配置
环境变量
# Server type
MCP_SERVER_TYPE=enhanced|browser|fallback|ollama
# Cache settings
CACHE_ENABLED=true
CACHE_TTL=3600
REDIS_URL=redis://localhost:6379
# Search settings
DEFAULT_SEARCH_ENGINE=google
MAX_SEARCH_RESULTS=10
# Browser settings (for browser server)
HEADLESS=true
TIMEOUT=30000
# Ollama settings
OLLAMA_BASE_URL=http://localhost:11434
OLLAMA_MODEL=llama2
配置文件
创建 config.json:
{
"server": {
"type": "enhanced",
"port": 3000
},
"cache": {
"enabled": true,
"ttl": 3600,
"redisUrl": "redis://localhost:6379"
},
"search": {
"defaultEngine": "google",
"maxResults": 10,
"engines": {
"google": {
"enabled": true
},
"bing": {
"enabled": true
}
}
}
}
✅ 测试与验证
快速测试命令
构建项目后,您可以使用以下方法测试MCP服务器功能:
方法1:测试工具列表
# List all available tools
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | node dist/index.js
方法2:测试Web搜索(后备服务器-推荐)
# Start fallback server (works without browser dependencies)
npm run start:fallback &
# Test search functionality
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "search_web_fallback", "arguments": {"query": "hello world", "engine": "duckduckgo", "max_results": 3}}}' | node dist/servers/FallbackServer.js
方法3:测试全浏览器服务器
# Install browser dependencies first
npx playwright install
# Test with full browser server
echo '{"jsonrpc": "2.0", "id": 3, "method": "tools/call", "params": {"name": "search_web", "arguments": {"query": "test search", "engine": "duckduckgo", "max_results": 3}}}' | node dist/index.js
方法4:测试页面访问
# Test content extraction
echo '{"jsonrpc": "2.0", "id": 4, "method": "tools/call", "params": {"name": "visit_page_fallback", "arguments": {"url": "https://example.com"}}}' | node dist/servers/FallbackServer.js
预期成功响应
{
"result": {
"content": [
{
"type": "text",
"text": "[\n {\n \"title\": \"Example Result\",\n \"url\": \"https://example.com\",\n \"snippet\": \"Description of the result\",\n \"domain\": \"example.com\"\n }\n]"
}
]
}
}
测试不同的服务器类型
# Test Enhanced Server
npm run start:enhanced &
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | node dist/servers/EnhancedServer.js
# Test Fallback Server (No browser required)
npm run start:fallback &
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | node dist/servers/FallbackServer.js
# Test Ollama Server
npm run start:ollama &
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | node dist/servers/OllamaServer.js
交互式测试脚本
创建 test_mcp.js:
const { spawn } = require('child_process');
const mcpServer = spawn('node', ['dist/servers/FallbackServer.js'], {
stdio: ['pipe', 'pipe', 'pipe']
});
const testMessages = [
{ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} },
{
jsonrpc: "2.0",
id: 2,
method: "tools/call",
params: {
name: "search_web_fallback",
arguments: { query: "test", max_results: 2 }
}
}
];
mcpServer.stdout.on('data', (data) => {
console.log('MCP Response:', data.toString());
});
mcpServer.stderr.on('data', (data) => {
console.error('MCP Error:', data.toString());
});
testMessages.forEach((msg, i) => {
setTimeout(() => {
console.log(`Sending: ${JSON.stringify(msg)}`);
mcpServer.stdin.write(JSON.stringify(msg) + '\n');
}, i * 1000);
});
setTimeout(() => {
mcpServer.kill();
}, 5000);
运行方式: node test_mcp.js
🧪 测试
运行测试
# Run all tests
npm test
# Run specific test suite
npm run test:unit
npm run test:integration
# Watch mode
npm run test:watch
手动测试
# Start server in debug mode
DEBUG=* npm start
# Test with curl
curl -X POST http://localhost:3000/mcp \
-H "Content-Type: application/json" \
-d '{"method": "search_web", "params": {"query": "test"}}'
🔒 安全考虑
最佳实践
- 使用环境变量进行敏感配置
- 在生产中启用速率限制
- 在生产部署中使用HTTPS
- 定期更新依赖关系
- 监控可疑活动
安全配置
# Enable security features
RATE_LIMIT_ENABLED=true
RATE_LIMIT_MAX=100
RATE_LIMIT_WINDOW=900000
# CORS settings
CORS_ENABLED=true
CORS_ORIGIN=https://your-domain.com
🐛 故障排除
常见问题
安装问题:
# Clear npm cache
npm cache clean --force
# Reinstall dependencies
rm -rf node_modules package-lock.json
npm install
浏览器服务器问题:
# Install Playwright browsers
npx playwright install
# Check browser dependencies
npx playwright install-deps
# If Playwright installation fails, use fallback server
npm run start:fallback
MCP测试问题:
“MCP服务器无响应”
# Check if server is running
ps aux | grep node
# Test basic connectivity
echo '{"jsonrpc": "2.0", "id": 1, "method": "ping"}' | node dist/index.js
“找不到工具”错误
# List available tools first
echo '{"jsonrpc": "2.0", "id": 1, "method": "tools/list", "params": {}}' | node dist/servers/FallbackServer.js
# Use correct tool names:
# - search_web_fallback (for fallback server)
# - search_web (for full browser server)
# - visit_page_fallback (for fallback server)
“browserType.launch:可执行文件不存在”错误
# This means Playwright browsers aren't installed
# Solution 1: Install browsers
npx playwright install
# Solution 2: Use fallback server instead
npm run start:fallback
“搜索未返回任何结果”
# Try different search engines
echo '{"jsonrpc": "2.0", "id": 2, "method": "tools/call", "params": {"name": "search_web_fallback", "arguments": {"query": "test", "engine": "bing"}}}' | node dist/servers/FallbackServer.js
# Check network connectivity
curl -I https://duckduckgo.com
内存问题:
# Increase Node.js memory limit
NODE_OPTIONS="--max-old-space-size=4096" npm start
端口冲突:
# Check what's using the port
lsof -i :3000
# Kill conflicting processes
pkill -f "node.*mcp"
调试模式
# Enable debug logging
DEBUG=mcp:* npm start
# Verbose logging
LOG_LEVEL=debug npm start
🤝 贡献
开发环境设置
- 分叉存储库
- 创建要素分支
- 进行更改
- 添加测试
- 提交拉取请求
代码规范
- 遵循TypeScript的最佳实践
- 使用ESLint和Prettier
- 编写全面的测试
- 记录新功能
📄 许可证
MIT许可证-有关详细信息,请参阅许可证文件。
🙏 致谢
- 模型上下文协议(MCP)团队
- 浏览器自动化剧作家
- 开源社区
由以下材料制成❤️ 对于MCP社区