Skip to main content
Glama
jahnavi-yarramsetty

LinkedIn MCP Server

README.md
# LinkedIn MCP Server

Read your own LinkedIn posts and articles inside **Claude Desktop** (or any MCP host) via the official LinkedIn OAuth 2.0 API.

> **Compliance** — This server uses only LinkedIn's official REST API with user-granted OAuth tokens. It accesses only the authenticated user's own data, performs no scraping, and stores no data beyond the local access token. Use is subject to the [LinkedIn API Terms of Use](https://legal.linkedin.com/api-terms-of-use).

---

## Tools

| Tool | Description |
|---|---|
| `authenticate()` | Start the OAuth flow — returns an auth URL to open in your browser |
| `check_auth_status()` | Verify the stored token is still valid |
| `get_profile()` | Return your LinkedIn profile (name, email, picture) |
| `get_my_posts(count)` | Fetch your most recent posts |
| `get_my_articles(count)` | Fetch your long-form articles (filtered from posts) |
| `get_post_detail(post_id)` | Full content of a single post by URN |
| `revoke_auth()` | Delete the stored token |

---

## Setup

### 1. LinkedIn Developer App

1. Go to [linkedin.com/developers/apps](https://www.linkedin.com/developers/apps) and create an app (or use an existing one).
2. Under **Auth**, add `http://localhost:8080/callback` as an **Authorized Redirect URL**.
3. Under **Products**, add:
   - **Sign In with LinkedIn using OpenID Connect** — provides `openid`, `profile`, `email`
   - **Community Management API** — provides `r_member_social` (required for reading posts)
4. Copy your **Client ID** and **Client Secret**.

### 2. Install dependencies

```bash
pip install -e .
```

Or without installing as a package:

```bash
pip install fastmcp httpx python-dotenv
```

### 3. Configure credentials

```bash
cp .env.example .env
```

Edit `.env`:

```env
LINKEDIN_CLIENT_ID=your_client_id
LINKEDIN_CLIENT_SECRET=your_client_secret
LINKEDIN_REDIRECT_URI=http://localhost:8080/callback
```

### 4. Configure Claude Desktop

Edit `%APPDATA%\Claude\claude_desktop_config.json` (Windows) or `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS):

```json
{
  "mcpServers": {
    "linkedin-posts": {
      "command": "python",
      "args": ["/absolute/path/to/server.py"],
      "cwd": "/absolute/path/to/linkedin-mcp"
    }
  }
}
```

Restart Claude Desktop after saving.

### 5. Authenticate

In Claude Desktop, ask:

> "Call authenticate"

Open the returned URL in your browser, sign in, and grant access. The token is saved to `~/.linkedin_mcp_token.json` automatically. Then try:

> "Call get_my_posts"

---

## Development / testing

Run the server with the MCP Inspector (browser UI for testing tools without Claude Desktop):

```bash
fastmcp dev inspector server.py --with-requirements requirements.txt
```

If `fastmcp` is not on your PATH, use the full path:

```bash
# Windows
C:\Users\<YOU>\AppData\Roaming\Python\Python3XX\Scripts\fastmcp.exe dev inspector server.py
```

---

## Token lifecycle

- LinkedIn access tokens are valid for **60 days**.
- There is no refresh token for standard apps — run `revoke_auth()` then `authenticate()` when the token expires.
- The token is stored at `~/.linkedin_mcp_token.json` (outside this repo).

---

## Troubleshooting

| Symptom | Fix |
|---|---|
| Tools not visible in Claude Desktop | Fully quit and reopen Claude Desktop; check **Settings → Developer** for MCP logs |
| `get_my_posts` returns 403 | Add **Community Management API** to your LinkedIn app products, then re-authenticate |
| `ModuleNotFoundError` | Run `pip install fastmcp httpx python-dotenv` |
| Port 8080 already in use | Change `LINKEDIN_REDIRECT_URI` in `.env` to another port and update your LinkedIn app's redirect URL list |

---

## License

MIT