站点地图发现工具

一个用于发现站点地图、枚举站点地图URL并生成爬取边界的服务器工具。

  • by BUZDOLAPCI
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 BUZDOLAPCI/sitemap-scout

使用说明

网站地图侦察

MCP服务器,用于发现站点的站点地图,枚举站点地图URL,并生成爬网边界。

特性

  • 从多个来源(robots.txt、标准位置、站点地图索引)发现站点地图
  • 支持常规站点地图和站点地图索引文件
  • 处理gzip压缩的站点地图(.xml.gz)
  • 对大型站点地图的分页支持
  • 使用包含/排除模式过滤爬取边界建筑
  • 标准Dedalus响应信封格式

安装

npm install

用法

HTTP传输(生产)

# Build and start
npm run build
npm start

# Or run in development mode
npm run dev:http

默认情况下,服务器在端口8000上启动。配置为 PORT 环境变量。

STDIO交通(发展)

npm run dev:stdio

CLI选项

--stdio, -s       Use STDIO transport (for local development)
--port, -p PORT   HTTP server port (default: 8000)
--help, -h        Show help message

工具

discover_sitemaps

通过检查以下内容查找给定域的所有站点地图:

  • /sitemap.xml (标准位置)
  • robots.txt 网站地图:指令
  • 站点地图索引文件(递归发现)

输入:

{
  "url": "https://example.com"
}

输出:

{
  "ok": true,
  "data": {
    "domain": "https://example.com",
    "sitemaps": [
      {
        "url": "https://example.com/sitemap.xml",
        "type": "sitemap_index",
        "discovered_from": "standard_location"
      },
      {
        "url": "https://example.com/sitemap-posts.xml",
        "type": "sitemap",
        "discovered_from": "sitemap_index"
      }
    ],
    "robots_txt_found": true
  },
  "meta": {
    "source": "https://example.com",
    "retrieved_at": "2024-01-15T10:30:00.000Z",
    "warnings": []
  }
}

list_sitemap_urls

从支持分页的站点地图中枚举URL。

输入:

{
  "sitemap_url": "https://example.com/sitemap.xml",
  "limit": 100,
  "cursor": null
}

输出:

{
  "ok": true,
  "data": {
    "sitemap_url": "https://example.com/sitemap.xml",
    "urls": [
      {
        "loc": "https://example.com/page1",
        "lastmod": "2024-01-01",
        "changefreq": "weekly",
        "priority": "0.8"
      }
    ],
    "total_in_page": 100,
    "is_index": false
  },
  "meta": {
    "source": "https://example.com/sitemap.xml",
    "retrieved_at": "2024-01-15T10:30:00.000Z",
    "pagination": {
      "next_cursor": "eyJvZmZzZXQiOjEwMH0"
    }
  }
}

build_crawl-frontier

使用过滤规则从发现的站点地图构建爬行边界。

输入:

{
  "seed_url": "https://example.com",
  "rules": {
    "include": ["*blog*", "*article*"],
    "exclude": ["*admin*", "*login*"],
    "max_urls": 1000
  },
  "limit": 500
}

输出:

{
  "ok": true,
  "data": {
    "seed_url": "https://example.com",
    "frontier": [
      {
        "url": "https://example.com/blog/post1",
        "source_sitemap": "https://example.com/sitemap-blog.xml",
        "last_modified": "2024-01-01",
        "priority": "0.8"
      }
    ],
    "total_urls": 500,
    "sitemaps_processed": 3,
    "rules_applied": {
      "include": ["*blog*", "*article*"],
      "exclude": ["*admin*", "*login*"],
      "max_urls": 1000
    }
  },
  "meta": {
    "source": "https://example.com",
    "retrieved_at": "2024-01-15T10:30:00.000Z",
    "warnings": []
  }
}

响应信封

所有回复均遵循Dedalus标准信封格式:

成功响应

{
  "ok": true,
  "data": {},
  "meta": {
    "source": "optional string",
    "retrieved_at": "ISO-8601 timestamp",
    "pagination": { "next_cursor": null },
    "warnings": []
  }
}

错误响应

{
  "ok": false,
  "error": {
    "code": "INVALID_INPUT | UPSTREAM_ERROR | RATE_LIMITED | TIMEOUT | PARSE_ERROR | INTERNAL_ERROR",
    "message": "human readable message",
    "details": {}
  },
  "meta": {
    "retrieved_at": "ISO-8601 timestamp"
  }
}

环境变量

变量 默认值 描述
PORT 8000 HTTP服务器端口
REQUEST_TIMEOUT 30000 请求超时(毫秒)
MAX_CONCURRENT_REQUESTS 5 最大并发HTTP请求数

发展

# Install dependencies
npm install

# Run in development mode (HTTP)
npm run dev:http

# Run in development mode (STDIO)
npm run dev:stdio

# Run tests
npm test

# Type check
npm run typecheck

# Build for production
npm run build

局限性

  • 无身份验证支持(无状态服务器)
  • 无JavaScript渲染(仅静态站点地图解析)
  • 每个爬网边界请求最多10000个URL
  • HTTP请求的默认超时时间为30秒
  • Gzip压缩的站点地图需要正确的Content-Type或.gz扩展名

许可证

麻省理工学院