LinkedIn数据智能代理集成

通过集成LinkedIn MCP Server与LlamaIndex,创建能够通过Model Context Protocol(MCP)与LinkedIn数据交互的AI代理,实现个人资料抓取、公司分析、职位搜索等功能。

  • by MaiM0hamed
  • 本地部署
  • 1 星标
  • 更新于
在 GitHub 查看 MaiM0hamed/MCP_linkedIn

使用说明

LinkedIn MCP服务器+LlamaIndex集成

该项目整合了 LinkedIn MCP服务器 随着 Llama索引 创建可以通过模型上下文协议(MCP)与LinkedIn数据交互的AI代理。

🎯 特性

  • LinkedIn个人资料删除:从LinkedIn个人资料中获取详细信息,包括工作经历、教育、技能和人脉
  • 公司分析:从LinkedIn公司页面提取全面的公司信息
  • 求职:使用关键字和位置等过滤器搜索工作
  • 推荐工作:根据您的LinkedIn个人资料获得个性化的工作推荐
  • 工作分析:检索和分析特定的职位发布详细信息
  • AI代理集成:使用LlamaIndex函数调用代理与LinkedIn数据自然交互

📋 先决条件

在开始之前,您需要:

  1. LinkedIn MCP服务器:LinkedIn MCP服务器的运行实例
  2. LinkedIn Cookie:您的LinkedIn会话cookie(li_at 值)
  3. OpenAI API密钥:对于LLM代理
  4. Python 3.8+:Python环境

🚀 快速开始

1.安装依赖项

pip install -r requirements.txt

2.设置LinkedIn MCP服务器

您有几个运行LinkedIn MCP服务器的选项:

选项A:Docker(推荐)

docker run -p 8000:8000 -e LINKEDIN_COOKIE="your_li_at_cookie" stickerdaniel/linkedin-mcp-server

选项B:uvx(快速安装)

uvx --from git+https://github.com/stickerdaniel/linkedin-mcp-server linkedin-mcp-server --cookie "your_li_at_cookie"

选项C:本地设置

git clone https://github.com/stickerdaniel/linkedin-mcp-server
cd linkedin-mcp-server
pip install -e .
linkedin-mcp-server --cookie "your_li_at_cookie"

3.获取您的LinkedIn Cookie

  1. 打开LinkedIn并登录
  2. 打开Chrome DevTools(F12或右键单击→ 检查)
  3. 转到应用程序>存储>Cookie>https://www.linkedin.com
  4. 查找名为的cookie li_at
  5. 复制“值”字段
  6. 使用此值作为您的 LINKEDIN_COOKIE

4.配置环境变量

创建一个 .env 项目根目录中的文件:

# Required
OPENAI_API_KEY=your_openai_api_key_here

# Optional (defaults shown)
LINKEDIN_MCP_URL=http://127.0.0.1:8000/mcp
LLM_MODEL=gpt-4
LLM_TEMPERATURE=0.7
AGENT_VERBOSE=true
AGENT_MAX_ITERATIONS=10

5.运行集成

# Run basic examples
python linkedin_mcp_llamaindex_integration.py

# Run advanced examples
python examples.py

💻 用法

基本用法

import asyncio
from linkedin_mcp_llamaindex_integration import LinkedInMCPAgent

async def main():
    # Create and initialize the agent
    agent = LinkedInMCPAgent()
    await agent.initialize()
    
    # Get recommended jobs
    response = await agent.get_my_recommended_jobs()
    print(response)
    
    # Research a profile
    profile_insights = await agent.get_profile_insights(
        "https://www.linkedin.com/in/example/"
    )
    print(profile_insights)
    
    # Clean up
    await agent.close()

asyncio.run(main())

高级用法

自定义配置

from linkedin_mcp_llamaindex_integration import LinkedInMCPAgent

agent = LinkedInMCPAgent(
    mcp_server_url="http://localhost:8000/mcp",
    llm_model="gpt-4-turbo-preview",
    api_key="your_api_key",
    allowed_tools=[
        "get_person_profile",
        "search_jobs",
        "get_recommended_jobs"
    ]
)

流响应

async def stream_example():
    agent = LinkedInMCPAgent()
    await agent.initialize()
    
    async for chunk in agent.stream_chat("Find ML engineer jobs in NYC"):
        print(chunk, end="", flush=True)
    
    await agent.close()

交互式聊天

async def interactive_session():
    agent = LinkedInMCPAgent()
    await agent.initialize()
    
    while True:
        user_input = input("You: ")
        if user_input.lower() in ['quit', 'exit']:
            break
        
        response = await agent.chat(user_input)
        print(f"Agent: {response}")
    
    await agent.close()

📚 可用工具

代理可以访问这些LinkedIn MCP工具:

  • get_person_profile:获取详细的LinkedIn个人资料信息
  • get_company_profile:提取公司信息
  • get_job_details:检索特定的职位发布详细信息
  • search_jobs:使用筛选器搜索工作
  • get_recommended_jobs:获得个性化的工作推荐
  • close_session:清理浏览器资源

🎓 用例

职业研究

研究多个LinkedIn个人资料并生成比较分析:

response = await agent.chat("""
    Research these profiles and compare their career paths:
    - https://www.linkedin.com/in/profile1/
    - https://www.linkedin.com/in/profile2/
""")

就业市场分析

分析特定职位的就业市场:

response = await agent.chat("""
    Search for 'Data Scientist' positions in 'San Francisco' 
    and analyze the common skills required
""")

CV优化

获取改进特定职位简历的建议:

response = await agent.chat("""
    Analyze this job posting: https://www.linkedin.com/jobs/view/123456
    and suggest how I can improve my CV to match it
""")

公司研究

深入了解公司以寻求合作伙伴关系或工作机会:

response = await agent.get_company_insights(
    "https://www.linkedin.com/company/example/"
)

🛠️ 建筑

graph TD
    A[User Query] --> B[LinkedInMCPAgent]
    B --> C[LlamaIndex Function Calling Agent]
    C --> D[MCP Client]
    D --> E[LinkedIn MCP Server]
    E --> F[LinkedIn API/Scraper]
    F --> G[LinkedIn Data]
    G --> F
    F --> E
    E --> D
    D --> C
    C --> H[LLM - GPT-4]
    H --> C
    C --> B
    B --> I[Response]

📁 项目结构

grad_search/
├── linkedin_mcp_llamaindex_integration.py  # Main integration module
├── config.py                                # Configuration management
├── examples.py                              # Advanced usage examples
├── requirements.txt                         # Python dependencies
└── README.md                                # This file

🔧 配置选项

环境变量 描述 默认值
OPENAI_API_KEY OpenAI API密钥(必需) -
LINKEDIN_MCP_URL LinkedIn MCP服务器URL http://127.0.0.1:8000/mcp
LINKEDIN_COOKIE LinkedIn会话cookie -
LLM_MODEL 要使用的LLM模型 gpt-4
LLM_TEMPERATURE 响应温度 0.7
AGENT_VERBOSE 启用详细日志记录 true
AGENT_MAX_ITERATIONS 最大代理迭代次数 10

🚨 重要说明

  1. Cookie过期:LinkedIn Cookie将在约30天后过期。需要时更新您的cookie。
  2. 速率限制注意LinkedIn的费率限制。避免过多的请求。
  3. 隐私负责任地处理领英数据,尊重用户隐私。
  4. 服务条款:确保遵守LinkedIn的服务条款。

🤝 贡献

欢迎投稿!请随时提交拉取请求。

📝 许可证

本项目按原样提供,用于教育和研究目的。

🙏 致谢

📖 额外资源

🆘 故障排除

连接问题

如果您无法连接到MCP服务器:

  1. 验证服务器是否正在运行: curl http://127.0.0.1:8000/mcp
  2. 检查 LINKEDIN_MCP_URL 环境变量
  3. 确保没有防火墙阻止连接

Cookie问题

如果您遇到身份验证错误:

  1. 获取一个新的LinkedIn cookie
  2. 验证cookie格式(应为 li_at 仅限值)
  3. 确保cookie未过期

导入错误

如果您收到导入错误:

  1. 安装所有依赖项: pip install -r requirements.txt
  2. 验证Python版本≥3.8
  3. 检查虚拟环境激活

📧 联系

对于问题和疑问: