Skip to main content
Glama

Google Ads MCP Server

by seovimalraj
googleAutocomplete.ts1.43 kB
import { fetchAutocompleteSuggestions } from '@/lib/search'; export interface FetchAutocompleteOptions { depth?: number; branchFactor?: number; signal?: AbortSignal; } export async function fetchAutocomplete( query: string, depth = 1, options: FetchAutocompleteOptions = {}, ): Promise<string[]> { const maxDepth = Math.max(1, depth); const branchFactor = Math.max(1, options.branchFactor ?? 5); const visited = new Set<string>(); const queue: Array<{ term: string; depth: number }> = [{ term: query, depth: 0 }]; const collected = new Set<string>(); while (queue.length > 0) { if (options.signal?.aborted) { break; } const current = queue.shift(); if (!current) { break; } if (current.depth >= maxDepth) { continue; } const { term } = current; if (visited.has(term)) { continue; } visited.add(term); const { suggestions } = await fetchAutocompleteSuggestions(term); for (const suggestion of suggestions) { if (!collected.has(suggestion)) { collected.add(suggestion); } } const nextDepth = current.depth + 1; if (nextDepth >= maxDepth) { continue; } const nextSeeds = suggestions.slice(0, branchFactor); for (const seed of nextSeeds) { if (!visited.has(seed)) { queue.push({ term: seed, depth: nextDepth }); } } } return Array.from(collected); }

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/seovimalraj/google-ads-mcp'

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