DataForSEO MCP 服务器
DataForSEO 的模型上下文协议 (MCP) 服务器实现,使 Claude 能够与选定的 DataForSEO API 进行交互并通过标准化接口获取 SEO 数据。
特征
- SERP API:Google、Bing 和 Yahoo 的实时搜索引擎结果页面 (SERP) 数据;
- KEYWORDS_DATA API:关键词研究和点击流数据,包括搜索量、每次点击费用和其他指标;
- ONPAGE API:允许根据可定制的参数抓取网站和网页,以获取页面 SEO 性能指标;
- DATAFORSEO_LABS API:基于 DataForSEO 内部数据库和专有算法的关键字、SERP 和域数据。
先决条件
- Node.js(v14 或更高版本)
- DataForSEO API 凭证(API 登录名和密码)
安装
- 克隆存储库:
git clone https://github.com/dataforseo/mcp-server-typescript
cd mcp-server-typescript
- 安装依赖项:
- 设置环境变量:
# Required
export DATAFORSEO_USERNAME=your_username
export DATAFORSEO_PASSWORD=your_password
# Optional: specify which modules to enable (comma-separated)
# If not set, all modules will be enabled
export ENABLED_MODULES="SERP,KEYWORDS_DATA,ONPAGE,DATAFORSEO_LABS,BACKLINKS,BUSINESS_DATA,DOMAIN_ANALYTICS"
# Optional: enable full API responses
# If not set or set to false, the server will filter and transform API responses to a more concise format
# If set to true, the server will return the full, unmodified API responses
export DATAFORSEO_FULL_RESPONSE="false"
作为 NPM 包安装
您可以全局安装该包:
npm install -g dataforseo-mcp-server
或者无需安装直接运行:
npx dataforseo-mcp-server
运行命令之前记得设置环境变量:
# Required environment variables
export DATAFORSEO_USERNAME=your_username
export DATAFORSEO_PASSWORD=your_password
# Run with npx
npx dataforseo-mcp-server
构建和运行
构建项目:
运行服务器:
可用模块
以下模块可以启用/禁用:
SERP
:Google、Bing 和 Yahoo 的实时 SERP 数据;KEYWORDS_DATA
:关键词研究和点击流数据;ONPAGE
:抓取网站和网页以获取页面 SEO 性能指标;DATAFORSEO_LABS
:基于 DataForSEO 数据库和算法的关键字、SERP 和域名数据;BACKLINKS
:任何域、子域或网页的入站链接、引用域和引用页面的数据;BUSINESS_DATA
:基于以下平台公开分享的商业评论和商业信息:Google、Trustpilot、Tripadvisor;DOMAIN_ANALYTICS
:帮助识别用于构建网站的所有可能技术并提供 Whois 数据;
添加新工具/模块
模块结构
每个模块对应一个特定的DataForSEO API:
实施选项
您可以:
- 向现有模块添加新工具
- 创建一个全新的模块
添加新工具
以下是向任何新模块或现有模块添加新工具的方法:
// src/modules/your-module/tools/your-tool.tool.ts
import { BaseTool } from '../../base.tool';
import { DataForSEOClient } from '../../../client/dataforseo.client';
import { z } from 'zod';
export class YourTool extends BaseTool {
constructor(private client: DataForSEOClient) {
super(client);
// DataForSEO API returns extensive data with many fields, which can be overwhelming
// for AI agents to process. We select only the most relevant fields to ensure
// efficient and focused responses.
this.fields = [
'title', // Example: Include the title field
'description', // Example: Include the description field
'url', // Example: Include the URL field
// Add more fields as needed
];
}
getName() {
return 'your-tool-name';
}
getDescription() {
return 'Description of what your tool does';
}
getParams(): z.ZodRawShape {
return {
// Required parameters
keyword: z.string().describe('The keyword to search for'),
location: z.string().describe('Location in format "City,Region,Country" or just "Country"'),
// Optional parameters
fields: z.array(z.string()).optional().describe('Specific fields to return in the response. If not specified, all fields will be returned'),
language: z.string().optional().describe('Language code (e.g., "en")'),
};
}
async handle(params: any) {
try {
// Make the API call
const response = await this.client.makeRequest({
endpoint: '/v3/dataforseo_endpoint_path',
method: 'POST',
body: [{
// Your request parameters
keyword: params.keyword,
location: params.location,
language: params.language,
}],
});
// Validate the response for errors
this.validateResponse(response);
//if the main data array is specified in tasks[0].result[:] field
const result = this.handleDirectResult(response);
//if main data array specified in tasks[0].result[0].items field
const result = this.handleItemsResult(response);
// Format and return the response
return this.formatResponse(result);
} catch (error) {
// Handle and format any errors
return this.formatErrorResponse(error);
}
}
}
创建新模块
- 在
src/modules/
下为您的模块创建一个新目录:
mkdir -p src/modules/your-module-name
- 创建模块文件:
// src/modules/your-module-name/your-module-name.module.ts
import { BaseModule } from '../base.module';
import { DataForSEOClient } from '../../client/dataforseo.client';
import { YourTool } from './tools/your-tool.tool';
export class YourModuleNameModule extends BaseModule {
constructor(private client: DataForSEOClient) {
super();
}
getTools() {
return {
'your-tool-name': new YourTool(this.client),
};
}
}
- 在
src/config/modules.config.ts
中注册您的模块:
export const AVAILABLE_MODULES = [
'SERP',
'KEYWORDS_DATA',
'ONPAGE',
'DATAFORSEO_LABS',
'YOUR_MODULE_NAME' // Add your module name here
] as const;
- 在
src/index.ts
中初始化您的模块:
if (isModuleEnabled('YOUR_MODULE_NAME', enabledModules)) {
modules.push(new YourModuleNameModule(dataForSEOClient));
}
您希望我们接下来支持哪些端点/API?
我们始终致力于扩展此 MCP 服务器的功能。如果您希望支持特定的 DataForSEO 端点或 API,请:
- 查看DataForSEO API 文档,了解可用内容
- 在我们的 GitHub 存储库中打开一个问题:
- 您希望支持的 API/端点;
- 您的用例的简要描述;
- 描述您希望实现的任何具体功能。
您的反馈有助于我们确定下一步要支持的 API 的优先级!
资源