Claude can write a LinkedIn post, but it cannot publish one until a connector gives it a way in. Most pages on this search answer with a hosted product, or with an open-source LinkedIn MCP server that drives a browser session or a private API. This guide builds a small MCP server on your computer that calls LinkedIn's official Posts API with your own token, with Claude Desktop asking you before anything goes live.
It posts to your personal profile. Company Pages are a different permission with its own review, covered below.
The short version
- Create a LinkedIn app, add two self-serve products, and generate a token for yourself with
openid,profileandw_member_social. - Save
server.mjs, a local MCP server with three tools: upload an image, publish a post, delete a post. - Add it to
claude_desktop_config.jsonwith the token in itsenv, and restart Claude Desktop. - Ask Claude for a post. It drafts the text and asks before the one tool that publishes.
Official API or scraping
Many LinkedIn MCP servers log in as you in a browser, or call the endpoints LinkedIn's own site uses. LinkedIn's User Agreement forbids software that scrapes the service and "bots or other unauthorized automated methods" that create, like or share posts (User Agreement, 8.2). The risk is your own account.
The official route is narrower: a token you grant to an app you created, and only what its permissions allow. For posting as yourself, that is enough.
Before you start
- A LinkedIn app. Create one in the Developer Portal. LinkedIn ties some products to a LinkedIn Page that a Page admin verifies (associate an app with a Page).
- Two products on its Products tab, both self-serve: Share on LinkedIn, which grants
w_member_social(Share on LinkedIn), and Sign In with LinkedIn using OpenID Connect, which grantsopenidandprofile(OpenID Connect). The second one is how the server learns who you are. - A token. The Developer Portal has a token generator for making one by hand (3-legged OAuth). Pick your app and the three scopes
openid,profileandw_member_social, and sign in as yourself. - Claude Desktop and Node.js 20 or later.
Unlike Instagram, LinkedIn takes the image file itself, so a file on your laptop works. No public URL is needed.
The server
Make a folder for it and install the MCP TypeScript SDK (v2) and zod:
mkdir ~/linkedin-mcp && cd ~/linkedin-mcp
npm init -y
npm install @modelcontextprotocol/server zodThen save this as server.mjs in that folder:
// A local MCP server with three LinkedIn tools, for Claude Desktop.
import { readFile } from "node:fs/promises";
import { McpServer } from "@modelcontextprotocol/server";
import { serveStdio } from "@modelcontextprotocol/server/stdio";
import * as z from "zod/v4";
const API = "https://api.linkedin.com";
const VERSION = "202610"; // LinkedIn-Version: YYYYMM, each one works for at least a year
const { LINKEDIN_TOKEN } = process.env;
if (!LINKEDIN_TOKEN) {
console.error("Set LINKEDIN_TOKEN in the server's env");
process.exit(1);
}
async function linkedin(method, path, { json, headers } = {}) {
const res = await fetch(`${API}${path}`, {
method,
headers: {
Authorization: `Bearer ${LINKEDIN_TOKEN}`,
"LinkedIn-Version": VERSION,
"X-Restli-Protocol-Version": "2.0.0",
...(json && { "Content-Type": "application/json" }),
...headers,
},
body: json && JSON.stringify(json),
signal: AbortSignal.timeout(60_000),
});
const body = await res.text();
if (!res.ok) throw new Error(`${res.status} ${body}`);
return { data: body ? JSON.parse(body) : {}, id: res.headers.get("x-restli-id") };
}
// The member's URN, from Sign In with LinkedIn (scopes openid and profile).
let author;
async function me() {
if (!author) {
const res = await fetch(`${API}/v2/userinfo`, { headers: { Authorization: `Bearer ${LINKEDIN_TOKEN}` } });
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
author = `urn:li:person:${(await res.json()).sub}`;
}
return author;
}
// Commentary is in LinkedIn's "little" format: escape its reserved characters,
// and keep a # followed by a word as a hashtag.
const little = (s) => s.replace(/[\\|{}@[\]()<>*_~]|#(?![\p{L}\p{N}_])/gu, (c) => `\\${c}`);
const text = (value) => ({ content: [{ type: "text", text: JSON.stringify(value, null, 2) }] });
serveStdio(() => {
const server = new McpServer({ name: "linkedin", version: "1.0.0" });
server.registerTool(
"upload_linkedin_image",
{
description:
"Upload one JPG, PNG or GIF to LinkedIn and return its image URN for create_linkedin_post. Nothing is posted.",
inputSchema: z.object({
source: z.string().describe("Absolute path of a file on this computer, or an https URL"),
}),
},
async ({ source }) => {
const bytes = /^https:\/\//.test(source)
? Buffer.from(await (await fetch(source, { signal: AbortSignal.timeout(60_000) })).arrayBuffer())
: await readFile(source);
const { data } = await linkedin("POST", "/rest/images?action=initializeUpload", {
json: { initializeUploadRequest: { owner: await me() } },
});
const { uploadUrl, image } = data.value;
const put = await fetch(uploadUrl, {
method: "PUT",
headers: { Authorization: `Bearer ${LINKEDIN_TOKEN}` },
body: bytes,
signal: AbortSignal.timeout(120_000),
});
if (!put.ok) throw new Error(`upload ${put.status} ${await put.text()}`);
return text({ image });
},
);
server.registerTool(
"create_linkedin_post",
{
description:
"Publish a post on the user's LinkedIn profile. It goes live at once. Write the text as plain text: " +
"the server escapes it, and #word stays a hashtag. Call it only after the user said yes to this exact text, " +
"and never again for the same post if it fails: ask the user to check their profile first.",
inputSchema: z.object({
text: z.string().min(1),
image: z.string().startsWith("urn:li:image:").optional().describe("From upload_linkedin_image"),
alt_text: z.string().max(4086).optional(),
visibility: z.enum(["PUBLIC", "CONNECTIONS"]).default("PUBLIC"),
}),
},
async ({ text: commentary, image, alt_text, visibility }) => {
const { id } = await linkedin("POST", "/rest/posts", {
json: {
author: await me(),
commentary: little(commentary),
visibility,
distribution: { feedDistribution: "MAIN_FEED", targetEntities: [], thirdPartyDistributionChannels: [] },
...(image && { content: { media: { id: image, ...(alt_text && { altText: alt_text }) } } }),
lifecycleState: "PUBLISHED",
isReshareDisabledByAuthor: false,
},
});
return text({ post: id, url: `https://www.linkedin.com/feed/update/${id}/` });
},
);
server.registerTool(
"delete_linkedin_post",
{
description: "Delete one of the user's LinkedIn posts by its URN. Only when the user asks for it by name.",
inputSchema: z.object({ post: z.string().regex(/^urn:li:(share|ugcPost):\d+$/) }),
annotations: { destructiveHint: true, idempotentHint: true },
},
async ({ post }) => {
await linkedin("DELETE", `/rest/posts/${encodeURIComponent(post)}`, { headers: { "X-RestLi-Method": "DELETE" } });
return text({ deleted: post });
},
);
return server;
});What the server takes care of
- The author. Every post names its author as a person URN. The server reads your id once from
/v2/userinfo, thesubfield, and buildsurn:li:person:{id}(OpenID Connect, Share on LinkedIn). - The version header. The Posts API needs
LinkedIn-VersioninYYYYMMform andX-Restli-Protocol-Version: 2.0.0on every call (Posts API). Versions come out monthly and each is supported for at least a year; a call with a version past its sunset gets an error, and none is applied by default (versioning). MoveVERSIONforward once a year. - Escaping. This is the one that bites agents. The
commentaryfield is in LinkedIn'slittleformat, where| { } @ [ ] ( ) < > # \ * _ ~are reserved, and all of them must be escaped with a backslash "even if those characters are not used" in a mention or hashtag (little format). Claude writes parentheses, bullet asterisks and underscores in URLs all the time. The server escapes every reserved character except a#followed by a word, whichlittlereads as a hashtag. Mentions of people or Pages are escaped too, so they show as plain text. - The image.
initializeUploadreturns anuploadUrland anurn:li:image:URN, and the file goes to that URL (Images API). JPG, PNG and GIF are accepted, under 36,152,320 pixels (same page). A token with onlyw_member_socialcannot read an image back on the versioned API, so the server does not check its status.
Why publishing is its own tool
- It is the tool you approve. Uploading an image posts nothing. Publishing goes live at once:
PUBLISHEDis the only state the Posts API accepts on create, so there are no drafts (Post schema). - A failed publish is never retried. A post is created with a
201and its id in thex-restli-idheader (Posts API). If the call times out, the post may exist, and this token cannot list your posts to find out: reading a member's posts needsr_member_social, which is "restricted" to approved apps (same page). The tool description tells Claude to ask you to look at your profile instead. - LinkedIn's errors reach Claude as they are. A thrown error comes back as a tool result marked as an error, with LinkedIn's status and message. The common ones:
401for a missing or expired token,403 ACCESS_DENIEDfor a missing scope,400 FIELD_LENGTH_TOO_LONGfor text that is too long,429for too many requests (Posts API errors). - Delete is there for mistakes. Deleting a post is idempotent: deleting it again also returns
204(same page).
The server writes nothing to stdout itself: in a stdio server, stdout is the protocol channel, and logs go to stderr (stdio).
Add it to Claude Desktop
In Claude Desktop, open Settings, then Developer, then Edit Config. It opens claude_desktop_config.json, in ~/Library/Application Support/Claude/ on macOS and %APPDATA%\Claude\ on Windows (connect local servers). Add the server with absolute paths:
{
"mcpServers": {
"linkedin": {
"command": "node",
"args": ["/Users/you/linkedin-mcp/server.mjs"],
"env": {
"LINKEDIN_TOKEN": "<ACCESS_TOKEN>"
}
}
}
}Quit Claude Desktop completely and open it again. In a new chat, linkedin should be listed among the tools Claude can use, with its three tools. If it is not, the server's own log is mcp-server-linkedin.log in ~/Library/Logs/Claude on macOS or %APPDATA%\Claude\logs on Windows (same page). If node is not found, put the full path from which node in command.
The token lasts 60 days
All LinkedIn access tokens are issued for 60 days, and refresh tokens are only for "a limited set of partners" (3-legged OAuth). Generate a new one before then and paste it into the config, or every tool starts failing with a 401.
Two more things from the same page: asking for a different set of scopes invalidates your earlier tokens, and the token sits in the config file in plain text. With these three scopes it can read your name and post as you, nothing else.
Approve every post
Claude Desktop asks for your approval before it runs a tool from a local server, and you can deny it (connect local servers). That prompt is the safeguard:
upload_linkedin_imageposts nothing, so allowing it is a matter of taste.- Approve
create_linkedin_postonce per post, after reading the text in the request. Never let it run without asking. delete_linkedin_postcannot be undone. Approve it only for a post you named.
The tool descriptions also tell Claude to wait for your yes. The approval prompt is what makes sure of it, since a model can skip an instruction and cannot skip the prompt.
Post something
Write a LinkedIn post about what we learned moving our API docs to Markdown:
three short points, no more than two hashtags. Use /Users/you/Desktop/docs-chart.png
as the image, with alt text. Show me the text before you post.What follows, in order: Claude shows the text, you ask for changes or say yes, Claude asks to run upload_linkedin_image, then create_linkedin_post with the image URN, and replies with the post's link.
Share on LinkedIn allows 150 requests a day per member and 100,000 per app (Share on LinkedIn), far more than one person posts.
What it does not do
- Video, documents and multi-image posts. The Posts API takes all three, each with its own upload: the Videos API, the Documents API and MultiImage. Add a tool for each when you need them.
- Link previews. The Posts API does not scrape a URL into a card: an article post needs its title, description and thumbnail set by you (Posts API). A URL in the text still works as a link.
- Mentions. Tagging a person or Page needs their URN, written as
@[Name](urn)(little format). The server escapes@so text never turns into a broken mention. - Scheduling. The server runs while Claude Desktop is open and only when you ask. A post for later needs something that calls the API at that time.
Company Pages need another review
Posting as a Page uses w_organization_social, for members who are an administrator or content admin of the Page (Posts API). That permission comes with the Community Management API, which is not self-serve (Community Management API):
- Only a new app with no other product can request it, verified by the Page of your organization.
- It is "only available to registered legal organizations for commercial use cases", with a business email and a privacy policy.
- The first tier allows 500 calls a day per app and 100 per member, and a second review, with a screen recording, lifts the limits.
For one person's profile, Share on LinkedIn is the right size. For a Page, the review is the cost of the official route.
Where Rizamo fits
Rizamo is a social media API and MCP server that posts to LinkedIn profiles and Pages, documents included, with the uploads and the escaping handled for you. In Claude you add it from Claude's directory (listing, Claude on Rizamo). Rizamo is open: start free. Free for 2 social accounts, with unlimited posts, profiles, seats and agents, and the API and MCP included. No card.