网页工具服务器

一个提供网页相关操作工具的模型上下文协议(MCP)服务器,允许LLM通过标准化工具与网页内容交互。

  • by surya-madhav
  • Python
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 surya-madhav/mcp

使用说明

MCP Web工具服务器

一种模型上下文协议(MCP)服务器,为web相关操作提供工具。此服务器允许LLM通过标准化工具与web内容进行交互。

当前工具

  • web_scrape:将URL转换为使用r.jina.ai作为前缀,并返回markdown内容

安装

  1. 克隆此存储库:

    git clone <repository-url>
    cd MCP
    
  2. 安装所需的依赖项:

    pip install -r requirements.txt
    

    或者,您可以使用 紫外线 为了更快地安装:

    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

这将在上启动HTTP服务器 localhost:5000 它接受MCP连接。

要手动运行Streamlit UI:

streamlit run streamlit_app.py

MCP检验员测试

MCP检查器是用于测试和调试MCP服务器的工具。您可以使用它与服务器进行交互:

  1. 安装MCP检查器:

    npm install -g @modelcontextprotocol/inspector
    
  2. 在服务器上运行检查器:

    npx @modelcontextprotocol/inspector python server.py
    
  3. 使用检查器界面测试 web_scrape 通过提供类似URL的工具 example.com 并查看返回的降价内容。

与Claude for Desktop集成

要将此服务器与Claude for Desktop一起使用,请执行以下操作:

  1. 确保你有 Claude桌面版 安装。

  2. 打开Claude for Desktop配置文件:

    • 雨衣: ~/Library/Application Support/Claude/claude_desktop_config.json
    • 窗户: %APPDATA%\Claude\claude_desktop_config.json
  3. 添加以下配置(根据需要调整路径):

{
  "mcpServers": {
    "web-tools": {
      "command": "python",
      "args": [
        "/absolute/path/to/MCP/server.py"
      ]
    }
  }
}
  1. 重新启动桌面版的Claude。

  2. 现在,您应该可以在Claude的界面中看到web_scrape工具。您可以让Claude从网站获取内容,它将使用该工具。

示例用法

一旦与Claude集成,您可以提出以下问题:

  • “example.com的主页上有什么?”
  • “你能从mozilla.org获取并总结内容吗?”
  • “从wikipedia.org/wiki/Model_Context_Protocol获取内容并向我解释。”

Claude将使用web_scrape工具获取内容并在其响应中提供。

添加更多工具

要向此服务器添加更多工具,请执行以下操作:

  1. 在中创建一个新的Python文件 tools/ 目录。, tools/new_tool.py.

  2. 按照与现有工具类似的模式实现工具功能。

  3. 将您的工具导入 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)
  1. 重新启动服务器以应用更改。

流线型UI

此存储库包含一个Streamlit应用程序,允许您连接并测试在Claude for Desktop中配置的所有MCP服务器。

运行Streamlit UI

streamlit run streamlit_app.py

这将启动Streamlit服务器并使用UI打开web浏览器。

特性

  • 加载并解析Claude for Desktop配置文件
  • 查看所有已配置的MCP服务器
  • 连接到任何服务器并查看其可用工具
  • 通过提供输入参数和查看结果来测试工具
  • 查看可用资源和提示

用法

  1. 启动Streamlit应用程序
  2. 输入Claude for Desktop配置文件的路径(默认路径已预先填写)
  3. 点击“加载服务器”查看所有可用的MCP服务器
  4. 选择一个服务器选项卡,然后单击“连接”以加载其工具
  5. 选择工具并提供所需参数
  6. 点击“执行”运行工具并查看结果

故障排除

  • 缺少的依赖:确保中的所有依赖关系 requirements.txt 已安装。
  • 连接问题:检查服务器是否正在运行,以及Claude for Desktop中的配置是否指向正确的路径。
  • 工具执行错误:在服务器输出中查找错误消息。
  • 简化UI问题:确保Streamlit安装正确,配置文件路径正确。

许可证

该项目在MIT许可证下可用。有关更多详细信息,请参阅LICENSE文件。