MCP网络爬虫
一种模型上下文协议服务器,允许大型语言模型通过标准化工具与网页内容交互,目前支持网页抓取功能。
服务介绍
MCP Web Tools Server
一个提供与网页相关的操作工具的模型上下文协议(MCP)服务器。该服务器允许大语言模型通过标准化工具与网页内容进行交互。
当前工具
- web_scrape: 将 URL 转换为使用 r.jina.ai 作为前缀,并返回 markdown 格式的内容
安装
-
克隆此仓库:
git clone <repository-url> cd MCP -
安装所需的依赖项:
pip install -r requirements.txt或者,你可以使用 uv 来加快安装速度:
uv pip install -r requirements.txt
运行服务器和 UI
此仓库包含方便的脚本来运行 MCP 服务器或 Streamlit UI。
使用运行脚本
在 macOS/Linux 上:
# Run the server with stdio transport (default)
./run.sh server
# Run the server with SSE transport
./run.sh server --transport sse --host localhost --port 5000
# Run the Streamlit UI
./run.sh ui
在 Windows 上:
# Run the server with stdio transport (default)
run.bat server
# Run the server with SSE transport
run.bat server --transport sse --host localhost --port 5000
# Run the Streamlit UI
run.bat ui
手动运行
你也可以直接运行服务器:
使用 stdio(默认)
python server.py
使用 SSE
python server.py --transport sse --host localhost --port 5000
这将在 localhost:5000 上启动一个接受 MCP 连接的 HTTP 服务器。
要手动运行 Streamlit UI:
streamlit run streamlit_app.py
使用 MCP Inspector 进行测试
MCP Inspector 是一个用于测试和调试 MCP 服务器的工具。你可以用它来与你的服务器交互:
-
安装 MCP Inspector:
npm install -g @modelcontextprotocol/inspector -
使用 Inspector 运行你的服务器:
npx @modelcontextprotocol/inspector python server.py -
使用 Inspector 界面测试
web_scrape工具,提供像example.com这样的 URL 并查看返回的 markdown 内容。
与 Claude for Desktop 集成
要将此服务器与 Claude for Desktop 一起使用:
-
确保你已安装 Claude for Desktop。
-
打开 Claude for Desktop 的配置文件:
- Mac:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%\Claude\claude_desktop_config.json
- Mac:
-
添加以下配置(根据需要调整路径):
{
"mcpServers": {
"web-tools": {
"command": "python",
"args": [
"/absolute/path/to/MCP/server.py"
]
}
}
}
-
重启 Claude for Desktop。
-
你现在应该可以在 Claude 的界面中看到 web_scrape 工具。你可以要求 Claude 从网站获取内容,它将使用该工具。
示例用法
一旦与 Claude 集成,你可以问类似的问题:
- "example.com 的主页上有什么?"
- "你能获取并总结 mozilla.org 的内容吗?"
- "获取 wikipedia.org/wiki/Model_Context_Protocol 的内容并向我解释。"
Claude 将使用 web_scrape 工具获取内容并在其响应中提供。
添加更多工具
要为此服务器添加更多工具:
-
在
tools/目录中创建一个新的 Python 文件,例如tools/new_tool.py。 -
实现你的工具函数,遵循现有工具类似的模式。
-
在
server.py中导入你的工具,并将其注册到 MCP 服务器:
# Import your new tool
from tools.new_tool import new_tool_function
# Register the tool with the MCP server
@mcp.tool()
async def new_tool(param1: str, param2: int) -> str:
"""
Description of what your tool does.
Args:
param1: Description of param1
param2: Description of param2
Returns:
Description of return value
"""
return await new_tool_function(param1, param2)
- 重启服务器以应用更改。
Streamlit UI
此仓库包含一个 Streamlit 应用程序,允许您连接并测试在 Claude for Desktop 中配置的所有 MCP 服务器。
运行 Streamlit UI
streamlit run streamlit_app.py
这将启动 Streamlit 服务器并在带有 UI 的网页浏览器中打开。
功能
- 加载和解析您的 Claude for Desktop 配置文件
- 查看所有已配置的 MCP 服务器
- 连接到任意服务器并查看其可用工具
- 通过提供输入参数来测试工具并查看结果
- 查看可用资源和提示
使用方法
- 启动 Streamlit 应用程序
- 输入您的 Claude for Desktop 配置文件路径(默认路径已预填)
- 点击“加载服务器”以查看所有可用的 MCP 服务器
- 选择一个服务器选项卡并点击“连接”以加载其工具
- 选择一个工具并提供所需的参数
- 点击“执行”运行工具并查看结果
故障排除
- 缺少依赖项:确保
requirements.txt中列出的所有依赖项都已安装。 - 连接问题:检查服务器是否正在运行,并且 Claude for Desktop 中的配置指向了正确的路径。
- 工具执行错误:查看服务器输出中的错误消息。
- Streamlit UI 问题:确保 Streamlit 正确安装并且配置文件路径正确。
许可证
本项目采用 MIT 许可证。更多详情请参见 LICENSE 文件。