SEO洞察MCP服务器
该项目提供了一个模型上下文协议(MCP)服务器,将AI助手连接到SEO API,用于反向链接分析、关键字研究和流量分析。
免责声明
此项目与此项目中使用的任何API都没有关联。 你需要一个 CAPSOLVER API密钥 解决 阿雷夫斯 验证码。
可用特征
SEO工具
- \[x\] 获取任何域名的反向链接列表
- \[x\] 为任何种子关键字生成关键字创意
- \[x\] 检查关键字难度和SERP分析
- \[x\] 分析网站流量和表现最佳的内容
支持的交通工具
- \[\]使用以下命令实现auth(“Authorization”标头 Bearer )
- \[x\] ~~"sse" 运输~~ (已弃用)
- \[\]编写测试
如何使用
命令行界面
# Analyze website traffic
npm run dev:cli -- get-traffic --domain "example.com"
# Equivalent to
npm run dev:cli -- get-traffic --domain "example.com" --mode "subdomains"
# Analyze website traffic for a specific country
npm run dev:cli -- get-traffic --domain "example.com" --mode "exact" --country "uk"
# Get backlinks for a domain
npm run dev:cli -- get-backlinks --domain "example.com"
# Generate keyword ideas
npm run dev:cli -- keyword-generator --keyword "seo tools" --country "us"
# Generate keyword ideas with specific search engine
npm run dev:cli -- keyword-generator --keyword "seo tools" --country "us" --search-engine "Google"
# Check keyword difficulty
npm run dev:cli -- keyword-difficulty --keyword "seo analytics" --country "us"
MCP设置
对于使用stdio传输的本地配置:
{
"mcpServers": {
"seo-insights": {
"command": "node",
"args": ["/path/to/seo-insights-mcp-server/dist/index.js"],
"transportType": "stdio"
}
}
}对于远程HTTP配置:
{
"mcpServers": {
"seo-insights": {
"type": "http",
"url": "http://localhost:8080/mcp"
}
}
}HTTP传输的环境变量:
您可以使用以下环境变量配置HTTP服务器:
MCP_HTTP_HOST:要绑定的主机(默认值:127.0.0.1)MCP_HTTP_PORT:要侦听的端口(默认值:8080)MCP_HTTP_PATH:端点路径(默认值:/mcp)
______________________________________________________________________
源代码概述
什么是MCP?
模型上下文协议(MCP)是一个开放标准,允许人工智能系统安全地与外部工具和数据源进行上下文连接。
该样板文件采用一种干净、分层的体系结构来实现MCP规范,该体系结构可以扩展为为任何API或数据源构建自定义MCP服务器。
为什么要使用这个锅炉板?
- 生产就绪架构:遵循已发布的MCP服务器中使用的相同模式,CLI、工具、控制器和服务之间有明确的分离。
- 类型安全:使用TypeScript构建,以改善开发人员体验、代码质量和可维护性。
- 工作示例:包括一个完全实现的IP查找工具,演示了从CLI到API集成的完整模式。
- 测试框架:配备用于单元和CLI集成测试的测试基础设施,包括覆盖率报告。
- 开发工具:包括ESLint、Prettier、TypeScript和其他为MCP服务器开发预配置的质量工具。
______________________________________________________________________
入门指南
先决条件
- Node.js (>=18.x): 下载
- Git:用于版本控制
______________________________________________________________________
步骤1:克隆并安装
# Clone the repository
git clone https://github.com/mrgoonie/seo-insights-mcp-server.git
cd seo-insights-mcp-server
# Install dependencies
npm install______________________________________________________________________
步骤2:运行开发服务器
在开发模式下使用stdio传输启动服务器(默认):
npm run dev:server或者使用流式HTTP传输:
npm run dev:server:http这将通过热重新加载启动MCP服务器,并在以下位置启用MCP检查器http://localhost:5173.
⚙️ 代理服务器侦听端口6277 🔍 MCP检查器已启动并运行http://127.0.0.1:6274
使用HTTP传输时,服务器将在http://127.0.0.1:8080/mcp默认情况下。
______________________________________________________________________
步骤3:测试SEO工具
使用CLI测试各种SEO工具:
# Get backlinks for a domain
npm run dev:cli -- get-backlinks --domain "example.com"
# Generate keyword ideas
npm run dev:cli -- generate-keywords --keyword "seo tools" --country "us"
# Check keyword difficulty
npm run dev:cli -- check-keyword-difficulty --keyword "seo analytics" --country "us"
# Analyze website traffic
npm run dev:cli -- get-traffic --domain "example.com" --mode "subdomains"示例响应
关键字难度检查
{
"keyword": "seo analytics",
"difficulty": 72,
"volume": 1200,
"cpc": 5.25,
"serp": [
{
"position": 1,
"title": "SEO Analytics: The Complete Guide",
"url": "https://example.com/seo-analytics-guide",
"domain": "example.com"
},
{
"position": 2,
"title": "Top 10 SEO Analytics Tools for 2025",
"url": "https://example.com/seo-analytics-tools",
"domain": "example.com"
}
]
}流量分析
{
"domain": "example.com",
"organicTraffic": 125000,
"paidTraffic": 15000,
"topPages": [
{
"url": "https://example.com/blog/seo-guide",
"traffic": 12500,
"keywords": 145
},
{
"url": "https://example.com/tools/keyword-research",
"traffic": 8700,
"keywords": 98
}
],
"trafficTrend": "increasing",
"growthRate": 15.4
}______________________________________________________________________
建筑
这个样板遵循一个干净的、分层的架构模式,该模式分离了关注点并提高了可维护性。
项目结构
src/
├── cli/ # Command-line interfaces
├── controllers/ # Business logic
├── resources/ # MCP resources: expose data and content from your servers to LLMs
├── services/ # External API interactions
├── tools/ # MCP tool definitions
├── types/ # Type definitions
├── utils/ # Shared utilities
└── index.ts # Entry point层次和责任
CLI层(src/cli/*.cli.ts)
- 目的:定义解析参数和调用控制器的命令行界面
- 命名:文件应命名
.cli.ts - 测试:中的CLI集成测试
.cli.test.ts
工具层(src/tools/*.tool.ts)
- 目的:为人工智能助手定义带有模式和描述的MCP工具
- 命名:文件应命名
.tool.ts类型在.types.ts - 模式:每个工具都应该使用zod进行参数验证
控制器层(src/controllers/*.controller.ts)
- 目的:实现业务逻辑、处理错误和格式化响应
- 命名:文件应命名
.controller.ts - 模式:应返回标准化
ControllerResponse物体
服务层(src/services/*.service.ts)
- 目的:与外部API或数据源交互
- 命名:文件应命名
.service.ts - 模式:具有最小逻辑的纯API交互
工具 层src/utils/*.util.ts)
- 目的:在整个应用程序中提供共享功能
- 关键实用程序:
- logger.util.ts:结构化日志记录 - error.util.ts:错误处理和标准化 - formatter.util.ts:Markdown格式助手
______________________________________________________________________
开发指南
开发脚本
# Start server in development mode (hot-reload & inspector)
npm run dev:server
# Run CLI in development mode
npm run dev:cli -- [command] [args]
# Build the project
npm run build
# Start server in production mode
npm run start:server
# Run CLI in production mode
npm run start:cli -- [command] [args]测试
# Run all tests
npm test
# Run specific tests
npm test -- src/path/to/test.ts
# Generate test coverage report
npm run test:coverage代码质量
# Lint code
npm run lint
# Format code with Prettier
npm run format
# Check types
npm run typecheck______________________________________________________________________
构建自定义工具
按照以下步骤将您自己的工具添加到服务器:
1.定义服务层
在中创建新服务 src/services/ 与外部API交互:
// src/services/example.service.ts
import { Logger } from '../utils/logger.util.js';
const logger = Logger.forContext('services/example.service.ts');
export async function getData(param: string): Promise {
logger.debug('Getting data', { param });
// API interaction code here
return { result: 'example data' };
}2.创建控制器
在中添加控制器 src/controllers/ 处理业务逻辑:
// src/controllers/example.controller.ts
import { Logger } from '../utils/logger.util.js';
import * as exampleService from '../services/example.service.js';
import { formatMarkdown } from '../utils/formatter.util.js';
import { handleControllerError } from '../utils/error-handler.util.js';
import { ControllerResponse } from '../types/common.types.js';
const logger = Logger.forContext('controllers/example.controller.ts');
export interface GetDataOptions {
param?: string;
}
export async function getData(
options: GetDataOptions = {},
): Promise {
try {
logger.debug('Getting data with options', options);
const data = await exampleService.getData(options.param || 'default');
const content = formatMarkdown(data);
return { content };
} catch (error) {
throw handleControllerError(error, {
entityType: 'ExampleData',
operation: 'getData',
source: 'controllers/example.controller.ts',
});
}
}3.实施MCP工具
在中创建工具定义 src/tools/:
// src/tools/example.tool.ts
import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
import { z } from 'zod';
import { Logger } from '../utils/logger.util.js';
import { formatErrorForMcpTool } from '../utils/error.util.js';
import * as exampleController from '../controllers/example.controller.js';
const logger = Logger.forContext('tools/example.tool.ts');
const GetDataArgs = z.object({
param: z.string().optional().describe('Optional parameter'),
});
type GetDataArgsType = z.infer;
async function handleGetData(args: GetDataArgsType) {
try {
logger.debug('Tool get_data called', args);
const result = await exampleController.getData({
param: args.param,
});
return {
content: [{ type: 'text' as const, text: result.content }],
};
} catch (error) {
logger.error('Tool get_data failed', error);
return formatErrorForMcpTool(error);
}
}
export function register(server: McpServer) {
server.tool(
'get_data',
`Gets data from the example API, optionally using \`param\`.
Use this to fetch example data. Returns formatted data as Markdown.`,
GetDataArgs.shape,
handleGetData,
);
}4.添加CLI支持
在中创建CLI命令 src/cli/:
// src/cli/example.cli.ts
import { program } from 'commander';
import { Logger } from '../utils/logger.util.js';
import * as exampleController from '../controllers/example.controller.js';
import { handleCliError } from '../utils/error-handler.util.js';
const logger = Logger.forContext('cli/example.cli.ts');
program
.command('get-data')
.description('Get example data')
.option('--param ', 'Optional parameter')
.action(async (options) => {
try {
logger.debug('CLI get-data called', options);
const result = await exampleController.getData({
param: options.param,
});
console.log(result.content);
} catch (error) {
handleCliError(error);
}
});5.注册组件
更新入口点以注册新组件:
// In src/cli/index.ts
import '../cli/example.cli.js';
// In src/index.ts (for the tool)
import exampleTool from './tools/example.tool.js';
// Then in registerTools function:
exampleTool.register(server);______________________________________________________________________
调试工具
MCP检查员
访问可视化MCP检查器以测试您的工具并查看请求/响应详细信息:
- 跑
npm run dev:server - 打开http://localhost:5173在您的浏览器中
- 测试您的工具并直接在UI中查看日志
服务器日志
启用开发调试日志:
# Set environment variable
DEBUG=true npm run dev:server
# Or configure in ~/.mcp/configs.json______________________________________________________________________
发布您的MCP服务器
准备发布自定义MCP服务器时:
- 用您的详细信息更新package.json
- 使用您的工具文档更新README.md
- 构建项目:
npm run build - 测试生产版本:
npm run start:server - 发布到npm:
npm publish
______________________________________________________________________
许可证
{
"seo-insights": {
"environments": {
"DEBUG": "true",
"CAPSOLVER_API_KEY": "your-api-key"
}
}
}注: 为了向后兼容,服务器还将识别完整包名称下的配置(seo-insights-mcp-server)或未作用域的包名称(seo-insights-mcp-server)如果 seo-insights 找不到密钥。然而,使用短 seo-insights 建议将密钥用于新配置。
