linkedin-mcp-server

linkedin-mcp-server

A production-ready MCP server that enables AI agents to autonomously create, manage, and engage with LinkedIn content through the official LinkedIn REST API.

Category
访问服务器

README

LinkedIn MCP Server

License: MIT Node.js Version MCP Version Tests

A production-ready Model Context Protocol (MCP) server connecting AI agents (Google Gemini Spark, OpenAI Codex, Claude Desktop, Cursor, Windsurf) to the official LinkedIn REST API.

Enables AI agents to autonomously draft and publish text updates, share rich link previews, upload images, create interactive polls, manage existing posts, and engage with reactions and threaded comments.

https://github.com/user-attachments/assets/cda965be-d6a2-4a37-8d3c-29a68a9959e1


Features

  • Dual-Mode MCP Transport:
    • Server-Sent Events (SSE) via GET /mcp and POST /messages for clients like Google Gemini Spark and Claude.
    • Streamable HTTP via POST /mcp for modern command-line and agent runtimes like OpenAI Codex (rmcp).
  • 12 Comprehensive Tools:
    • Content Creation: Text updates, article link preview cards, binary image uploads (3-step pipeline), and multi-option polls.
    • Content Management: Delete posts by URN, fetch engagement statistics (likes, comments, shares), and verify account profile connections.
    • Social Engagement: Add reactions (LIKE, CELEBRATE, LOVE, INSIGHTFUL, FUNNY, EMPATHY), delete reactions, add comments, reply in threads, and remove comments.
  • Robust Validation: Powered by Zod schemas for all tool input parameters.
  • Enterprise-Ready: Automated unit and integration test suite with 100% endpoint coverage.

Tool Reference

Tool Category Description Parameters
create_text_post Content Publish a standard text post to your LinkedIn feed content (string, required)
create_link_post Content Publish a post with a clickable preview card content (string), url (string, URL), title (string)
create_image_post Content Download an image from a URL, upload it to LinkedIn, and publish content (string), image_url (string, URL)
create_poll_post Content Create a poll with customizable duration question (string), options (string array, 2-4 items), duration (ONE_DAY, THREE_DAYS, ONE_WEEK, TWO_WEEKS)
delete_post Management Delete a post using its Post URN post_urn (string, e.g. urn:li:ugcPost:...)
get_user_profile Management Retrieve authenticated profile details (name, member ID) None
get_post_stats Management Fetch engagement metrics (likes, comments, shares) post_urn (string)
react_to_post Engagement Add a reaction to a post post_urn (string), reaction_type (LIKE, CELEBRATE, LOVE, INSIGHTFUL, FUNNY, EMPATHY)
remove_reaction Engagement Remove your reaction from a post post_urn (string)
comment_on_post Engagement Add a top-level comment on a post post_urn (string), comment_text (string)
delete_comment Engagement Delete a comment you made post_urn (string), comment_id (string)
reply_to_comment Engagement Post a threaded reply to an existing comment post_urn (string), parent_comment_urn (string), reply_text (string)

Setup & Authentication

1. LinkedIn Developer Portal Setup

  1. Create a LinkedIn application in the LinkedIn Developer Portal.
  2. Under the Products tab, request access to:
    • Share on LinkedIn (provides w_member_social permission)
    • Sign In with LinkedIn using OpenID Connect (provides openid and profile permissions)
  3. In the Auth tab, add a redirect URL (e.g. https://httpbin.org/get or your domain).

2. Generate a User Access Token

  1. Construct the authorization URL in your browser:
    https://www.linkedin.com/oauth/v2/authorization?response_type=code&client_id=YOUR_CLIENT_ID&redirect_uri=YOUR_REDIRECT_URI&scope=openid%20profile%20w_member_social
    
  2. Authorize the application and copy the code query parameter from the redirection URL.
  3. Exchange the code for a 60-day access token:
    curl -X POST https://www.linkedin.com/oauth/v2/accessToken \
      -d "grant_type=authorization_code" \
      -d "code=YOUR_AUTHORIZATION_CODE" \
      -d "client_id=YOUR_CLIENT_ID" \
      -d "client_secret=YOUR_CLIENT_SECRET" \
      -d "redirect_uri=YOUR_REDIRECT_URI"
    
  4. Fetch your member ID:
    curl -H "Authorization: Bearer YOUR_ACCESS_TOKEN" https://api.linkedin.com/v2/userinfo
    
    The sub field is your member identifier (e.g., urn:li:person:<sub_id>).

Configuration

Copy the sample environment file:

cp .env.example .env

Configure your .env variables:

LINKEDIN_ACCESS_TOKEN=your_oauth2_access_token
LINKEDIN_AUTHOR_URN=urn:li:person:your_member_sub_id
PORT=3000

Running Locally

# Install dependencies
npm install

# Run unit and integration tests
npm test

# Start the server
npm start

# Start in development mode (with live reload)
npm run dev

Client Integration

OpenAI Codex CLI

Add the server using the Codex CLI:

codex mcp add linkedin --url https://your-server-domain.com/mcp

Or add it directly to ~/.codex/config.toml:

[mcp_servers.linkedin]
url = "https://your-server-domain.com/mcp"

Claude Desktop

Add to your claude_desktop_config.json:

{
  "mcpServers": {
    "linkedin": {
      "command": "node",
      "args": ["/path/to/linkedin-mcp-server/server.js"],
      "env": {
        "LINKEDIN_ACCESS_TOKEN": "your_access_token",
        "LINKEDIN_AUTHOR_URN": "urn:li:person:your_sub_id"
      }
    }
  }
}

Google Gemini Spark

In your Gemini Spark custom applications settings, enter your public SSE endpoint URL:

https://your-server-domain.com/mcp

Deployment

Deploy to Railway

  1. Install the Railway CLI: npm i -g @railway/cli
  2. Link or create a project:
    railway init
    railway up
    
  3. Set environment variables:
    railway variable set LINKEDIN_ACCESS_TOKEN="your_token" LINKEDIN_AUTHOR_URN="urn:li:person:your_sub_id"
    
  4. Generate a public domain:
    railway domain
    

Development & Testing

The test suite includes 62 automated unit and integration tests covering the LinkedIn API client, all 12 tool registrations and execution handlers, and SSE / Streamable HTTP transports.

# Run tests once
npm test

# Run tests in watch mode
npm run test:watch

License

This project is licensed under the MIT License.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选