使用说明
MCP网关
一种模块化的MCP(模型上下文协议)服务器,为LLM提供web访问功能。展示了两个简单的工具: search() 和 get().
特性
- 搜索(查询) -通过自托管的SearXNG(元搜索引擎)进行网络搜索
- 获取(url) -具有自动路由功能的智能内容获取:
- 图片(.png、.jpg、.webp)→ 视觉AI描述
- 文档(PDF、DOCX、XLSX)→ 文档解析
- 网页→ 剧作家浏览器+视觉AI(所有网站质量一致)
建筑
┌─────────────────┐ SSE/HTTP ┌──────────────────┐
│ LLM Client │ ◄───────────────► │ MCP Gateway │
│ (Claude, │ Port 8000 │ (FastMCP) │
│ etc.) │ └────────┬─────────┘
└─────────────────┘ │
▼
┌──────────────────────────┼──────────────────────────┐
│ │ │
┌─────▼─────┐ ┌────────▼────────┐ ┌───────▼───────┐
│ SearXNG │ │ LM Studio │ │ Playwright │
│ :8080 │ │ :1234 │ │ (Chrome) │
│ (search) │ │ (summarize/ │ │ (all web │
└───────────┘ │ vision) │ │ pages) │
└─────────────────┘ └───────────────┘
快速开始
先决条件
- Python 3.11+
- Docker(适用于SearXNG)
- 紫外线 (推荐)或pip
- Node.js(通过npx用于剧作家MCP)
- 可选:LM Studio用于总结/展望
设置
-
克隆并安装依赖项
git clone <repo-url> cd searxng-mcp uv sync # or: pip install -e . -
启动SearXNG (搜索引擎)
cd docker/searxng && docker compose up -d -
开始文档记录 (文档解析器)
# CPU version (simpler, no GPU required) cd docker/docling && docker compose up -d # OR GPU version with CUDA + VLM picture descriptions cd docker/docling && docker compose -f docker-compose.gpu.yml up -d -
配置环境
cp .env.example .env # Edit .env with your settings -
运行网关
# SSE mode (for network access) python gateway.py -t sse -p 8000 # Or stdio mode (for local CLI) python gateway.py
配置
环境变量 .env:
核心设置
| 变量 | 描述 | 默认值 |
|---|---|---|
MCP_PORT |
网关端口 | 8000 |
SEARXNG_URL |
SearXNG实例URL | http://localhost:8080 |
文档解析器
| 变量 | 描述 | 默认值 |
|---|---|---|
DOCLING_URL |
CPU文档服务URL | http://localhost:8001 |
DOCLING_GPU_URL |
GPU文档服务URL(CUDA) | http://localhost:8002 |
USE_DOCLING_GPU |
启用GPU服务 | false |
DOCUMENT_MAX_LENGTH |
返回的最大文档字符数 | 1000000 |
愿景/总结法学硕士
| 变量 | 描述 | 默认值 |
|---|---|---|
SUMMARIZE_ENABLED |
启用LLM摘要 | false |
SUMMARIZE_API_URL |
OpenAI兼容的API URL | http://localhost:1234/v1 |
SUMMARIZE_MODEL |
总结/愿景模型 | qwen3-vl-4b |
SUMMARIZE_TIMEOUT |
API超时(秒) | 120 |
浏览器
| 变量 | 描述 | 默认值 |
|---|---|---|
PLAYWRIGHT_MCP_TOKEN |
Chrome扩展程序令牌 | - |
PLAYWRIGHT_HEADLESS |
无头运行浏览器 | true |
用法
来自MCP客户端
# Search the web
results = await search("Python asyncio tutorial", max_results=10)
# Get content from URL (uses Playwright + Vision AI)
content = await get("https://docs.python.org/3/")
# Get with summarization prompt
content = await get("https://amazon.com/dp/B123", "extract price and specs")
# Describe an image
description = await get("https://example.com/photo.jpg", "describe what you see")
# Parse a PDF
content = await get("https://arxiv.org/pdf/1706.03762.pdf")
Docker部署
使用Caddy反向代理的全栈:
docker compose up -d
这将开始:
- 8080端口上的SearXNG
- 端口8000上的MCP网关(通过Caddy)
项目结构
searxng-mcp/
├── gateway.py # Main entry point, tool definitions
├── core/
│ ├── __init__.py # Exports search() and get()
│ ├── router.py # URL routing logic
│ ├── search.py # SearXNG integration
│ ├── browser.py # Playwright integration
│ ├── image.py # Vision AI handling
│ ├── document.py # Docling PDF/DOCX parsing
│ ├── summarizer.py # LLM summarization
│ ├── config.py # Environment configuration
│ └── logger.py # Centralized logging
├── scripts/
│ └── benchmark_image.py # Performance benchmarks
├── searxng/ # SearXNG configuration
├── docker-compose.yml
├── Dockerfile
└── pyproject.toml
许可证
麻省理工学院