search_locations
Search for countries, regions, cities, and zip codes to use as ad targeting locations. Filter results by location type and limit the number of returns.
Instructions
Search for geographic locations (countries, regions, cities, zip codes) for ad targeting.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| q | Yes | Search query (e.g. 'New York', 'California', 'United States') | |
| location_types | No | Comma-separated location types: country, region, city, zip, geo_market, electoral_district | |
| limit | No | Number of results (default 25) |
Implementation Reference
- src/tools/targeting.ts:29-48 (handler)The handler function for the 'search_locations' tool. It accepts 'q' (search query), optional 'location_types', and optional 'limit', then calls the Meta API endpoint '/search' with type 'adgeolocation' to find geographic locations for ad targeting. Returns the results with rate limit info.
server.tool( "search_locations", "Search for geographic locations (countries, regions, cities, zip codes) for ad targeting.", { q: z.string().describe("Search query (e.g. 'New York', 'California', 'United States')"), location_types: z.string().optional().describe("Comma-separated location types: country, region, city, zip, geo_market, electoral_district"), limit: z.number().optional().default(25).describe("Number of results (default 25)"), }, async ({ q, location_types, limit }) => { try { const params: Record<string, unknown> = { q, type: "adgeolocation" }; if (location_types) params.location_types = location_types; if (limit) params.limit = limit; const { data, rateLimit } = await client.get(`/search`, params); return { content: [{ type: "text" as const, text: JSON.stringify({ ...data as object, _rateLimit: rateLimit }, null, 2) }] }; } catch (error) { return { content: [{ type: "text" as const, text: `Failed: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } ); - src/tools/targeting.ts:32-36 (schema)Zod schema definitions for the 'search_locations' tool inputs: 'q' (string, required), 'location_types' (string, optional, comma-separated types), 'limit' (number, optional, default 25).
{ q: z.string().describe("Search query (e.g. 'New York', 'California', 'United States')"), location_types: z.string().optional().describe("Comma-separated location types: country, region, city, zip, geo_market, electoral_district"), limit: z.number().optional().default(25).describe("Number of results (default 25)"), }, - src/tools/targeting.ts:29-34 (registration)Registration of the 'search_locations' tool via server.tool() inside registerTargetingTools(). Also the function registerTargetingTools is exported and called from src/index.ts at line 62.
server.tool( "search_locations", "Search for geographic locations (countries, regions, cities, zip codes) for ad targeting.", { q: z.string().describe("Search query (e.g. 'New York', 'California', 'United States')"), location_types: z.string().optional().describe("Comma-separated location types: country, region, city, zip, geo_market, electoral_district"),