Skip to main content
Glama
localseodata

Local SEO Data

Official

ai_top_pages

Read-only

Retrieve specific pages cited by AI models for a keyword, providing granular insights beyond domain-level data to refine local SEO strategies.

Instructions

Get the top pages (not just domains) cited by AI models for a keyword. More granular than top_sources. Costs 5 credits.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYesKeyword to search for (e.g. "best dentist")
locationNoLocation for results (e.g. "Chicago, IL"). Default: US
platformsNoPlatforms to query. Default: all
limitNoMax pages. Default: 10, max: 50

Implementation Reference

  • src/server.ts:13-13 (registration)
    Import of registerAIVisibilityTools function, which registers the ai_top_pages tool among others.
    import { registerAIVisibilityTools } from "./tools/ai-visibility.js";
  • src/server.ts:45-45 (registration)
    Invocation of registerAIVisibilityTools to register all AI visibility tools including ai_top_pages on the MCP server.
    registerAIVisibilityTools(server, getAuth);
  • The ai_top_pages tool definition and handler. Calls GET /v1/ai/top-pages API with keyword, location, platforms, and limit parameters. Returns formatted JSON result.
    server.tool(
      "ai_top_pages",
      "Get the top pages (not just domains) cited by AI models for a keyword. More granular than top_sources. Costs 5 credits.",
      {
        keyword: z.string().min(1).describe('Keyword to search for (e.g. "best dentist")'),
        location: z.string().optional().describe('Location for results (e.g. "Chicago, IL"). Default: US'),
        platforms: z.array(z.enum(["chat_gpt", "google"])).optional().describe("Platforms to query. Default: all"),
        limit: z.number().int().min(1).max(50).optional().describe("Max pages. Default: 10, max: 50"),
      },
      READ_ONLY,
      withErrorHandling(async ({ keyword, location, platforms, limit }) => {
        const result = await callApi(
          "/v1/ai/top-pages",
          { keyword, ...(location && { location }), ...(platforms && { platforms }), ...(limit && { limit }) },
          getAuth()
        );
        return { content: [{ type: "text" as const, text: formatResult(result.data, result) }] };
      })
    );
  • Schema definition for ai_top_pages tool inputs: keyword (required string), location, platforms (array of chat_gpt/google), and limit (1-50).
    {
      keyword: z.string().min(1).describe('Keyword to search for (e.g. "best dentist")'),
      location: z.string().optional().describe('Location for results (e.g. "Chicago, IL"). Default: US'),
      platforms: z.array(z.enum(["chat_gpt", "google"])).optional().describe("Platforms to query. Default: all"),
      limit: z.number().int().min(1).max(50).optional().describe("Max pages. Default: 10, max: 50"),
    },
  • The callApi helper function that makes the actual POST request to the API endpoint. Used by the ai_top_pages handler to call /v1/ai/top-pages.
    export async function callApi(
      path: string,
      body: Record<string, unknown>,
      authHeader: string,
      timeoutMs = 60_000
    ): Promise<{ data: unknown; credits_used: number; credits_remaining: number; cached: boolean }> {
      const url = `${env.API_BASE_URL}${path}`;
    
      console.log(`[api] POST ${url} (timeout: ${timeoutMs / 1000}s, auth: ${authHeader ? `${authHeader.slice(0, 15)}...` : "MISSING"})`);
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: authHeader,
        },
        body: JSON.stringify(body),
        signal: AbortSignal.timeout(timeoutMs),
      });
    
      if (!response.ok) {
        const text = await response.text();
        console.error(`[api] ${response.status} ${response.statusText} from ${path}: ${text.slice(0, 200)}`);
        // Try to parse as structured error
        try {
          const result = JSON.parse(text) as ApiErrorResponse;
          if (result.status === "error") {
            const err = result.error;
            const reqId = result.request_id ? ` [request_id: ${result.request_id}]` : "";
            throw new Error(
              err.required_credits
                ? `${err.message} (requires ${err.required_credits} credits, balance: ${err.current_balance})${reqId}`
                : `${err.message}${reqId}`
            );
          }
        } catch (parseErr) {
          if (parseErr instanceof Error && parseErr.message !== "error") {
            // Re-throw if it's our structured error from above
            if (!text.includes('"status":"error"')) {
              throw new Error(`API returned ${response.status}: ${text.slice(0, 200)}`);
            }
            throw parseErr;
          }
        }
        throw new Error(`API returned ${response.status}: ${text.slice(0, 200)}`);
      }
    
      const result = (await response.json()) as ApiResponse;
    
      if (result.status === "error") {
        const err = (result as ApiErrorResponse).error;
        const reqId = (result as ApiErrorResponse).request_id ? ` [request_id: ${(result as ApiErrorResponse).request_id}]` : "";
        throw new Error(
          err.required_credits
            ? `${err.message} (requires ${err.required_credits} credits, balance: ${err.current_balance})${reqId}`
            : `${err.message}${reqId}`
        );
      }
    
      console.log(`[api] ${path} OK (${result.credits_used} credits used, ${result.credits_remaining} remaining)`);
    
      return {
        data: result.data,
        credits_used: result.credits_used,
        credits_remaining: result.credits_remaining,
        cached: result.cached,
      };
    }
Behavior4/5

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

Annotations already provide readOnlyHint, destructiveHint, openWorldHint. The description adds a specific cost of 5 credits, which is valuable behavioral info beyond annotations. No contradiction.

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?

Two concise sentences with no fluff. Front-loaded with the core action and differentiation.

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

Completeness4/5

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

Given no output schema, description provides enough context: purpose, differentiation, cost. Annotations cover safety. Could mention pagination or response format, but not critical.

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%, so baseline is 3. Description adds context about the tool's purpose but does not elaborate on parameter meanings beyond what the schema already 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?

Clearly states it gets top pages (not just domains) for a keyword, and distinguishes itself from sibling tool 'top_sources' by specifying higher granularity. The verb 'Get' and resource 'top pages' are specific.

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?

Explains when to use (when pages are needed over domains) and references a more general alternative (top_sources). However, does not explicitly state when NOT to use or list other alternatives.

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/localseodata/mcp-server'

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