Skip to main content
Glama
patchwindow

seo-mcp

by patchwindow

gsc_search_performance

Retrieve Google Search Console search performance data with clicks, impressions, CTR, and position. Filter by query, page, device, or country, and group by multiple dimensions.

Instructions

Query Google Search Console search performance data. Returns clicks, impressions, CTR, and position for a site. Supports filtering by query, page, device, or country and grouping by multiple dimensions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
site_urlNoSite URL in GSC format, e.g. 'sc-domain:example.com' or 'https://example.com/'. Uses config default if omitted.
start_dateYesStart date in YYYY-MM-DD format.
end_dateYesEnd date in YYYY-MM-DD format.
dimensionsNoDimensions to group results by. Default: ['query'].
filter_queryNoFilter results to queries containing this string.
filter_pageNoFilter results to this page URL (exact match).
filter_deviceNoFilter results to this device type.
filter_countryNoFilter results to this country (ISO 3166-1 alpha-3, e.g. 'USA').
row_limitNoMax rows to return. Default 100, max 25000.

Implementation Reference

  • Zod schema for gsc_search_performance tool, defining all input parameters: site_url, start_date, end_date, dimensions, filter_*, and row_limit.
    const schema = z.object({
      site_url: z.string().optional().describe(
        "Site URL in GSC format, e.g. 'sc-domain:example.com' or 'https://example.com/'. Uses config default if omitted."
      ),
      start_date: z.string().describe("Start date in YYYY-MM-DD format."),
      end_date: z.string().describe("End date in YYYY-MM-DD format."),
      dimensions: z
        .array(z.enum(["query", "page", "country", "device", "date"]))
        .optional()
        .describe("Dimensions to group results by. Default: ['query']."),
      filter_query: z.string().optional().describe("Filter results to queries containing this string."),
      filter_page: z.string().optional().describe("Filter results to this page URL (exact match)."),
      filter_device: z
        .enum(["DESKTOP", "MOBILE", "TABLET"])
        .optional()
        .describe("Filter results to this device type."),
      filter_country: z
        .string()
        .optional()
        .describe("Filter results to this country (ISO 3166-1 alpha-3, e.g. 'USA')."),
      row_limit: z.number().optional().describe("Max rows to return. Default 100, max 25000."),
    });
  • Full tool definition including name, description, schema, and handler. The handler authenticates via GSC OAuth2, calls the Search Analytics query API, applies filters, and returns tab-separated results.
    export const gscSearchPerformance: ToolDefinition<typeof schema> = {
      name: "gsc_search_performance",
      description:
        "Query Google Search Console search performance data. Returns clicks, impressions, CTR, and position for a site. Supports filtering by query, page, device, or country and grouping by multiple dimensions.",
      schema,
      handler: async (args, config) => {
        const auth = getOAuth2Client();
        const sc = google.searchconsole({ version: "v1", auth });
    
        const siteUrl = args.site_url ?? config.gsc?.default_site;
        if (!siteUrl) {
          throw new Error(
            "site_url is required. Pass it as an argument or set gsc.default_site in ~/.seo-mcp/config.json"
          );
        }
    
        const dimensions = args.dimensions ?? ["query"];
        const rowLimit = args.row_limit ?? 100;
    
        const filterGroups: Record<string, unknown>[] = [];
    
        if (args.filter_query) {
          filterGroups.push({ filters: [{ dimension: "query", operator: "contains", expression: args.filter_query }] });
        }
        if (args.filter_page) {
          filterGroups.push({ filters: [{ dimension: "page", operator: "equals", expression: args.filter_page }] });
        }
        if (args.filter_device) {
          filterGroups.push({ filters: [{ dimension: "device", operator: "equals", expression: args.filter_device }] });
        }
        if (args.filter_country) {
          filterGroups.push({ filters: [{ dimension: "country", operator: "equals", expression: args.filter_country }] });
        }
    
        const res = await sc.searchanalytics.query({
          siteUrl,
          requestBody: {
            startDate: args.start_date,
            endDate: args.end_date,
            dimensions,
            rowLimit,
            dimensionFilterGroups: filterGroups.length > 0 ? filterGroups : undefined,
          },
        });
    
        const rows = res.data.rows ?? [];
        if (rows.length === 0) {
          return { content: [{ type: "text", text: "No data returned for the specified parameters." }] };
        }
    
        const header = [...dimensions, "clicks", "impressions", "ctr", "position"].join("\t");
        const lines = rows.map((r) => {
          const keys = (r.keys ?? []).join("\t");
          const ctr = ((r.ctr ?? 0) * 100).toFixed(2) + "%";
          const pos = r.position?.toFixed(1) ?? "—";
          return `${keys}\t${r.clicks ?? 0}\t${r.impressions ?? 0}\t${ctr}\t${pos}`;
        });
    
        return { content: [{ type: "text", text: [header, ...lines].join("\n") }] };
      },
    };
  • Imports and registers gscSearchPerformance in the gscTools array, making it available as a tool definition.
    import { gscSearchPerformance } from "./search-performance.js";
    import { gscStrikingDistance } from "./striking-distance.js";
    import { gscTrafficDrop } from "./traffic-drop.js";
    import { gscUrlInspection } from "./url-inspection.js";
    import { gscSitemapList } from "./sitemap-list.js";
    import { gscBrandNonbrand } from "./brand-nonbrand.js";
    import type { ToolDefinition } from "../../types/tool.js";
    
    export const gscTools: ToolDefinition[] = [
      gscSearchPerformance as unknown as ToolDefinition,
      gscStrikingDistance as unknown as ToolDefinition,
      gscTrafficDrop as unknown as ToolDefinition,
      gscUrlInspection as unknown as ToolDefinition,
      gscSitemapList as unknown as ToolDefinition,
      gscBrandNonbrand as unknown as ToolDefinition,
    ];
  • getOAuth2Client helper used by the handler to authenticate with Google Search Console API.
    export function getOAuth2Client() {
      const clientId = process.env.GSC_CLIENT_ID;
      const clientSecret = process.env.GSC_CLIENT_SECRET;
    
      if (!clientId || !clientSecret) {
        throw new Error(
          "GSC_CLIENT_ID and GSC_CLIENT_SECRET must be set.\n" +
          "Run: npx @patchwindow/seo-mcp auth gsc\n" +
          "See README for Google Cloud Console setup instructions."
        );
      }
    
      const oauth2 = new google.auth.OAuth2(clientId, clientSecret, GSC_REDIRECT_URI);
    
      const tokens = readTokens();
      if (!tokens) {
        throw new Error(
          "GSC not authenticated. Run: npx @patchwindow/seo-mcp auth gsc"
        );
      }
    
      oauth2.setCredentials(tokens);
      oauth2.on("tokens", (newTokens) => {
        writeTokens({ ...tokens, ...newTokens });
      });
    
      return oauth2;
    }
  • ToolDefinition type that provides the interface contract for the tool definition, ensuring it has name, description, schema, and handler.
    export interface ToolDefinition<T extends AnyZodObject = AnyZodObject> {
      name: string;
      description: string;
      schema: T;
      handler: (args: z.infer<T>, config: Config) => Promise<ToolResult>;
    }
Behavior2/5

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

With no annotations, the description must fully disclose behavior. It states the tool returns data and supports filtering/grouping, but omits details like read-only nature, rate limits, aggregation behavior (daily vs. total), pagination, or data latency. These gaps are significant for a data query tool.

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 long, front-loaded with the action and resource. Every sentence adds value with no fluff. Efficient and well-structured.

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

Completeness2/5

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

Given the tool has 9 parameters and no output schema or annotations, the description lacks essential context such as default dimension, behavior when multiple dimensions are combined, row limit impact, and how the date range is sampled (daily vs. aggregated). More detail is needed for effective use.

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. The description adds context about return values and operations (e.g., 'Returns clicks, impressions, CTR, and position'), but this information is not critical for parameter usage and doesn't significantly enhance understanding beyond the schema.

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

Purpose4/5

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

The description clearly states the tool queries GSC search performance data and lists return fields (clicks, impressions, CTR, position). It mentions filtering and grouping, which distinguishes it from siblings like gsc_brand_nonbrand or gsc_striking_distance, but lacks explicit differentiation.

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

Usage Guidelines2/5

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

The description does not provide guidance on when to use this tool versus alternatives, such as gsc_traffic_drop or gsc_brand_nonbrand. No prerequisites or typical scenarios are mentioned.

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/patchwindow/seo-mcp'

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