LinkedIn MCP Server

LinkedIn MCP Server

A production-ready MCP server for interacting with the LinkedIn API, enabling profile lookup, post creation and deletion, image posting, and organization page management through a secure tool-based interface.

Category
访问服务器

README

LinkedIn MCP Server

A production-ready Model Context Protocol (MCP) server for interacting with the LinkedIn API through a secure, tool-based interface. This project is designed for developers who want to use LinkedIn from MCP-compatible clients such as Claude Desktop, Cursor, VS Code, or custom agents.

The server supports profile lookup, publishing posts, uploading image posts, deleting posts, and managing organization page feeds when the appropriate LinkedIn partner permissions are enabled.

Why this project exists

LinkedIn exposes powerful APIs, but integrating them into MCP workflows usually requires writing a fair amount of boilerplate for authentication, token storage, callback handling, and request retry logic. This project packages those concerns into a small, maintainable server so you can focus on using the tools rather than building the plumbing yourself.

Key features

  • OAuth 2.0 authentication flow with local callback handling
  • Automatic token caching and refresh support
  • Profile retrieval via LinkedIn OpenID Connect
  • Text post creation and deletion
  • Image post creation with upload and status polling
  • Organization page support for partner-tier applications
  • Clear error handling and structured logging
  • Ready-to-use MCP tool definitions for client integration

Supported capabilities

Personal profile tools

  • get_profile: retrieve your profile details and Person URN
  • create_post: publish a text post to your personal feed
  • upload_image_post: upload an image and publish it as a post
  • delete_post: remove a published post by URN

Organization tools

  • get_organization_pages: list organization pages you can manage
  • create_company_post: publish a post to a company page feed
  • list_recent_posts: inspect recent posts on an organization page

Organization features require the correct LinkedIn partner-tier permissions and app scopes. If those permissions are missing, the server raises explicit errors that guide you toward the correct setup steps.

Architecture overview

The project is organized into a few simple layers:

  • server.py: starts the FastMCP server and registers tools
  • tools.py: exposes MCP tool implementations
  • auth.py: manages OAuth flows, redirect handling, and token exchange
  • linkedin_client.py: wraps LinkedIn HTTP requests and error handling
  • config.py: loads configuration from environment variables and .env
  • tests/: contains automated tests for the core behavior

Prerequisites

Before you begin, make sure you have:

  • Python 3.11 or newer
  • pip installed
  • A LinkedIn developer app created in the LinkedIn Developer Portal
  • A valid redirect URI configured for local development

LinkedIn developer app setup

To use this server, you need to create a LinkedIn app and configure it correctly.

  1. Go to the LinkedIn Developer Portal.
  2. Create a new app.
  3. Under the Products tab, enable:
    • Share on LinkedIn
    • Sign In with LinkedIn using OpenID Connect
  4. Under the Auth tab, copy your Client ID and Client Secret.
  5. Add a redirect URI such as http://localhost:8000/callback.
  6. Save the app and keep the credentials safe.

Installation

From the project root, install the dependencies:

pip install -r requirements.txt

If you use a virtual environment, activate it first:

python -m venv .venv
source .venv/bin/activate  # macOS/Linux
.venv\Scripts\activate   # Windows PowerShell
pip install -r requirements.txt

Configuration

Create a local environment file from the sample:

copy .env.example .env

On Linux or macOS, use:

cp .env.example .env

Then edit .env and set the values:

LINKEDIN_CLIENT_ID=your_linkedin_client_id_here
LINKEDIN_CLIENT_SECRET=your_linkedin_client_secret_here
LINKEDIN_REDIRECT_URI=http://localhost:8000/callback
LINKEDIN_SCOPES=w_member_social,openid,profile,email
LINKEDIN_TOKEN_CACHE_PATH=~/.linkedin_mcp_token.json
LINKEDIN_API_VERSION=202406

Environment variable reference

  • LINKEDIN_CLIENT_ID: your LinkedIn app client ID
  • LINKEDIN_CLIENT_SECRET: your LinkedIn app client secret
  • LINKEDIN_REDIRECT_URI: the locally served callback URL
  • LINKEDIN_SCOPES: the scopes required by the app
  • LINKEDIN_TOKEN_CACHE_PATH: where access tokens are cached
  • LINKEDIN_API_VERSION: LinkedIn API version header value

Running the server

Start the MCP server with:

python server.py

When the server starts, it will expose the available tools to whichever MCP client is connected to it.

OAuth flow walkthrough

The server handles OAuth automatically:

  1. It checks whether a cached access token already exists.
  2. If no valid token is available, it starts a temporary local callback listener.
  3. It opens the LinkedIn authorization page in your browser.
  4. After you authorize the app, LinkedIn redirects back to the callback URL.
  5. The server exchanges the authorization code for tokens and stores them locally.

This makes the authentication experience much smoother than manually wiring the callback flow for each integration.

Integrating with MCP clients

Claude Desktop

Add a server entry similar to the following in your Claude Desktop config:

{
  "mcpServers": {
    "linkedin-mcp": {
      "command": "python",
      "args": [
        "C:/path/to/linkedin_mcp/server.py"
      ],
      "env": {
        "LINKEDIN_CLIENT_ID": "your_linkedin_client_id_here",
        "LINKEDIN_CLIENT_SECRET": "your_linkedin_client_secret_here",
        "LINKEDIN_REDIRECT_URI": "http://localhost:8000/callback",
        "LINKEDIN_SCOPES": "w_member_social,openid,profile,email",
        "LINKEDIN_TOKEN_CACHE_PATH": "C:/Users/YourName/.linkedin_mcp_token.json",
        "LINKEDIN_API_VERSION": "202406"
      }
    }
  }
}

Cursor or other MCP clients

Most MCP-compatible clients support a command-based server definition. Point them to the server.py file and provide the same environment variables shown above.

Docker deployment

You can also run the server in Docker.

docker compose up --build -d

The compose configuration mounts a local data directory so the token cache can persist between container restarts.

Testing

Run the test suite with:

pytest

Security notes

  • Never commit your real .env file or any real credentials.
  • Keep your LinkedIn client secret private.
  • Use placeholders in sample configuration files.
  • If you publish this repository publicly, make sure the real secrets are removed from your local environment before pushing.

Project structure

linkedin_mcp/
├── auth.py
├── config.py
├── linkedin_client.py
├── server.py
├── tools.py
├── tests/
├── .env.example
├── .gitignore
├── README.md
└── requirements.txt

Troubleshooting

  • If the OAuth flow fails, confirm that the redirect URI in LinkedIn matches the value in .env exactly.
  • If the server cannot publish posts, verify that your LinkedIn app has the correct products enabled.
  • If organization tools fail, confirm that your app has the necessary partner-tier permissions.
  • If you see 401 or 403 errors, refresh the token cache or re-run the authorization flow.

Contributing

Pull requests are welcome. If you make changes, please keep the documentation up to date and avoid committing secrets or local environment files.

License

This project is provided as-is for educational and development purposes. Review LinkedIn's developer terms and API usage policies before deploying it publicly or in production.

推荐服务器

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

官方
精选