Skip to main content
Glama

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

TableJSON Schema
NameRequiredDescriptionDefault
long_lived_tokenYesLong-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);
  • 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 };
        }
      }
    );
  • Input schema for refresh_token: requires long_lived_token (string)
    {
      long_lived_token: z.string().describe("Long-lived access token to refresh"),
    },
  • 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 };
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description must carry the full burden. It mentions returning a new token but does not disclose whether the old token is invalidated, rate limits, or authentication requirements.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is two sentences, front-loads the action, and contains no unnecessary words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a simple token refresh tool with one parameter, the description is adequate but lacks behavioral details that would make it fully complete for an agent, especially given no annotations or output schema.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% and the parameter description in the schema already states 'Long-lived access token'. The description adds no new meaning beyond what the schema provides.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool refreshes a long-lived access token to extend its expiration, which is a specific verb+resource. It distinguishes from sibling tools like exchange_token and debug_token.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies the tool is used to extend token expiration, providing clear context. However, it does not explicitly state when not to use it (e.g., for short-lived tokens) or compare to alternatives like exchange_token.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mikusnuz/meta-ads-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server