li_list_campaigns
List LinkedIn ad campaigns with details on status, objective, budget, and targeting. Filter by status or campaign group to streamline campaign management.
Instructions
List campaigns in a LinkedIn ad account. Returns campaign name, status, objectiveType (WEBSITE_VISITS/LEAD_GENERATION/BRAND_AWARENESS/etc.), optimizationTargetType, bid amount, daily/total budget, run schedule, and targeting criteria summary. Filter by status or campaign_group_id. Use li_get_campaign for full targeting detail on a specific campaign.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ad_account_id | No | Ad account numeric ID or URN. Defaults to LINKEDIN_DEFAULT_AD_ACCOUNT. | |
| status | No | Filter by campaign status. Omit to return campaigns in all statuses. | |
| campaign_group_id | No | Filter to campaigns belonging to a specific campaign group (numeric ID or URN). | |
| page_size | No |
Implementation Reference
- src/index.ts:74-79 (registration)Registration of the li_list_campaigns MCP tool. Maps the tool name to listCampaignsSchema and the listCampaigns handler function.
server.tool( "li_list_campaigns", "List campaigns in a LinkedIn ad account. Returns campaign name, status, objectiveType (WEBSITE_VISITS/LEAD_GENERATION/BRAND_AWARENESS/etc.), optimizationTargetType, bid amount, daily/total budget, run schedule, and targeting criteria summary. Filter by status or campaign_group_id. Use li_get_campaign for full targeting detail on a specific campaign.", listCampaignsSchema, async (args) => { try { return ok(await listCampaigns(args)); } catch (e) { return err(e); } } ); - src/tools/campaigns.ts:42-66 (handler)The listCampaigns handler function. Resolves the ad account, builds query params with optional status and campaign_group_id filters, and calls the LinkedIn API GET /adAccounts/{accountId}/adCampaigns endpoint.
export async function listCampaigns(args: { ad_account_id?: string; status?: string; campaign_group_id?: string; page_size?: number; }) { const account = resolveAdAccount(args.ad_account_id); const accountId = unwrapURN(account); const params: Record<string, string | number> = { q: "search", pageSize: args.page_size ?? 50, }; const criteria: string[] = []; if (args.status) { criteria.push(`status:(values:List(${args.status}))`); } if (args.campaign_group_id) { const groupUrn = urn("sponsoredCampaignGroup", args.campaign_group_id); criteria.push(`campaignGroup:(values:List(${groupUrn}))`); } if (criteria.length > 0) { params["search"] = `(${criteria.join(",")})`; } return liGet(`/adAccounts/${accountId}/adCampaigns`, params); } - src/tools/campaigns.ts:26-40 (schema)Zod schema for li_list_campaigns input validation. Defines optional ad_account_id, status (enum), campaign_group_id, and page_size (default 50) parameters.
export const listCampaignsSchema = { ad_account_id: z .string() .optional() .describe("Ad account numeric ID or URN. Defaults to LINKEDIN_DEFAULT_AD_ACCOUNT."), status: z .enum(CAMPAIGN_STATUSES) .optional() .describe("Filter by campaign status. Omit to return campaigns in all statuses."), campaign_group_id: z .string() .optional() .describe("Filter to campaigns belonging to a specific campaign group (numeric ID or URN)."), page_size: z.number().int().min(1).max(100).default(50), }; - src/client.ts:39-50 (helper)The liGet helper function used by listCampaigns to perform the HTTP GET request to LinkedIn's REST API.
export async function liGet<T = unknown>( path: string, query?: Record<string, string | number | boolean | undefined> ): Promise<T> { const url = new URL(BASE_URL + path); if (query) { for (const [k, v] of Object.entries(query)) { if (v !== undefined && v !== null) url.searchParams.set(k, String(v)); } } return liFetch<T>("GET", url.toString()); } - src/client.ts:84-93 (helper)The resolveAdAccount helper used by listCampaigns to resolve the ad account ID from argument or environment variable.
/** Resolve an ad account from arg override or LINKEDIN_DEFAULT_AD_ACCOUNT env. Returns full URN. */ export function resolveAdAccount(override?: string): string { const v = (override ?? process.env.LINKEDIN_DEFAULT_AD_ACCOUNT ?? "").trim(); if (!v) { throw new LinkedInError( "No ad account provided. Pass ad_account_id or set LINKEDIN_DEFAULT_AD_ACCOUNT in .env." ); } return urn("sponsoredAccount", v); }