使用说明

项目简介

本项目包含两个MCP服务器的示例实现,分别用于:

  • LinkedIn Profile Scraper: 抓取LinkedIn公开的个人资料信息。
  • Weather Data Service: 获取美国国家气象局(NWS)提供的天气预警和预报。

这两个示例旨在演示如何使用MCP框架快速构建工具型服务器,并将其与大型语言模型(LLM)客户端集成,扩展LLM的功能。

主要功能点

  • LinkedIn Profile Scraper:
    • 提供 'get_profile' 工具,根据LinkedIn个人资料URL获取详细信息。
  • Weather Data Service:
    • 提供 'get_alerts' 工具,获取指定美国州的天气警报信息。
    • 提供 'get_forecast' 工具,获取指定经纬度位置的天气预报信息。

安装步骤

  1. 克隆仓库到本地:
    git clone https://github.com/mybarefootstory/MCP-Server-Practice-2.git
    cd MCP-Server-Practice-2
  2. 安装Python依赖库:
    pip install httpx python-dotenv mcp
  3. 配置环境变量:
    • 在项目根目录下创建 '.env' 文件。
    • 添加 RapidAPI 密钥 (用于 LinkedIn Profile Scraper,如不需要LinkedIn功能可忽略):
      RAPIDAPI_KEY=你的RapidAPI密钥
      请访问 RapidAPI Fresh LinkedIn Profile Data 获取API密钥。

服务器配置

LinkedIn Profile Scraper 服务器配置 (JSON):

{
  "server_name": "linkedin_profile_scraper",
  "command": "python",
  "args": ["linkedin_profile_scraper/linkedin_profile_scraper.py"]
}
  • 'server_name': 服务器名称,用于MCP客户端识别。
  • 'command': 启动服务器的命令,这里使用 'python' 解释器。
  • 'args': 启动命令的参数,指定 LinkedIn Profile Scraper 服务器脚本的路径。

Weather Data Service 服务器配置 (JSON):

{
  "server_name": "weather",
  "command": "python",
  "args": ["weather/weather.py"]
}
  • 'server_name': 服务器名称,用于MCP客户端识别。
  • 'command': 启动服务器的命令,这里使用 'python' 解释器。
  • 'args': 启动命令的参数,指定 Weather Data Service 服务器脚本的路径。

请注意:MCP客户端需要配置以上JSON信息才能连接到对应的MCP服务器。 假设MCP客户端与MCP服务器在同一目录下运行,如果不是,请根据实际情况修改 'args' 中的脚本路径。

基本使用方法

  1. 启动服务器: 根据需要,分别运行 'linkedin_profile_scraper/linkedin_profile_scraper.py' 或 'weather/weather.py' 脚本以启动对应的MCP服务器。例如,在终端中进入项目根目录,执行 'python linkedin_profile_scraper/linkedin_profile_scraper.py' 即可启动 LinkedIn Profile Scraper 服务器。
  2. MCP客户端调用: 使用支持MCP协议的客户端(如LLM应用或MCP测试客户端),根据上述服务器配置信息连接到已启动的MCP服务器。
  3. 调用工具: 通过MCP客户端,可以调用服务器提供的工具,例如:
    • 调用 'linkedin_profile_scraper' 服务器的 'get_profile' 工具,并传入 LinkedIn 个人资料 URL 作为参数,即可获取该用户的资料信息。
    • 调用 'weather' 服务器的 'get_alerts' 工具,并传入美国州代码(如 "CA")作为参数,即可获取该州的天气警报。
    • 调用 'weather' 服务器的 'get_forecast' 工具,并传入经纬度坐标作为参数,即可获取该位置的天气预报。

具体工具调用方法和参数格式,请参考MCP协议文档和客户端的使用说明。

信息

分类

网页与API