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