refresh_token
Refresh a long-lived access token to extend its expiration. Returns a new long-lived token.
Instructions
Refresh a long-lived access token to extend its expiration. Returns a new long-lived token.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| long_lived_token | Yes | Long-lived access token to refresh |
Implementation Reference
- src/index.ts:93-93 (registration)Registration call: registerAuthTools wires refresh_token tool into the MCP server
registerAuthTools(server, client); - src/tools/auth.ts:23-38 (handler)The MCP tool handler for 'refresh_token' - receives long_lived_token, calls client.refreshToken, returns the result
// ─── refresh_token ──────────────────────────────────────────── server.tool( "refresh_token", "Refresh a long-lived access token to extend its expiration. Returns a new long-lived token.", { long_lived_token: z.string().describe("Long-lived access token to refresh"), }, async ({ long_lived_token }) => { try { const { data } = await client.refreshToken(long_lived_token); return { content: [{ type: "text" as const, text: JSON.stringify(data, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/tools/auth.ts:27-29 (schema)Input schema for refresh_token: requires long_lived_token (string)
{ long_lived_token: z.string().describe("Long-lived access token to refresh"), }, - src/services/ads-client.ts:274-293 (helper)AdsClient.refreshToken method - calls Facebook Graph API /oauth/access_token with grant_type=fb_exchange_token
/** Refresh a long-lived token */ async refreshToken(longToken: string): Promise<ClientResponse> { const qs = new URLSearchParams({ grant_type: "fb_exchange_token", access_token: longToken, }); const url = `${this.baseUrl}/oauth/access_token?${qs.toString()}`; const res = await fetch(url, { signal: AbortSignal.timeout(30_000) }); if (!res.ok) { const text = await res.text().catch(() => ""); throw new Error(`Token refresh failed (${res.status}): ${text}`); } const data = await res.json(); if (data.error) { throw new Error(this.formatError(data)); } return { data }; }