meta_exchange_token
Exchange a short-lived access token for a long-lived token valid for about 60 days. Requires Meta App ID and App Secret to extend token lifespan.
Instructions
Exchange a short-lived token for a long-lived token (valid ~60 days). Requires META_APP_ID and META_APP_SECRET.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| short_lived_token | Yes | Short-lived access token to exchange |
Implementation Reference
- src/tools/meta/auth.ts:7-21 (handler)Handler function that defines the meta_exchange_token tool. Calls client.exchangeToken() with the short_lived_token input and returns the result as JSON.
server.tool( "meta_exchange_token", "Exchange a short-lived token for a long-lived token (valid ~60 days). Requires META_APP_ID and META_APP_SECRET.", { short_lived_token: z.string().describe("Short-lived access token to exchange"), }, async ({ short_lived_token }) => { try { const { data, rateLimit } = await client.exchangeToken(short_lived_token); return { content: [{ type: "text", text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text", text: `Token exchange failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/tools/meta/auth.ts:10-12 (schema)Zod schema definition for the meta_exchange_token tool input: requires a short_lived_token string.
{ short_lived_token: z.string().describe("Short-lived access token to exchange"), }, - src/services/meta-client.ts:111-121 (helper)Helper method MetaClient.exchangeToken() that makes the actual HTTP GET request to Facebook's /oauth/access_token endpoint with grant_type=fb_exchange_token to exchange a short-lived token for a long-lived one.
async exchangeToken(shortToken: string): Promise<ClientResponse> { if (!this.config.appId || !this.config.appSecret) { throw new Error("META_APP_ID and META_APP_SECRET are required for token exchange."); } return this.request(IG_BASE, shortToken, "GET", "/oauth/access_token", { grant_type: "fb_exchange_token", client_id: this.config.appId, client_secret: this.config.appSecret, fb_exchange_token: shortToken, }); } - src/index.ts:41-41 (registration)Registration call: registerMetaAuthTools(server, client) registers all Meta auth tools including meta_exchange_token on the MCP server.
registerMetaAuthTools(server, client); - src/tools/meta/auth.ts:5-5 (registration)Export function registerMetaAuthTools that registers all Meta auth tools (including meta_exchange_token) onto the McpServer instance.
export function registerMetaAuthTools(server: McpServer, client: MetaClient): void {