linkedin-mcp

lurenss/linkedin-mcp

3.3

If you are the rightful owner of linkedin-mcp and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.

A Model Context Protocol (MCP) server for creating and managing LinkedIn posts, enabling AI assistants to interact with LinkedIn's API.

Tools
  1. create_linkedin_post

    Create a text-only LinkedIn post.

  2. create_linkedin_image_post

    Create a LinkedIn post with an image.

  3. get_linkedin_profile

    Get the authenticated user's LinkedIn profile information.

  4. validate_linkedin_credentials

    Validate that the LinkedIn credentials are working correctly.

LinkedIn MCP Server

A Model Context Protocol (MCP) server for creating and managing LinkedIn posts. This server enables AI assistants to interact with LinkedIn's API to create text posts, image posts, and retrieve profile information.

Features

  • ✅ Create text-only LinkedIn posts
  • ✅ Create LinkedIn posts with images
  • ✅ Get authenticated user's profile information
  • ✅ Validate LinkedIn API credentials
  • ✅ Support for post visibility settings (PUBLIC, CONNECTIONS)
  • ✅ Compatible with Claude Desktop and Windsurf IDE

Prerequisites

  • Node.js 18 or higher
  • npm or yarn
  • LinkedIn Developer App with OAuth 2.0 credentials
  • Required LinkedIn API permissions:
    • w_member_social - Create and manage posts
    • r_liteprofile (optional) - Access basic profile information
    • r_emailaddress (optional) - Access email address

Installation

  1. Clone the repository:
git clone https://github.com/yourusername/linkedin-mcp.git
cd linkedin-mcp
  1. Install dependencies:
npm install
  1. Build the TypeScript code:
npm run build

LinkedIn App Setup

Step 1: Create a LinkedIn Developer App

  1. Go to LinkedIn Developers
  2. Click "Create app"
  3. Fill in the required information:
    • App name: Choose a descriptive name (e.g., "My LinkedIn MCP Server")
    • LinkedIn Page: Select or create a company page to associate with your app
    • App logo: Upload an app logo (120x120px minimum)
    • Check the legal agreement checkbox
  4. Click "Create app"

Step 2: Configure OAuth 2.0 Settings

  1. In your app dashboard, go to the "Auth" tab
  2. Add Redirect URLs (for OAuth flow):
    • http://localhost:8080/callback
    • https://oauth.pstmn.io/v1/callback (for Postman testing)
  3. Note your credentials:
    • Client ID: Found at the top of the Auth page
    • Client Secret: Found below the Client ID (keep this secure!)

Step 3: Request API Access

  1. Go to the "Products" tab in your app dashboard
  2. Request access to the following products:
    • Share on LinkedIn - Required for posting capabilities
    • Sign In with LinkedIn - Required for authentication
  3. These products will be automatically approved for development

Step 4: Generate an Access Token

Option A: Using LinkedIn's Token Generator (Easiest)
  1. In your app dashboard, look for "OAuth Token Tools" or similar in the Auth section
  2. Select the scopes: w_member_social
  3. Click "Generate token"
  4. Copy the access token (valid for 60 days)
Option B: Using Postman
  1. Open Postman and create a new request
  2. Go to the Authorization tab
  3. Select Type: OAuth 2.0
  4. Configure:
    • Token Name: LinkedIn Token
    • Grant Type: Authorization Code
    • Callback URL: https://oauth.pstmn.io/v1/callback
    • Auth URL: https://www.linkedin.com/oauth/v2/authorization
    • Access Token URL: https://www.linkedin.com/oauth/v2/accessToken
    • Client ID: Your LinkedIn app's Client ID
    • Client Secret: Your LinkedIn app's Client Secret
    • Scope: w_member_social r_liteprofile r_emailaddress
  5. Click "Get New Access Token"
  6. Authorize the app in the browser window that opens
  7. Copy the access token from Postman
Option C: Manual OAuth Flow
  1. Direct users to:
https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=http://localhost:8080/callback&scope=w_member_social%20r_liteprofile%20r_emailaddress
  1. After authorization, extract the code parameter from the callback URL

  2. Exchange the code for an access token:

curl -X POST https://www.linkedin.com/oauth/v2/accessToken \
  -H 'Content-Type: application/x-www-form-urlencoded' \
  -d 'grant_type=authorization_code' \
  -d 'code=YOUR_AUTH_CODE' \
  -d 'redirect_uri=http://localhost:8080/callback' \
  -d 'client_id=YOUR_CLIENT_ID' \
  -d 'client_secret=YOUR_CLIENT_SECRET'

Configuration

Environment Variables

Create a .env file in the project root:

# Required LinkedIn API credentials
LINKEDIN_CLIENT_ID=your_client_id_here
LINKEDIN_CLIENT_SECRET=your_client_secret_here
LINKEDIN_ACCESS_TOKEN=your_access_token_here

# Optional: API version (default: 202406)
LINKEDIN_API_VERSION=202406

Setting up with Claude Desktop

  1. Find your Claude Desktop configuration file:

    • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
    • Windows: %APPDATA%/Claude/claude_desktop_config.json
  2. Add the LinkedIn MCP server configuration:

{
  "mcpServers": {
    "linkedin-mcp": {
      "command": "/usr/bin/env",
      "args": ["node", "/path/to/linkedin-mcp/build/index.js"],
      "env": {
        "PATH": "/usr/local/bin:/usr/bin:/bin",
        "LINKEDIN_CLIENT_ID": "your_client_id",
        "LINKEDIN_CLIENT_SECRET": "your_client_secret",
        "LINKEDIN_ACCESS_TOKEN": "your_access_token",
        "LINKEDIN_API_VERSION": "202406"
      }
    }
  }
}
  1. For macOS users with Homebrew Node.js:
{
  "mcpServers": {
    "linkedin-mcp": {
      "command": "/usr/bin/env",
      "args": ["node", "/path/to/linkedin-mcp/build/index.js"],
      "env": {
        "PATH": "/opt/homebrew/opt/node@20/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin",
        "LINKEDIN_CLIENT_ID": "your_client_id",
        "LINKEDIN_CLIENT_SECRET": "your_client_secret",
        "LINKEDIN_ACCESS_TOKEN": "your_access_token",
        "LINKEDIN_API_VERSION": "202406"
      }
    }
  }
}
  1. Restart Claude Desktop

  2. Verify the server is running:

    • Look for the tools icon (🔨) in Claude Desktop
    • You should see the LinkedIn MCP server listed

Setting up with Windsurf IDE

  1. Create or edit the Windsurf MCP configuration file:

    • Location: ~/.codeium/windsurf/mcp_config.json
  2. Add the LinkedIn MCP server configuration:

{
  "mcpServers": {
    "linkedin-mcp": {
      "command": "/usr/bin/env",
      "args": ["node", "/path/to/linkedin-mcp/build/index.js"],
      "env": {
        "PATH": "/opt/homebrew/opt/node@20/bin:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin",
        "LINKEDIN_CLIENT_ID": "your_client_id",
        "LINKEDIN_CLIENT_SECRET": "your_client_secret",
        "LINKEDIN_ACCESS_TOKEN": "your_access_token",
        "LINKEDIN_API_VERSION": "202406"
      }
    }
  }
}
  1. Enable MCP in Windsurf:
    • Open Windsurf Settings (Cmd+Shift+P → "Open Windsurf Settings")
    • Navigate to the "Cascade" section
    • Enable Model Context Protocol
    • Restart or refresh the MCP servers

Available Tools

1. create_linkedin_post

Create a text-only LinkedIn post.

Parameters:

  • text (required): The text content of the post (max 3000 characters)
  • visibility (optional): Post visibility - "PUBLIC" or "CONNECTIONS" (default: "PUBLIC")

Example:

Create a LinkedIn post saying "Excited to share my latest project!"

2. create_linkedin_image_post

Create a LinkedIn post with an image.

Parameters:

  • text (required): The text content of the post
  • imageUrl (required): URL of the image to include
  • visibility (optional): Post visibility - "PUBLIC" or "CONNECTIONS" (default: "PUBLIC")

Example:

Post to LinkedIn with the text "Check out this amazing view!" and image https://example.com/image.jpg

3. get_linkedin_profile

Get the authenticated user's LinkedIn profile information.

Note: Requires additional profile permissions that may not be available with basic app access.

4. validate_linkedin_credentials

Validate that the LinkedIn credentials are working correctly.

Development

Running in development mode

npm run dev

Building the project

npm run build

Running tests

npm test

Troubleshooting

"403 Forbidden" Error

  • Ensure your app has the required products enabled (Share on LinkedIn)
  • Verify your access token has the w_member_social scope
  • Check that your access token hasn't expired (tokens last 60 days)

"500 Internal Server Error"

  • This might indicate an issue with LinkedIn's servers
  • Try generating a fresh access token
  • Ensure you're using the correct API version

"Cannot find module" Error

  • Make sure you've run npm install
  • Rebuild the project with npm run build
  • Check that the build directory exists

Server Won't Start in Claude/Windsurf

  • Verify the path to Node.js is correct in your configuration
  • Ensure all environment variables are properly set
  • Check logs in:
    • Claude: ~/Library/Logs/Claude/mcp-server-linkedin-mcp.log
    • Windsurf: ~/.codeium/windsurf/logs/

Security Best Practices

  1. Never commit credentials: Always use environment variables
  2. Keep tokens secure: Treat access tokens like passwords
  3. Rotate tokens regularly: Generate new tokens before they expire
  4. Use HTTPS: Always use HTTPS URLs in production
  5. Validate input: The server validates all inputs before sending to LinkedIn

API Limitations

  • Token expiration: Access tokens expire after 60 days
  • Rate limits: LinkedIn has rate limits on API calls
  • Post length: Maximum 3000 characters for post text
  • Image posts: Currently supports single image posts only
  • Profile access: Full profile access requires additional permissions

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgments

  • Built with the Model Context Protocol SDK
  • LinkedIn API documentation and developer resources
  • Claude Desktop and Windsurf IDE for MCP support