@pipeworx/mcp-linkedin_ads 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +39 -0
- package/package.json +20 -0
- package/server.json +18 -0
- package/src/index.ts +194 -0
- package/tsconfig.json +14 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Pipeworx
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# mcp-linkedin_ads
|
|
2
|
+
|
|
3
|
+
LinkedIn Ads MCP Pack
|
|
4
|
+
|
|
5
|
+
Part of the [Pipeworx](https://pipeworx.io) open MCP gateway.
|
|
6
|
+
|
|
7
|
+
## Tools
|
|
8
|
+
|
|
9
|
+
| Tool | Description |
|
|
10
|
+
|------|-------------|
|
|
11
|
+
| `li_list_ad_accounts` | List LinkedIn ad accounts accessible by the authenticated user. |
|
|
12
|
+
| `li_list_campaigns` | List campaigns for a LinkedIn ad account. |
|
|
13
|
+
| `li_get_campaign` | Get details for a specific LinkedIn ad campaign. |
|
|
14
|
+
| `li_campaign_analytics` | Get analytics for one or more LinkedIn ad campaigns over a date range. |
|
|
15
|
+
| `li_list_creatives` | List creatives (ads) for a specific LinkedIn campaign. |
|
|
16
|
+
|
|
17
|
+
## Quick Start
|
|
18
|
+
|
|
19
|
+
Add to your MCP client config:
|
|
20
|
+
|
|
21
|
+
```json
|
|
22
|
+
{
|
|
23
|
+
"mcpServers": {
|
|
24
|
+
"linkedin_ads": {
|
|
25
|
+
"url": "https://gateway.pipeworx.io/linkedin_ads/mcp"
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Or use the CLI:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npx pipeworx use linkedin_ads
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## License
|
|
38
|
+
|
|
39
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@pipeworx/mcp-linkedin_ads",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "LinkedIn Ads MCP Pack",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "src/index.ts",
|
|
7
|
+
"types": "src/index.ts",
|
|
8
|
+
"keywords": ["mcp", "mcp-server", "model-context-protocol", "pipeworx", "linkedin_ads"],
|
|
9
|
+
"license": "MIT",
|
|
10
|
+
"repository": {
|
|
11
|
+
"type": "git",
|
|
12
|
+
"url": "https://github.com/pipeworx-io/mcp-linkedin_ads"
|
|
13
|
+
},
|
|
14
|
+
"scripts": {
|
|
15
|
+
"typecheck": "tsc --noEmit"
|
|
16
|
+
},
|
|
17
|
+
"devDependencies": {
|
|
18
|
+
"typescript": "^5.7.0"
|
|
19
|
+
}
|
|
20
|
+
}
|
package/server.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json",
|
|
3
|
+
"name": "io.github.pipeworx-io/linkedin_ads",
|
|
4
|
+
"title": "linkedin_ads",
|
|
5
|
+
"description": "LinkedIn Ads MCP Pack",
|
|
6
|
+
"version": "0.1.0",
|
|
7
|
+
"websiteUrl": "https://pipeworx.io/packs/linkedin_ads",
|
|
8
|
+
"repository": {
|
|
9
|
+
"url": "https://github.com/pipeworx-io/mcp-linkedin_ads",
|
|
10
|
+
"source": "github"
|
|
11
|
+
},
|
|
12
|
+
"remotes": [
|
|
13
|
+
{
|
|
14
|
+
"type": "streamable-http",
|
|
15
|
+
"url": "https://gateway.pipeworx.io/linkedin_ads/mcp"
|
|
16
|
+
}
|
|
17
|
+
]
|
|
18
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
interface McpToolDefinition {
|
|
2
|
+
name: string;
|
|
3
|
+
description: string;
|
|
4
|
+
inputSchema: {
|
|
5
|
+
type: 'object';
|
|
6
|
+
properties: Record<string, unknown>;
|
|
7
|
+
required?: string[];
|
|
8
|
+
};
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface McpToolExport {
|
|
12
|
+
tools: McpToolDefinition[];
|
|
13
|
+
callTool: (name: string, args: Record<string, unknown>) => Promise<unknown>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* LinkedIn Ads MCP Pack
|
|
18
|
+
*
|
|
19
|
+
* Requires OAuth connection — gateway injects credentials via _context.linkedin_ads.
|
|
20
|
+
* Uses the LinkedIn Marketing API (REST v2, LinkedIn-Version: 202404).
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
const API = 'https://api.linkedin.com/rest';
|
|
25
|
+
const LI_VERSION = '202404';
|
|
26
|
+
|
|
27
|
+
interface LinkedInAdsContext {
|
|
28
|
+
linkedin_ads?: { accessToken: string };
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function liFetch(ctx: LinkedInAdsContext, path: string, params: Record<string, string> = {}) {
|
|
32
|
+
if (!ctx.linkedin_ads) {
|
|
33
|
+
return { error: 'connection_required', message: 'Connect your LinkedIn Ads account at https://pipeworx.io/account' };
|
|
34
|
+
}
|
|
35
|
+
const { accessToken } = ctx.linkedin_ads;
|
|
36
|
+
const qs = new URLSearchParams(params);
|
|
37
|
+
const url = Object.keys(params).length > 0 ? `${API}${path}?${qs}` : `${API}${path}`;
|
|
38
|
+
const res = await fetch(url, {
|
|
39
|
+
headers: {
|
|
40
|
+
Authorization: `Bearer ${accessToken}`,
|
|
41
|
+
'LinkedIn-Version': LI_VERSION,
|
|
42
|
+
'X-Restli-Protocol-Version': '2.0.0',
|
|
43
|
+
},
|
|
44
|
+
});
|
|
45
|
+
if (!res.ok) {
|
|
46
|
+
const text = await res.text();
|
|
47
|
+
throw new Error(`LinkedIn Ads API error (${res.status}): ${text}`);
|
|
48
|
+
}
|
|
49
|
+
return res.json();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const tools: McpToolExport['tools'] = [
|
|
53
|
+
{
|
|
54
|
+
name: 'li_list_ad_accounts',
|
|
55
|
+
description: 'List LinkedIn ad accounts accessible by the authenticated user.',
|
|
56
|
+
inputSchema: {
|
|
57
|
+
type: 'object' as const,
|
|
58
|
+
properties: {
|
|
59
|
+
count: { type: 'number', description: 'Max results (default 10)' },
|
|
60
|
+
start: { type: 'number', description: 'Pagination offset (default 0)' },
|
|
61
|
+
},
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
{
|
|
65
|
+
name: 'li_list_campaigns',
|
|
66
|
+
description: 'List campaigns for a LinkedIn ad account.',
|
|
67
|
+
inputSchema: {
|
|
68
|
+
type: 'object' as const,
|
|
69
|
+
properties: {
|
|
70
|
+
account_id: { type: 'string', description: 'Sponsored account ID (numeric, e.g., "508127070")' },
|
|
71
|
+
count: { type: 'number', description: 'Max results (default 10)' },
|
|
72
|
+
start: { type: 'number', description: 'Pagination offset (default 0)' },
|
|
73
|
+
},
|
|
74
|
+
required: ['account_id'],
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
{
|
|
78
|
+
name: 'li_get_campaign',
|
|
79
|
+
description: 'Get details for a specific LinkedIn ad campaign.',
|
|
80
|
+
inputSchema: {
|
|
81
|
+
type: 'object' as const,
|
|
82
|
+
properties: {
|
|
83
|
+
campaign_id: { type: 'string', description: 'Campaign ID' },
|
|
84
|
+
},
|
|
85
|
+
required: ['campaign_id'],
|
|
86
|
+
},
|
|
87
|
+
},
|
|
88
|
+
{
|
|
89
|
+
name: 'li_campaign_analytics',
|
|
90
|
+
description: 'Get analytics for one or more LinkedIn ad campaigns over a date range.',
|
|
91
|
+
inputSchema: {
|
|
92
|
+
type: 'object' as const,
|
|
93
|
+
properties: {
|
|
94
|
+
campaign_ids: {
|
|
95
|
+
type: 'array',
|
|
96
|
+
items: { type: 'string' },
|
|
97
|
+
description: 'Array of campaign IDs to query',
|
|
98
|
+
},
|
|
99
|
+
date_range_start: { type: 'string', description: 'Start date (YYYY-MM-DD)' },
|
|
100
|
+
date_range_end: { type: 'string', description: 'End date (YYYY-MM-DD)' },
|
|
101
|
+
time_granularity: { type: 'string', description: 'Granularity: DAILY, MONTHLY, or ALL (default ALL)' },
|
|
102
|
+
},
|
|
103
|
+
required: ['campaign_ids', 'date_range_start', 'date_range_end'],
|
|
104
|
+
},
|
|
105
|
+
},
|
|
106
|
+
{
|
|
107
|
+
name: 'li_list_creatives',
|
|
108
|
+
description: 'List creatives (ads) for a specific LinkedIn campaign.',
|
|
109
|
+
inputSchema: {
|
|
110
|
+
type: 'object' as const,
|
|
111
|
+
properties: {
|
|
112
|
+
campaign_id: { type: 'string', description: 'Campaign ID' },
|
|
113
|
+
count: { type: 'number', description: 'Max results (default 10)' },
|
|
114
|
+
start: { type: 'number', description: 'Pagination offset (default 0)' },
|
|
115
|
+
},
|
|
116
|
+
required: ['campaign_id'],
|
|
117
|
+
},
|
|
118
|
+
},
|
|
119
|
+
];
|
|
120
|
+
|
|
121
|
+
async function callTool(name: string, args: Record<string, unknown>): Promise<unknown> {
|
|
122
|
+
const context = (args._context ?? {}) as LinkedInAdsContext;
|
|
123
|
+
delete args._context;
|
|
124
|
+
|
|
125
|
+
switch (name) {
|
|
126
|
+
case 'li_list_ad_accounts': {
|
|
127
|
+
const count = String((args.count as number) ?? 10);
|
|
128
|
+
const start = String((args.start as number) ?? 0);
|
|
129
|
+
return liFetch(context, '/adAccounts', { q: 'search', count, start });
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
case 'li_list_campaigns': {
|
|
133
|
+
const accountId = args.account_id as string;
|
|
134
|
+
const count = String((args.count as number) ?? 10);
|
|
135
|
+
const start = String((args.start as number) ?? 0);
|
|
136
|
+
return liFetch(context, '/adCampaigns', {
|
|
137
|
+
q: 'search',
|
|
138
|
+
'search.account.values[0]': `urn:li:sponsoredAccount:${accountId}`,
|
|
139
|
+
count,
|
|
140
|
+
start,
|
|
141
|
+
});
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
case 'li_get_campaign': {
|
|
145
|
+
const campaignId = args.campaign_id as string;
|
|
146
|
+
return liFetch(context, `/adCampaigns/${campaignId}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
case 'li_campaign_analytics': {
|
|
150
|
+
const campaignIds = args.campaign_ids as string[];
|
|
151
|
+
const startDate = args.date_range_start as string;
|
|
152
|
+
const endDate = args.date_range_end as string;
|
|
153
|
+
const granularity = (args.time_granularity as string) ?? 'ALL';
|
|
154
|
+
|
|
155
|
+
const [startYear, startMonth, startDay] = startDate.split('-');
|
|
156
|
+
const [endYear, endMonth, endDay] = endDate.split('-');
|
|
157
|
+
|
|
158
|
+
const params: Record<string, string> = {
|
|
159
|
+
q: 'analytics',
|
|
160
|
+
pivot: 'CAMPAIGN',
|
|
161
|
+
timeGranularity: granularity,
|
|
162
|
+
'dateRange.start.year': startYear,
|
|
163
|
+
'dateRange.start.month': startMonth,
|
|
164
|
+
'dateRange.start.day': startDay,
|
|
165
|
+
'dateRange.end.year': endYear,
|
|
166
|
+
'dateRange.end.month': endMonth,
|
|
167
|
+
'dateRange.end.day': endDay,
|
|
168
|
+
};
|
|
169
|
+
|
|
170
|
+
campaignIds.forEach((id, i) => {
|
|
171
|
+
params[`campaigns[${i}]`] = `urn:li:sponsoredCampaign:${id}`;
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
return liFetch(context, '/adAnalytics', params);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
case 'li_list_creatives': {
|
|
178
|
+
const campaignId = args.campaign_id as string;
|
|
179
|
+
const count = String((args.count as number) ?? 10);
|
|
180
|
+
const start = String((args.start as number) ?? 0);
|
|
181
|
+
return liFetch(context, '/adCreatives', {
|
|
182
|
+
q: 'search',
|
|
183
|
+
'search.campaign.values[0]': `urn:li:sponsoredCampaign:${campaignId}`,
|
|
184
|
+
count,
|
|
185
|
+
start,
|
|
186
|
+
});
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
default:
|
|
190
|
+
throw new Error(`Unknown tool: ${name}`);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
export default { tools, callTool, meter: { credits: 15 }, provider: 'linkedin_ads' } satisfies McpToolExport;
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES2022",
|
|
4
|
+
"module": "ESNext",
|
|
5
|
+
"moduleResolution": "bundler",
|
|
6
|
+
"strict": true,
|
|
7
|
+
"esModuleInterop": true,
|
|
8
|
+
"skipLibCheck": true,
|
|
9
|
+
"outDir": "dist",
|
|
10
|
+
"rootDir": "src",
|
|
11
|
+
"declaration": true
|
|
12
|
+
},
|
|
13
|
+
"include": ["src"]
|
|
14
|
+
}
|