li_get_campaign
Retrieve complete campaign details including targeting criteria, bid strategy, budget, and schedule to audit targeting setup, diagnose budget configuration, or confirm campaign structure.
Instructions
Get complete detail for a single LinkedIn campaign, including the full targetingCriteria object (all included/excluded facets), bid strategy, unit cost, daily/total budget, run schedule, objective, optimization target, format, and locale. Use this when you need to audit targeting setup, diagnose budget configuration, or confirm campaign structure before pulling performance data.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| campaign_id | Yes | Campaign numeric ID or URN (urn:li:sponsoredCampaign:123). Required. | |
| ad_account_id | No | Ad account numeric ID or URN. Defaults to LINKEDIN_DEFAULT_AD_ACCOUNT. |
Implementation Reference
- src/tools/campaigns.ts:80-85 (handler)The actual handler function for li_get_campaign. It resolves the ad account, unwraps the campaign URN, and performs a GET request to the LinkedIn API endpoint /adAccounts/{accountId}/adCampaigns/{campaignId}.
export async function getCampaign(args: { campaign_id: string; ad_account_id?: string }) { const account = resolveAdAccount(args.ad_account_id); const accountId = unwrapURN(account); const campaignId = unwrapURN(urn("sponsoredCampaign", args.campaign_id)); return liGet(`/adAccounts/${accountId}/adCampaigns/${campaignId}`); } - src/tools/campaigns.ts:70-78 (schema)Zod schema for li_get_campaign input validation. Requires campaign_id (string) and optionally ad_account_id (string) which defaults to LINKEDIN_DEFAULT_AD_ACCOUNT.
export const getCampaignSchema = { campaign_id: z .string() .describe("Campaign numeric ID or URN (urn:li:sponsoredCampaign:123). Required."), ad_account_id: z .string() .optional() .describe("Ad account numeric ID or URN. Defaults to LINKEDIN_DEFAULT_AD_ACCOUNT."), }; - src/index.ts:81-86 (registration)Registration of the 'li_get_campaign' tool on the MCP server, binding the schema and handler function.
server.tool( "li_get_campaign", "Get complete detail for a single LinkedIn campaign, including the full targetingCriteria object (all included/excluded facets), bid strategy, unit cost, daily/total budget, run schedule, objective, optimization target, format, and locale. Use this when you need to audit targeting setup, diagnose budget configuration, or confirm campaign structure before pulling performance data.", getCampaignSchema, async (args) => { try { return ok(await getCampaign(args)); } catch (e) { return err(e); } } ); - src/client.ts:71-76 (helper)The urn() helper function used by getCampaign to wrap a bare ID into a LinkedIn URN.
/** Wrap a bare ID in a LinkedIn URN. Idempotent — already-URN inputs pass through. */ export function urn(type: URNType, id: string | number): string { const s = String(id).trim(); if (s.startsWith("urn:li:")) return s; return `urn:li:${type}:${s}`; } - src/client.ts:79-82 (helper)The unwrapURN() helper function used by getCampaign to extract the numeric ID from a URN.
export function unwrapURN(u: string): string { const parts = u.split(":"); return parts[parts.length - 1] ?? u; }