Skip to main content
Glama

linkedin_comment

Post comments on LinkedIn posts with a preview workflow. First generate a preview to review, then post after confirmation using the LinkedIn post URL and comment text.

Instructions

Post a comment on a LinkedIn post via Unipile. IMPORTANT: dry_run defaults to true — this returns a preview of the comment without posting it. WORKFLOW: 1) Call with dry_run=true, 2) Show preview to user, 3) Get confirmation, 4) Call with dry_run=false. Accepts a LinkedIn post URL (e.g. https://linkedin.com/feed/update/urn:li:activity:12345) or a raw URN (urn:li:activity:12345 or urn:li:ugcPost:67890).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
post_urlYesLinkedIn post URL (linkedin.com/feed/update/...) or raw URN (urn:li:activity:... or urn:li:ugcPost:...)
textYesComment text to post
dry_runNoDEFAULT TRUE. When true, returns a preview without posting. Set to false only after user confirms.

Implementation Reference

  • The `handleComment` function executes the logic for the linkedin_comment tool, including input validation, dry-run simulation, and actual LinkedIn API interaction.
    export async function handleComment(args) {
    	const { post_url, text, dry_run = true } = args;
    
    	if (
    		!post_url ||
    		typeof post_url !== "string" ||
    		post_url.trim().length === 0
    	) {
    		return { error: "post_url is required" };
    	}
    	if (!text || typeof text !== "string" || text.trim().length === 0) {
    		return { error: "text is required and must be a non-empty string" };
    	}
    
    	const urn = parsePostUrn(post_url);
    	if (!urn) {
    		return {
    			error: `Could not parse post URN from: "${post_url}". Provide a LinkedIn post URL (linkedin.com/feed/update/...) or a raw URN (urn:li:activity:...).`,
    		};
    	}
    
    	// ── Dry run ──────────────────────────────────────────────────────────────
    	if (dry_run) {
    		return {
    			status: "preview",
    			post_urn: urn,
    			comment_text: text,
    			character_count: text.length,
    			ready_to_post: true,
    		};
    	}
    
    	// ── Resolve account and post ─────────────────────────────────────────────
    	const accountResult = await resolveAccountId();
    	if (!accountResult.success) {
    		return {
    			error: `Could not resolve LinkedIn account: ${accountResult.error}`,
    		};
    	}
    
    	const result = await createComment(accountResult.data, urn, text);
    	if (!result.success) {
    		return { error: result.error, details: result.details };
    	}
    
    	return {
    		status: "posted",
    		post_urn: urn,
    		comment_id: result.data.commentId,
    		comment_text: text,
    		posted_at: new Date().toISOString(),
    	};
    }
  • The input schema for the linkedin_comment tool, defining parameters such as post_url, text, and dry_run.
    {
    	name: "linkedin_comment",
    	description:
    		"Post a comment on a LinkedIn post via Unipile. " +
    		"IMPORTANT: dry_run defaults to true — this returns a preview of the comment without posting it. " +
    		"WORKFLOW: 1) Call with dry_run=true, 2) Show preview to user, 3) Get confirmation, " +
    		"4) Call with dry_run=false. " +
    		"Accepts a LinkedIn post URL (e.g. https://linkedin.com/feed/update/urn:li:activity:12345) " +
    		"or a raw URN (urn:li:activity:12345 or urn:li:ugcPost:67890).",
    	inputSchema: {
    		type: "object",
    		properties: {
    			post_url: {
    				type: "string",
    				description:
    					"LinkedIn post URL (linkedin.com/feed/update/...) or raw URN (urn:li:activity:... or urn:li:ugcPost:...)",
    			},
    			text: {
    				type: "string",
    				description: "Comment text to post",
    			},
    			dry_run: {
    				type: "boolean",
    				description:
    					"DEFAULT TRUE. When true, returns a preview without posting. Set to false only after user confirms.",
    				default: true,
    			},
    		},
    		required: ["post_url", "text"],
    	},
    },
  • src/server.js:145-147 (registration)
    Registration of the linkedin_comment tool in the server request handler, mapping it to the handleComment function.
    case "linkedin_comment":
    	result = await handleComment(args || {});
    	break;
  • Helper function `parsePostUrn` used to canonicalize LinkedIn post URLs or raw URNs.
    export function parsePostUrn(postUrl) {
    	if (!postUrl) return null;
    
    	// Already a URN
    	if (postUrl.startsWith("urn:li:")) return postUrl.trim();
    
    	// Extract URN from URL (linkedin.com/feed/update/urn:li:activity:...)
    	const match = postUrl.match(/urn:li:[^/?#\s]+/);
    	if (match) return match[0];
    
    	return null;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/timkulbaev/mcp-linkedin'

If you have feedback or need assistance with the MCP directory API, please join our Discord server