数据抓取服务

MCP服务器实现,提供LinkedIn个人资料抓取和天气数据检索功能,支持AI服务集成。

  • by mybarefootstory
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 mybarefootstory/mcp-server-practice-2

使用说明

MCP服务器实践

此存储库包含用于LinkedIn个人资料抓取和天气数据检索的模型上下文协议(MCP)服务器的实现。MCP框架促进了AI服务之间的无缝集成和通信。

概述

  • LinkedIn个人资料抓取器:使用全新LinkedIn个人资料数据API获取LinkedIn个人档案数据。
  • 气象数据服务:使用美国国家气象局(NWS)API检索天气警报和预报。

先决条件

  • Python 3.7+
  • httpx 用于异步HTTP请求
  • python-dotenv 环境变量管理
  • mcp 用于MCP服务器实现

安装

  1. 克隆存储库:

    git clone https://github.com/mybarefootstory/MCP-Server-Practice-2.git
    cd MCP-Server-Practice-2
    
  2. 安装依赖项:

    pip install httpx python-dotenv mcp
    
  3. 设置环境变量:

    • 创建一个 .env 根目录中的文件。
    • 添加您的RapidAPI密钥:
      RAPIDAPI_KEY=your_rapidapi_key_here
      

LinkedIn个人资料抓取器

描述

使用全新LinkedIn个人资料数据API获取LinkedIn个人档案数据。服务器已初始化为 FastMCP 并监听检索简档信息的请求。

代码段

from mcp.server.fastmcp import FastMCP
import httpx
import os
from dotenv import load_dotenv

load_dotenv()
RAPIDAPI_KEY = os.getenv("RAPIDAPI_KEY")

mcp = FastMCP("linkedin_profile_scraper")

async def get_linkedin_data(linkedin_url: str) -> dict:
    # Fetch LinkedIn profile data
    ...

@mcp.tool()
async def get_profile(linkedin_url: str) -> str:
    # Get LinkedIn profile data
    ...

if __name__ == "__main__":
    mcp.run(transport="stdio")

气象数据服务

描述

使用NWS API检索天气警报和预报。服务器已初始化为 FastMCP 并提供用于获取警报和预测的工具。

代码段

from mcp.server.fastmcp import FastMCP
import httpx

mcp = FastMCP("weather")

async def make_nws_request(url: str) -> dict:
    # Make a request to the NWS API
    ...

@mcp.tool()
async def get_alerts(state: str) -> str:
    # Get weather alerts for a US state
    ...

@mcp.tool()
async def get_forecast(latitude: float, longitude: float) -> str:
    # Get weather forecast for a location
    ...

if __name__ == "__main__":
    mcp.run(transport='stdio')

用法

  • LinkedIn个人资料抓取器:运行服务器并使用 get_profile 获取LinkedIn数据的工具。
  • 气象数据服务:运行服务器并使用 get_alerts 和 get_forecast 检索天气信息的工具。