LinkedIn Poster

LinkedIn Poster

Enables ChatGPT and Claude Desktop to post text content directly to your LinkedIn profile using the official LinkedIn UGC Posts API with OAuth 2.0 authentication.

Category
访问服务器

README

MCP LinkedIn Poster (TypeScript)

An MCP (Model Context Protocol) server that allows ChatGPT / Claude Desktop to post content to LinkedIn using the official LinkedIn UGC Posts API and an OAuth 2.0 access token.

This server runs locally and is designed to be registered in your ChatGPT / Claude MCP server settings.


What this does

  • Runs an MCP server over stdio
  • Accepts post requests from ChatGPT / Claude
  • Publishes text posts to your LinkedIn profile
  • Uses LinkedIn OAuth (3-legged) authentication
  • Reads secrets securely via environment variables

Project structure

mcp-linkedin-poster/ ├─ src/ │ └─ index.ts # main MCP server (TypeScript source) ├─ dist/ │ └─ index.js # compiled output (what Node actually runs) ├─ .env # environment variables (DO NOT COMMIT) ├─ package.json ├─ tsconfig.json └─ README.md

yaml Copy code

What is dist?

dist stands for distribution.
It contains the compiled JavaScript output generated from TypeScript.

You edit src/index.ts
You run dist/index.js


Install

npm install
Build
Compile TypeScript → JavaScript:

bash
Copy code
npx tsc
This generates:

bash
Copy code
dist/index.js
Run locally (sanity check)
bash
Copy code
node dist/index.js
If environment variables are missing you will see:

bash
Copy code
Missing env LINKEDIN_ACCESS_TOKEN
Missing env LINKEDIN_AUTHOR_URN
That is expected until setup is complete.

Environment variables (.env)
Create a file named .env in the project root:

env
Copy code
LINKEDIN_ACCESS_TOKEN=
LINKEDIN_AUTHOR_URN=
LINKEDIN_VERSION=202502
What each variable is
Variable	Description
LINKEDIN_ACCESS_TOKEN	OAuth 2.0 member access token from LinkedIn
LINKEDIN_AUTHOR_URN	Your LinkedIn profile URN (urn:li:person:...)
LINKEDIN_VERSION	LinkedIn API version header (optional, safe to keep)

⚠️ Never commit .env
Add it to .gitignore.

How to get LINKEDIN_ACCESS_TOKEN
Go to https://www.linkedin.com/developers/

Open your LinkedIn app

Use OAuth 2.0 → Token Generator

Select scope:

w_member_social (required for posting)

Generate token

Copy it as a single line

Paste into .env:

env
Copy code
LINKEDIN_ACCESS_TOKEN=PASTE_TOKEN_HERE
How to get LINKEDIN_AUTHOR_URN
Method (recommended): LinkedIn userinfo endpoint
Curl
bash
Copy code
curl -X GET "https://api.linkedin.com/v2/userinfo" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "Content-Type: application/json"
Example response:

json
Copy code
{
  "sub": "8qD1tr1-1m",
  "name": "Your Name"
}
Your author URN becomes:

env
Copy code
LINKEDIN_AUTHOR_URN=urn:li:person:8qD1tr1-1m
Windows PowerShell version
powershell
Copy code
$token="YOUR_ACCESS_TOKEN"
Invoke-RestMethod `
  -Uri "https://api.linkedin.com/v2/userinfo" `
  -Headers @{ Authorization = "Bearer $token" }
Example: LinkedIn post via curl (UGC API)
bash
Copy code
curl -X POST "https://api.linkedin.com/v2/ugcPosts" \
  -H "Authorization: Bearer YOUR_ACCESS_TOKEN" \
  -H "X-Restli-Protocol-Version: 2.0.0" \
  -H "Content-Type: application/json" \
  -d '{
    "author": "urn:li:person:YOUR_PERSON_ID",
    "lifecycleState": "PUBLISHED",
    "specificContent": {
      "com.linkedin.ugc.ShareContent": {
        "shareCommentary": { "text": "Hello from MCP 🚀" },
        "shareMediaCategory": "NONE"
      }
    },
    "visibility": {
      "com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"
    }
  }'
A 201 Created response means success.

Registering this server in ChatGPT / Claude MCP
Add this to your MCP config:

json
Copy code
{
  "mcpServers": {
    "linkedin_poster": {
      "command": "node",
      "args": [
        "C:\\Users\\User\\Desktop\\mcp-linkedin-poster\\dist\\index.js"
      ],
      "env": {
        "LINKEDIN_ACCESS_TOKEN": "PASTE_TOKEN_HERE",
        "LINKEDIN_AUTHOR_URN": "urn:li:person:PASTE_ID_HERE",
        "LINKEDIN_VERSION": "202502"
      }
    }
  }
}
Restart ChatGPT / Claude Desktop after saving.

Common errors & fixes
❌ Missing env LINKEDIN_ACCESS_TOKEN
.env not created

MCP config missing env

Token pasted with line breaks

❌ Invalid OAuth 2.0 Access Token (code 190)
Token expired

Wrong app

Missing w_member_social scope

Regenerate token.

❌ PowerShell header error
Use a hashtable, not a string:

powershell
Copy code
-Headers @{ Authorization = "Bearer $token" }
❌ Node cannot find dist/index.js
Run commands from the project root, not src/.

Correct:

bash
Copy code
node dist\index.js
Wrong:

bash
Copy code
node src\dist\index.js
Security notes
Treat LinkedIn tokens like passwords

Do not commit secrets

Prefer MCP environment injection over .env in production
**
for CLAUDE

    "linkedin_poster": {
      "command": "node",
      "args": [
        "C:\\Users\\User\\Desktop\\mcp-linkedin-poster\\dist\\index.js"
      ],
      "env": {
        "LINKEDIN_ACCESS_TOKEN": "",
        "LINKEDIN_AUTHOR_URN": "urn:li:person:",
        "LINKEDIN_VERSION": "202502"

推荐服务器

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 模型以安全和受控的方式获取实时的网络信息。

官方
精选