Labsco
souravdasbiswas logo

LinkedIn MCP Server

β˜… 3

from souravdasbiswas

A MCP server for LinkedIn REST API v2 that enables AI assistants to create, list, and delete posts, manage events, upload images, comment, and reactβ€”featuring OAuth 2.0 with session persistence, local post history tracking, and multiple automated tests

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedAccount requiredNeeds API keys

LinkedIn MCP Server

linkedin-mcp-server MCP server

A Model Context Protocol (MCP) server that provides AI assistants with access to LinkedIn's official API. Create posts, manage events, and interact with LinkedIn - all through natural language via any MCP-compatible client.

Official API only. No scraping, no unofficial endpoints, no account risk.

Features

Self-Serve Tools (No LinkedIn Approval Required)

ToolDescription
linkedin_auth_startStart OAuth 2.0 authentication flow
linkedin_auth_callbackComplete OAuth with authorization code
linkedin_auth_logoutRevoke token and log out
linkedin_get_my_profileGet your LinkedIn profile (name, headline, photo, email)
linkedin_get_my_emailGet your email address
linkedin_get_auth_statusCheck authentication status
linkedin_get_rate_limitsView API rate limit usage
linkedin_create_postCreate text, article, or image posts
linkedin_delete_postDelete your posts
linkedin_create_commentComment on posts
linkedin_react_to_postReact to posts (like, celebrate, support, love, insightful, funny)
linkedin_upload_imageUpload images for posts
linkedin_list_my_postsList posts created through this server with URNs for reference
linkedin_create_eventCreate LinkedIn events
linkedin_get_eventGet event details

Architecture Highlights

  • OAuth 2.0 - Secure authentication with persistent token storage
  • Session auto-restore - Survives server restarts without re-authentication (until token expires)
  • Post history tracking - Local SQLite log of posts created through the server for easy reference and deletion
  • Adaptive rate limiting - Learns LinkedIn's actual limits from response headers
  • Automatic retry - Exponential backoff for transient failures (429, 5xx)
  • Capability detection - Only exposes tools matching your granted scopes
  • API versioning - Handles LinkedIn's monthly API version rotation

Environment Variables

VariableRequiredDefaultDescription
LINKEDIN_CLIENT_IDYes-LinkedIn app client ID
LINKEDIN_CLIENT_SECRETYes-LinkedIn app client secret
LINKEDIN_REDIRECT_URINohttp://localhost:3000/callbackOAuth redirect URI
LINKEDIN_MCP_DATA_DIRNo~/.linkedin-mcpDirectory for token storage
LINKEDIN_API_BASE_URLNohttps://api.linkedin.comAPI base URL (override for testing)
LINKEDIN_AUTH_BASE_URLNohttps://www.linkedin.com/oauth/v2Auth base URL

Development

Copy & paste β€” that's it
# Install dependencies
npm install

# Type check
npm run typecheck

# Run tests
npm test

# Run tests in watch mode
npm run test:watch

# Run with coverage
npm run test:coverage

# Lint
npm run lint

# Dev mode (tsx, no build needed)
npm run dev

Testing Architecture

Tests run entirely against a mock LinkedIn API server - no real API calls are made.

LayerWhat It TestsFiles
Unit testsAuth, PKCE, token store, rate limiter, errors, capabilitiestests/unit/
Integration testsFull MCP protocol flow via in-memory transporttests/integration/
Contract testsRequest/response shapes match LinkedIn API spectests/contract/

Project Structure

Copy & paste β€” that's it
src/
  index.ts              # Entry point, stdio transport
  server.ts             # MCP server wiring
  auth/
    oauth2.ts           # OAuth 2.0 flow + token exchange
    token-store.ts      # SQLite token persistence + session auto-restore
    pkce.ts             # PKCE challenge generation (available for public clients)
    tools.ts            # Auth MCP tools
  client/
    api-client.ts       # HTTP client with retry
    rate-limiter.ts     # Adaptive rate limiting
    version-manager.ts  # LinkedIn API versioning
    errors.ts           # Structured error types
    post-history.ts     # Local post tracking (SQLite)
  capabilities/
    detector.ts         # Scope-based capability detection
  modules/
    profile/tools.ts    # Profile reading tools
    posting/tools.ts    # Post creation/management tools
    events/tools.ts     # Event management tools
  types/
    linkedin.ts         # LinkedIn API type definitions
    config.ts           # Server configuration types

Extending to Pro Tier

If your LinkedIn app has Community Management API or Advertising API approval, the server's capability detection will automatically enable additional modules when you authenticate with the corresponding scopes. The modular architecture supports adding new API modules without modifying the core server.

License

MIT