LinkedIn MCP Server
A FastMCP server for LinkedIn automation that provides comprehensive LinkedIn API integration with support for creating, updating, and deleting posts with media (images, videos, documents).
๐ Features
Core Tools
- create_post: Create LinkedIn posts with text, images, videos, or documents
- update_post: Update existing LinkedIn post text
- delete_post: Delete LinkedIn posts (supports both UGC and Share formats)
Media Support
- TEXT: Simple text posts
- IMAGE: Image uploads (JPG, PNG, GIF)
- VIDEO: Video uploads (MP4, MOV, AVI) with extended timeout support
- DOCUMENT: Document uploads (PDF, DOC, DOCX, PPT, PPTX)
Advanced Features
- Intelligent timeout handling (up to 10 minutes for large files)
- Dynamic video processing wait times based on file size
- Proper URN encoding for post operations
- Comprehensive error handling and progress feedback
- Support for both UGC posts and legacy Share posts
๐ Prerequisites
- Python 3.10 or higher
uvpackage manager- LinkedIn Developer Account with API access
- Valid LinkedIn Access Token with required permissions
Required LinkedIn API Permissions
w_member_social: Write access to member's social posts- (Optional)
r_liteprofile: Read basic profile information
๐ Installation
-
Clone or download the project
mkdir linkedin-mcp cd linkedin-mcp -
Install dependencies
uv init uv add fastmcp>=2.12.4 requests -
Set up LinkedIn API credentials
- Create a LinkedIn Developer App at LinkedIn Developer Portal
- Generate an Access Token with
w_member_socialpermission - Get your Member URN (personal LinkedIn profile URN)
โ๏ธ Configuration
Update the following variables in main.py with your LinkedIn credentials:
# LinkedIn API Credentials (REPLACE WITH YOUR VALUES)
LINKEDIN_ACCESS_TOKEN = "YOUR_ACCESS_TOKEN_HERE"
LINKEDIN_MEMBER_URN = "urn:li:person:YOUR_MEMBER_ID"
LINKEDIN_API_BASE = "https://api.linkedin.com/v2"
How to Get Your Credentials
-
Access Token:
- Go to LinkedIn Developer Portal
- Create an app and request
w_member_socialpermission - Generate access token from your app settings
-
Member URN:
- Use LinkedIn API
/meendpoint to get your profile - Extract the URN from the response
- Format:
urn:li:person:XXXXXXXXXX
- Use LinkedIn API
๐ Usage
Starting the Server
# Start in development mode
uv run fastmcp dev main.py
The server will start on http://localhost:6274 with MCP Inspector available for testing.
Tool Examples
1. Create Text Post
create_post(
content="Hello LinkedIn! This is my first MCP post.",
media_type="TEXT"
)
2. Create Image Post
create_post(
content="Check out this amazing image!",
media_type="IMAGE",
file_path="C:/path/to/your/image.jpg"
)
3. Create Video Post
create_post(
content="Watch this cool video!",
media_type="VIDEO",
file_path="C:/path/to/your/video.mp4"
)
4. Create Document Post
create_post(
content="Read my latest report",
media_type="DOCUMENT",
file_path="C:/path/to/your/document.pdf"
)
5. Update Post
update_post(
post_id="urn:li:ugcPost:1234567890",
new_text="Updated post content"
)
6. Delete Post
delete_post(post_id="urn:li:ugcPost:1234567890")
# or for legacy shares
delete_post(post_id="urn:li:share:1234567890")
โฑ๏ธ Timeout Configuration
The server uses intelligent timeout handling:
- TEXT posts: 30 seconds
- IMAGE posts: 2 minutes
- VIDEO posts: 10 minutes
- DOCUMENT posts: 10 minutes
File upload timeouts are dynamic based on file size:
- Files < 10MB: 2 minutes
- Files 10-50MB: 5 minutes
- Files > 50MB: 10 minutes
๐ง Technical Details
Media Upload Process
- Registration: Register upload with LinkedIn to get upload URL and asset URN
- Binary Upload: Upload the actual file data to LinkedIn's storage
- Processing Wait: Wait for LinkedIn to process the media (especially videos)
- Post Creation: Create the LinkedIn post with the uploaded media
Error Handling
The server provides comprehensive error handling:
- File existence validation
- Media type validation
- Upload failure recovery
- Timeout management
- LinkedIn API error parsing
URN Handling
The server properly handles different LinkedIn URN formats:
- UGC Posts:
urn:li:ugcPost:{id} - Legacy Shares:
urn:li:share:{id} - Proper URL encoding for API calls
๐ Project Structure
linkedin-mcp/
โโโ main.py # Main MCP server code
โโโ pyproject.toml # Python project configuration
โโโ README.md # This file
โโโ .env # Environment variables (optional)
๐ API Reference
create_post(content, media_type="TEXT", file_path=None)
Create a new LinkedIn post with optional media.
Parameters:
content(str): Text content of the postmedia_type(str): Type of media - "TEXT", "IMAGE", "VIDEO", or "DOCUMENT"file_path(str, optional): Absolute path to media file
Returns:
- Dict with success status, post URN, and any error details
update_post(post_id, new_text)
Update the text content of an existing UGC post.
Parameters:
post_id(str): Post URN (e.g., "urn:li:ugcPost:1234567890")new_text(str): New text content
Returns:
- Dict with success status and operation details
delete_post(post_id)
Delete a LinkedIn post (supports both UGC and Share formats).
Parameters:
post_id(str): Post URN (e.g., "urn:li:ugcPost:1234567890" or "urn:li:share:1234567890")
Returns:
- Dict with success status and operation details
๐จ Important Notes
Timeout Behavior
- If you see a timeout error but the post appears on LinkedIn, the upload succeeded
- LinkedIn processes uploads in the background, so timeouts may occur before final confirmation
- Check your LinkedIn profile to verify post creation
File Size Limits
- LinkedIn has file size limits for different media types
- Large videos (>100MB) may take the full 10-minute timeout
- Consider compressing large files before upload
API Rate Limits
- LinkedIn has rate limits on API calls
- Space out your requests to avoid hitting limits
- The server includes appropriate delays for video processing
๐ Troubleshooting
Common Issues
-
"ACCESS_DENIED" errors
- Verify your access token has the required permissions
- Check that your LinkedIn app has
w_member_socialpermission
-
"File not found" errors
- Use absolute file paths
- Ensure file exists and is accessible
-
Upload timeouts
- Check your internet connection
- Try smaller files first
- Remember: timeout doesn't always mean failure
-
Invalid URN format
- Post IDs must start with
urn:li:ugcPost:orurn:li:share: - Get correct URNs from post creation responses
- Post IDs must start with
Debug Mode
Start the server with debug logging:
uv run fastmcp dev main.py --debug
๐ License
This project is provided as-is for educational and development purposes. Please ensure compliance with LinkedIn's API Terms of Service.
๐ค Contributing
Feel free to submit issues, feature requests, or pull requests to improve this LinkedIn MCP server.
๐ Support
For questions or issues:
- Check the troubleshooting section above
- Review LinkedIn's API documentation
- Test with the MCP Inspector at
http://localhost:6274
Note: Replace all placeholder credentials in main.py with your actual LinkedIn API credentials before running the server.