dataforseo-mcp-server
Version:
A Model Context Protocol (MCP) server for the DataForSEO API, enabling modular and extensible integration of DataForSEO endpoints with support for both HTTP and SSE transports.
85 lines (84 loc) • 3.99 kB
JavaScript
import { z } from 'zod';
import { BaseTool } from '../../../../base.tool.js';
export class GoogleTopSearchesTool extends BaseTool {
client;
constructor(client) {
super(client);
this.client = client;
}
getName() {
return 'dataforseo_labs_google_top_searches';
}
getDescription() {
return `The Top Searches endpoint of DataForSEO Labs API can provide you with over 7 billion keywords from the DataForSEO Keyword Database. Each keyword in the API response is provided with a set of relevant keyword data with Google Ads metrics`;
}
getParams() {
return {
location_name: z.string().default("United States").describe(`full name of the location
required field
in format "Country"
example:
United Kingdom`),
language_code: z.string().default("en").describe(`language code
required field
example:
en`),
limit: z.number().min(1).max(1000).default(10).optional().describe("Maximum number of keywords to return"),
offset: z.number().min(0).optional().describe(`offset in the results array of returned keywords
optional field
default value: 0
if you specify the 10 value, the first ten keywords in the results array will be omitted and the data will be provided for the successive keywords`),
filters: z.array(z.union([
z.array(z.union([z.string(), z.number(), z.boolean()])).length(3),
z.enum(["and", "or"])
])).max(8).optional().describe(`you can add several filters at once (8 filters maximum)
you should set a logical operator and, or between the conditions
the following operators are supported:
regex, not_regex, <, <=, >, >=, =, <>, in, not_in, match, not_match, ilike, not_ilike, like, not_like
you can use the % operator with like and not_like, as well as ilike and not_ilike to match any string of zero or more characters
merge operator must be a string and connect two other arrays, availible values: or, and.
example:
["keyword_info.search_volume",">",0]
[["keyword_info.search_volume","in",[0,1000]],
"and",
["keyword_info.competition_level","=","LOW"]][["keyword_info.search_volume",">",100],
"and",
[["keyword_info.cpc","<",0.5],
"or",
["keyword_info.high_top_of_page_bid","<=",0.5]]]`),
order_by: z.array(z.string()).optional().describe(`resuresults sorting rules
optional field
you can use the same values as in the filters array to sort the results
possible sorting types:
asc – results will be sorted in the ascending order
desc – results will be sorted in the descending order
you should use a comma to set up a sorting type
example:
["keyword_info.competition,desc"]
default rule:
["keyword_info.search_volume,desc"]
note that you can set no more than three sorting rules in a single request
you should use a comma to separate several sorting rules
example:
["keyword_info.search_volume,desc","keyword_info.cpc,desc"]`),
include_clickstream_data: z.boolean().optional().default(false).describe(`Include or exclude data from clickstream-based metrics in the result`)
};
}
async handle(params) {
try {
const response = await this.client.makeRequest('/v3/dataforseo_labs/google/top_searches/live', 'POST', [{
location_name: params.location_name,
language_code: params.language_code,
limit: params.limit,
offset: params.offset,
filters: this.formatFilters(params.filters),
order_by: this.formatOrderBy(params.order_by),
include_clickstream_data: params.include_clickstream_data
}]);
return this.validateAndFormatResponse(response);
}
catch (error) {
return this.formatErrorResponse(error);
}
}
}