Skip to main content
Glama

LinkedIn Content Creation MCP Server

by chrishayuk
try_post.py2.57 kB
#!/usr/bin/env python3 """ Try to make a test post to LinkedIn to reveal URN info from error. """ import asyncio import sys from pathlib import Path sys.path.insert(0, str(Path(__file__).parent.parent / "src")) import httpx from chuk_mcp_linkedin.api import config async def try_post(): """Try different person URN formats""" print("Testing LinkedIn Person URN formats") print("=" * 60) print() # Different URN formats to try urns_to_try = [ config.linkedin_person_urn, # Try the URN from .env first "urn:li:person:me", "me", ] test_text = "Test post - please ignore" for urn in urns_to_try: print(f"Trying with URN: {urn}") payload = { "author": urn, "lifecycleState": "PUBLISHED", "specificContent": { "com.linkedin.ugc.ShareContent": { "shareCommentary": {"text": test_text}, "shareMediaCategory": "NONE", } }, "visibility": {"com.linkedin.ugc.MemberNetworkVisibility": "PUBLIC"}, } url = "https://api.linkedin.com/v2/ugcPosts" async with httpx.AsyncClient() as client: try: response = await client.post( url, json=payload, headers={ "Authorization": f"Bearer {config.linkedin_access_token}", "Content-Type": "application/json", "X-Restli-Protocol-Version": "2.0.0", }, timeout=30.0, ) print(f" Status: {response.status_code}") if response.status_code in (200, 201): print(f" ✓ SUCCESS! This URN works: {urn}") result = response.json() print(f" Response: {result}") print() print("Add this to .env:") print(f"LINKEDIN_PERSON_URN={urn}") return else: print(f" Error: {response.text}") print() except Exception as e: print(f" Exception: {e}") print() print("None of the URN formats worked.") print() print("The error messages above might contain clues about the correct format.") print("Look for any mention of 'person' or 'urn' in the error messages.") if __name__ == "__main__": asyncio.run(try_post())

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/chrishayuk/chuk-mcp-linkedin'

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