Metadata-Version: 2.5
Name: keos-linkedin-leadsync-mcp
Version: 0.1.0
Summary: LinkedIn Lead Sync MCP server (official APIs only): OpenID profile, lead gen forms, lead responses and lead webhooks. The calling application supplies the access token.
License: MIT
Keywords: lead-sync,leadgen,linkedin,mcp
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Requires-Python: >=3.10
Requires-Dist: mcp<2,>=1.2.0
Requires-Dist: requests>=2.31.0
Description-Content-Type: text/markdown

# LinkedIn Lead Sync MCP Server

Official-API LinkedIn tools (no scraping) for the Lead Sync product: the authenticated
member's profile, the ad accounts and organizations they administer, Lead Gen Forms,
lead submissions, and lead webhook subscriptions.

Standalone bundle. It shares no code with `keos-linkedin-memberdata-mcp` and runs on its own.

## Why this is a separate bundle

LinkedIn does not allow Lead Sync and Member Data Portability to be requested on the same
developer app, so the two products need two apps with two client ids. One app, one client
id, one token, one MCP server.

This app also has Sign In with LinkedIn using OpenID Connect granted, so its token carries
the profile scopes and this bundle includes `linkedin_get_profile`. The Member Data app was
**denied** OIDC, so `keos-linkedin-memberdata-mcp` has no profile tool at all and reads the
profile record from the PROFILE snapshot domain instead. The two bundles are not symmetric,
and that asymmetry is driven by what LinkedIn approved per app.

**This server does not log in.** The calling application owns the LinkedIn OAuth flow,
user consent, token storage and re-authentication, and passes one access token with every
request. The server writes nothing to disk and needs no client id or secret.

## Run

```bash
uvx keos-linkedin-leadsync-mcp                                           # stdio, from PyPI
uvx --from . keos-linkedin-leadsync-mcp                                  # stdio, from this folder
python -m linkedin_leadsync_mcp                                          # stdio, from source
python -m linkedin_leadsync_mcp --http --port 8765                       # streamable HTTP at /mcp
keos-linkedin-leadsync-mcp --http --remote --host 0.0.0.0 --port 8765    # hosted / multi-user
```

## Tools (9)

| Tool | What it does |
|---|---|
| `linkedin_auth_status()` | Whether a token reached the server, where it came from, and the scopes your app must request. Never returns token values. |
| `linkedin_get_profile()` | The member's own profile via OpenID Connect — name, email, picture, locale, plus a derived `person_urn`. |
| `leadsync_list_ad_accounts()` | Sponsored ad accounts the member can access; supplies owner ids for SPONSORED leads. |
| `leadsync_list_organizations()` | Company pages the member holds a role on; supplies owner ids for organic leads. |
| `leadsync_list_lead_forms(owner_urn, count=10, start=0)` | Paged list of Lead Gen Forms for an ad account or organization. |
| `leadsync_get_lead_form(form_id)` | One form by numeric id. |
| `leadsync_list_lead_responses(owner_urn, lead_type, test_leads_only, submitted_after_ms, include_form_content)` | Lead submissions with answers, filtered by lead type, test-only flag and submission time. |
| `leadsync_get_lead_response(response_id)` | A single submission by response id. |
| `leadsync_list_notifications(owner_urn, lead_type)` | Webhook subscriptions that fire on new leads. |

## Token

One token covers every tool here.

| Source | Value |
|---|---|
| HTTP header | `Authorization: Bearer <token>` |
| Local fallback | `LINKEDIN_ACCESS_TOKEN` env / `.env` |

Scopes your application must request on it:

```
openid profile email
r_marketing_leadgen_automation r_ads r_ads_leadgen_automation r_events r_organization_admin
```

Your LinkedIn app needs the Lead Sync product approved, and the member needs a role on
the ad account or company page whose leads you read.

## What the calling application must implement

1. Send the user to `https://www.linkedin.com/oauth/v2/authorization` with
   `response_type=code`, your `client_id`, a `redirect_uri` registered on your LinkedIn app
   (HTTPS, not localhost, for a hosted app), a `state` value, and the scopes above.
2. Exchange the returned code at `https://www.linkedin.com/oauth/v2/accessToken`.
3. Store the token per user and send it on every MCP request.

There is no token refresh in this server. LinkedIn access tokens last about 60 days and
refresh tokens are only issued to approved apps, so your application has to track expiry
and re-run consent. A lapsed token surfaces here as `HTTP 401`.

## Configuration

| Key | Purpose |
|---|---|
| `LINKEDIN_ACCESS_TOKEN` | Local-only token fallback. Ignored with `--remote`. |
| `LINKEDIN_ENV_FILE` | Path to the `.env` file. Defaults to `./.env`. |
| `LINKEDIN_REMOTE_MODE` | `1` is equivalent to `--remote`. |
| `LEADSYNC_OWNER_TYPE` | Default owner type: `sponsoredAccount` or `organization`. |
| `LEADSYNC_OWNER_ID` | Default numeric owner id, used when `owner_urn` is omitted. |
| `LEADSYNC_LEAD_TYPE` | Default lead type. Defaults to `SPONSORED`. |
| `LEADSYNC_API_VERSION` | `Linkedin-Version` header. Defaults to `202610`. |

`.env` is read, never written. Process env overrides `.env`.

## Responses

`{ "ok": true, "data": ... }` or `{ "ok": false, "error": "linkedin_error", "message": "..." }`.

## Remote / hosted mode

```bash
keos-linkedin-leadsync-mcp --http --remote --host 0.0.0.0 --port 8765   # or LINKEDIN_REMOTE_MODE=1
```

Use this whenever more than one user's tokens pass through the server.

- The token comes only from the request header. The env/`.env` fallback is refused, so a
  request without a header errors instead of borrowing another caller's stored credential.
- `--remote` requires `--http`.
- Serve it behind HTTPS and restrict who can reach it (API key or network rules at the
  proxy). The server has no TLS or authentication of its own.
- If your gateway uses `Authorization` for its own API key, it will collide with the
  LinkedIn token. Use a different header for gateway auth, or have the proxy rewrite it.

Without `--remote`, an `--http` server falls back to the environment or `.env`. That is for
local development only; do not expose it to a network.

## Scope of the data

Every tool is limited to what the authenticated member can see. Lead submissions are
personal data belonging to the people who filled in your forms: store and use them
according to your consent and privacy terms.
