LinkedIn MCP服务器
](https://badge.fury.io/py/linkedin-mcp-server)  
一个强大的模型上下文协议(MCP)服务器,使像克劳德这样的人工智能代理能够与领英的专业网络无缝交互 FastMCP 高性能和可靠性。
这是什么?
此MCP服务器弥合了AI助手和LinkedIn之间的差距,使他们能够:
- 创建和管理带有文本和图像的LinkedIn帖子
- 评论帖子并参与内容
- 访问配置文件信息
- 搜索公司、职位和人员
- 通过自然语言自动化LinkedIn交互
非常适合希望利用人工智能高效管理领英形象的专业人士。
特性
核心能力
- 安全认证 -OAuth 2.0流与访问令牌管理
- 内容创作 -发布文字帖子和图片帖子
- 内容管理 -更新和删除帖子
- 参与 -评论帖子和管理评论
- 个人资料访问 -检索经过身份验证的用户配置文件信息
- 公司情报 -搜索和查看公司简介
- 工作发现 -搜索职位发布并查看详细信息
- 人员搜索 -在LinkedIn上寻找专业人士
构建于
- FastMCP -现代Python MCP框架
- HTTPX -API调用的异步HTTP客户端
- 派丹蒂克 -数据验证和设置管理
- OAuth 2.0 -行业标准认证
安装
选项1:使用uvx(推荐)
最快的入门方法:
uvx linkedin-mcp-server选项2:使用pip
从PyPI安装:
pip install linkedin-mcp-server选项3:来源
对于开发或定制:
git clone https://github.com/SARAMALI15792/LinkedIn_mcp_custom_server.git
cd LinkedIn_mcp_custom_server
pip install -e .快速入门指南
第一步:创建LinkedIn应用
- 首选 LinkedIn开发者门户
- 点击“创建应用”
- 填写必填信息:
- 应用程序名称:选择描述性名称 - LinkedIn页面:与您的页面关联或创建一个页面 - 应用程序徽标:上传徽标(可选,但推荐)
- 请求访问这些产品:
- 使用OpenID Connect登录LinkedIn (即时批准) - 在LinkedIn上分享 (即时批准)
- 在“身份验证”选项卡中:
- 添加重定向URL: http://localhost:8000 - 复制您的 客户端ID - 复制您的 客户端密钥
步骤2:配置环境
创建一个 .env 工作目录中的文件:
LINKEDIN_CLIENT_ID=your_client_id_here
LINKEDIN_CLIENT_SECRET=your_client_secret_here
LINKEDIN_REDIRECT_URI=http://localhost:8000安全说明: 永远不要承诺 .env 文件到版本控制。它已经在里面了 .gitignore.
步骤3:配置Claude桌面
编辑您的Claude Desktop配置文件:
窗户: %APPDATA%\Claude\claude_desktop_config.json macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json
添加LinkedIn MCP服务器:
{
"mcpServers": {
"linkedin": {
"command": "uvx",
"args": ["linkedin-mcp-server"]
}
}
}如果通过pip安装:
{
"mcpServers": {
"linkedin": {
"command": "linkedin-mcp-server"
}
}
}对于当地发展:
{
"mcpServers": {
"linkedin": {
"command": "python",
"args": ["-m", "linkedin_mcp_server"],
"env": {
"LINKEDIN_CLIENT_ID": "your_client_id",
"LINKEDIN_CLIENT_SECRET": "your_client_secret",
"LINKEDIN_REDIRECT_URI": "http://localhost:8000"
}
}
}
}步骤4:通过LinkedIn进行身份验证
- 重新启动克劳德桌面
- 在Claude中,键入: “生成LinkedIn登录URL”
- 在浏览器中复制并打开URL
- 登录LinkedIn并授权应用程序
- 您将被重定向到
http://localhost:8000/?code=... - 复制
codeURL中的参数值 - 在Claude中,键入: “交换此代码:\[粘贴代码\]”
- 完成!您现在已通过身份验证。
您的访问令牌将自动保存到 .env 并且将用于所有未来的请求。
使用示例
认证
User: "Generate LinkedIn login URL"
Claude: [Provides OAuth URL with instructions]
User: "Exchange this code: AQTvqXXXXXXXXXXX"
Claude: "Success! Access Token saved. Expires in 5183999 seconds."创建帖子
文本发布:
User: "Post to LinkedIn: Excited to announce the launch of our new AI-powered LinkedIn MCP server! Check it out on GitHub."
Claude: [Creates post and returns post URN]带有图片的帖子:
User: "Post this image to LinkedIn with caption 'Team celebration': C:/Users/photos/team.jpg"
Claude: [Uploads image and creates post with caption]管理内容
更新帖子:
User: "Update post urn:li:share:7289123456789 to say: Updated announcement..."
Claude: [Deletes old post and creates new one with updated text]删除帖子:
User: "Delete my post urn:li:share:7289123456789"
Claude: [Deletes the post permanently]参与
对帖子的评论:
User: "Comment on post urn:li:share:7289123456789: Great insights, thanks for sharing!"
Claude: [Posts comment and returns comment URN]查看评论:
User: "Show comments on post urn:li:share:7289123456789"
Claude: [Retrieves and displays all comments]个人资料信息
User: "What's my LinkedIn email address?"
Claude: [Retrieves profile and shows email]
User: "Show me my LinkedIn profile"
Claude: [Displays profile information: name, email, picture URL, etc.]公司研究
User: "Search for companies: Microsoft"
Claude: [Returns list of matching companies]
User: "Get details for company urn:li:organization:1035"
Claude: [Shows company profile information]求职
User: "Find remote Python developer jobs"
Claude: [Searches and displays matching job postings]
User: "Search for Machine Learning Engineer positions in San Francisco"
Claude: [Returns relevant job listings]
User: "Get details for job urn:li:job:123456789"
Claude: [Shows detailed job information]人员搜索
User: "Search for AI researchers at Stanford"
Claude: [Returns matching professionals]可用工具
| 工具名称 | 描述 | 只读 | 破坏性 |
|---|---|---|---|
linkedin_get_oauth_url | 生成OAuth 2.0授权URL | 是 | 否 |
linkedin_exchange_code | 访问令牌的Exchange身份验证码 | 否 | 否 |
linkedin_get_my_profile | 获取经过身份验证的用户的个人资料 | 是 | 否 |
linkedin_get_member_profile | 按URN获取会员资料 | 是 | 否 |
linkedin_create_post | 创建文本帖子 | 否 | 否 |
linkedin_create_image_post | 创建带有图片的帖子 | 否 | 否 |
linkedin_update_post | 更新现有帖子(通过删除+创建) | 否 | 是 |
linkedin_delete_post | 永久删除帖子 | 否 | 是 |
linkedin_get_recent_posts | 列出最近的帖子 | 是 | 否 |
linkedin_create_comment | 对内容的评论 | 否 | 否 |
linkedin_get_post_comments | 获取帖子评论 | 是 | 否 |
linkedin_delete_comment | 永久删除评论 | 否 | 是 |
linkedin_get_company_profile | 按URN获取公司详细信息 | 是 | 否 |
linkedin_search_companies | 搜索公司 | 是 | 否 |
linkedin_search_jobs | 搜索招聘信息 | 是 | 否 |
linkedin_get_job_details | 按URN获取作业详细信息 | 是 | 否 |
linkedin_search_people | 搜索人员 | 是 | 否 |
了解LinkedIn URNs
LinkedIn使用URNs(统一资源名称)来识别资源:
- 人:
urn:li:person:AbC123XyZ - 发布/分享:
urn:li:share:7289123456789 - 评论:
urn:li:comment:(ugcPost:7289123456789,7289987654321) - 组织机构:
urn:li:organization:1035 - 职位:
urn:li:job:123456789
当Claude返回URN时,您可以在其他命令中使用它来引用该资源。
API权限和限制
可用权限
此服务器请求以下OAuth作用域:
openid-OpenID连接身份验证profile-访问个人资料信息email-访问电子邮件地址w_member_social-创建帖子和评论
已知限制
某些LinkedIn API功能需要额外的权限,这些权限仅限于经批准的合作伙伴:
受限读取操作:
r_member_social-阅读用户的帖子(很少授予第三方应用程序)- 营销开发平台-高级公司/人员搜索
- 人才解决方案-高级求职功能
这意味着:
- 创建帖子:效果完美
- 删除帖子:效果完美
- 阅读自己的帖子:可能不起作用(需要受限权限)
- 高级搜索:可能需要获得营销/人才API的批准
为什么? LinkedIn限制这些API以保护用户隐私并控制第三方对其平台的访问。
项目结构
linkedin-mcp-server/
├── linkedin_mcp_server/ # Main package
│ ├── __init__.py # Package initialization
│ ├── __main__.py # CLI entry point
│ ├── server.py # MCP server with 18 tool definitions
│ ├── config.py # Configuration with pydantic-settings
│ ├── utils.py # Shared HTTP client utilities
│ └── tools/ # Tool implementations
│ ├── auth.py # OAuth 2.0 authentication flow
│ ├── profile.py # Profile retrieval operations
│ ├── post.py # Post and comment operations
│ ├── company.py # Company search and profiles
│ ├── job.py # Job search operations
│ └── search.py # People search functionality
├── pyproject.toml # Package metadata and dependencies
├── requirements.txt # Pinned dependencies
├── README.md # This file
├── claude.md # Claude integration guide
├── LICENSE # MIT License
└── get_profile.py # Example standalone script发展
设置开发环境
# Clone repository
git clone https://github.com/SARAMALI15792/LinkedIn_mcp_custom_server.git
cd LinkedIn_mcp_custom_server
# Install with dev dependencies
pip install -e ".[dev]"运行测试
pytest tests/代码质量
# Format code
black linkedin_mcp_server/
# Lint
ruff check linkedin_mcp_server/
# Type checking
mypy linkedin_mcp_server/本地运行
# Using module syntax
python -m linkedin_mcp_server
# Using installed command
linkedin-mcp-server故障排除
身份验证问题
问题: “错误:未配置LINKEDIN_CLIENT_ID” 解决方案: 创建 .env 使用您的LinkedIn应用凭据文件
问题: “未授权(401)”错误 解决方案: 您的访问令牌已过期。使用OAuth流重新进行身份验证
问题: “交换代码时出错:无效代码” 解决方案: 授权码很快过期。生成新的OAuth URL并重试
API错误
问题: “禁止(403)”错误 解决方案: 您的LinkedIn应用程序可能缺少所需的权限。在开发者门户中查看应用程序的产品
问题: “需要r_member_social权限” 解决方案: 此权限受到限制。LinkedIn很少将其授予第三方应用程序。转而专注于写操作
问题: 无法搜索公司/工作/人员 解决方案: 这些API可能需要营销/人才解决方案产品,这些产品需要LinkedIn批准
连接问题
问题: Claude Desktop中的MCP服务器未连接 解决方案:
- 验证
claude_desktop_config.json语法是有效的JSON - 检查命令路径是否正确
- 重新启动克劳德桌面
- 检查Claude Desktop日志中的错误消息
问题: “找不到.env文件” 解决方案: 创建 .env Claude Desktop运行服务器的同一目录中的文件,或在配置中指定环境变量
安全最佳实践
- 从不提交凭据 -
.env在...里.gitignore事出有因 - 定期旋转令牌 -定期重新验证以确保安全
- 在生产环境中使用HTTPS -将生产应用程序的重定向URI更新为HTTPS
- 最低权限 -只有您实际需要的请求范围
- 查看应用程序访问权限 -定期查看LinkedIn设置中的“应用程序”部分
贡献
欢迎投稿!方法如下:
- 分叉存储库
- 创建要素分支:
git checkout -b feature/amazing-feature - 进行更改
- 运行测试:
pytest tests/ - 格式代码:
black linkedin_mcp_server/ - 承诺:
git commit -m 'Add amazing feature' - 推:
git push origin feature/amazing-feature - 打开拉取请求
贡献指南
- 遵循现有的代码风格(黑色格式化程序,100个字符行长)
- 为新功能添加测试
- 根据需要更新文档
- 保持提交的重点和原子性
- 写明确的提交消息
路线图
正在考虑未来的增强功能:
- 令牌刷新流程实现
- Webhook支持实时通知
- 增强的错误处理和重试逻辑
- 搜索结果分页支持
- 批量操作以提高效率
- 分析和见解(如果授予API访问权限)
- 连接管理功能
- 消息发送(如果授予消息API访问权限)
常见问题解答
Q: 为什么我不能阅读自己的帖子? A: The r_member_social 阅读帖子所需的权限受到LinkedIn的限制。大多数第三方应用程序无法访问此功能。
Q: 访问令牌的时间有多长? A: LinkedIn控制令牌过期。通常,代币的有效期为60天,但这可能会有所不同。令牌过期时,您需要重新进行身份验证。
Q: 我可以将其用于多个LinkedIn帐户吗? A: 目前,服务器是为单用户身份验证而设计的。每 .env 文件包含一个访问令牌。
Q: 这是LinkedIn官方支持的吗? A: 不,这是一个社区项目。它使用LinkedIn的公共API,但没有得到LinkedIn的正式认可。
Q: 我可以在商业上使用它吗? A: 是的,MIT许可证允许商业使用。但是,请查看LinkedIn的服务条款和API使用政策。
Q: 为什么有些搜索返回空结果? A: 搜索API可能需要其他需要批准的LinkedIn产品(营销/人才)。此外,API访问权限因帐户类型而异。
支持
- 报告错误:
- 文档:
- 集成指南: claude.md
- 讨论:
资源
许可证
此项目根据MIT许可证获得许可-请参阅 许可证 文件以获取详细信息。
致谢
内置:
- FastMCP -对于优秀的MCP框架
- 模型上下文协议 -用于启用AI代理集成
- 领英API -用于提供专业的网络功能
- 克劳德 -为了激励和测试这种集成
作者
萨拉·阿里
- 电子邮件:saramali15792@gmail.com
- github: @萨拉马里15792
- 项目: LinkedIn MCP自定义服务器
______________________________________________________________________
