🚀 MCP Webpage Timestamps
MCP Webpage Timestamps 是一個強大的 模型上下文協議(Model Context Protocol,MCP) 服務器,用於提取網頁的創建、修改和發佈時間戳。該工具專為網頁抓取和網頁內容的時間分析而設計。
🚀 快速開始
MCP Webpage Timestamps 是一款強大的工具,你可以按照以下步驟快速開始使用:
- 安裝依賴:確保你的系統滿足 Node.js 18.0.0 或更高版本的要求,同時安裝 npm 或 yarn。
- 選擇安裝方式:根據你的需求選擇合適的安裝方式,如使用 npm 全局安裝、npx 臨時使用或通過 Smithery 自動安裝。
- 配置客戶端:如果你使用的是 Claude Desktop 或其他 MCP 兼容客戶端,需要按照文檔進行相應的配置。
- 啟動服務:安裝完成後,你可以使用
npm start
啟動服務,或者使用 npm run dev
在開發模式下啟動。
✨ 主要特性
- 全面的時間戳提取:能夠從網頁中提取創建、修改和發佈時間戳。
- 多數據源支持:支持 HTML 元標籤、HTTP 頭部、JSON-LD、微數據、OpenGraph、Twitter 卡片和啟發式分析。
- 置信度評分:為提取的時間戳提供高、中、低置信度級別。
- 批量處理:可同時從多個 URL 提取時間戳。
- 可配置性:可自定義超時時間、用戶代理、重定向處理和啟發式選項。
- 生產就緒:具備強大的錯誤處理能力、全面的日誌記錄和 TypeScript 支持。
📦 安裝指南
快速安裝
npm install -g mcp-webpage-timestamps
使用 npx
npx mcp-webpage-timestamps
通過 Smithery 安裝
若要通過 Smithery 自動為 Claude Desktop 安裝 mcp-webpage-timestamps,可運行以下命令:
npx -y @smithery/cli install @Fabien-desablens/mcp-webpage-timestamps --client claude
前提條件
- Node.js 18.0.0 或更高版本
- npm 或 yarn
開發環境安裝
git clone https://github.com/Fabien-desablens/mcp-webpage-timestamps.git
cd mcp-webpage-timestamps
npm install
npm run build
💻 使用示例
基礎用法
import { TimestampExtractor } from './src/extractor.js';
const extractor = new TimestampExtractor();
const result = await extractor.extractTimestamps('https://example.com/article');
console.log('Published:', result.publishedAt);
console.log('Modified:', result.modifiedAt);
console.log('Confidence:', result.confidence);
console.log('Sources:', result.sources.length);
高級用法
const extractor = new TimestampExtractor({
timeout: 15000,
userAgent: 'MyBot/1.0',
enableHeuristics: false,
maxRedirects: 3
});
const result = await extractor.extractTimestamps('https://example.com');
批量處理
const urls = [
'https://example.com/article1',
'https://example.com/article2',
'https://example.com/article3'
];
const results = await Promise.all(
urls.map(url => extractor.extractTimestamps(url))
);
📚 詳細文檔
作為 MCP 服務器使用
該服務器可與任何 MCP 兼容的客戶端配合使用,以下是配置方法:
Claude Desktop 配置
在 claude_desktop_config.json
中添加以下內容:
{
"mcpServers": {
"webpage-timestamps": {
"command": "npx",
"args": ["mcp-webpage-timestamps"],
"env": {}
}
}
}
客戶端配置
在 MCP 設置中添加以下內容:
{
"mcpServers": {
"webpage-timestamps": {
"command": "npx",
"args": ["mcp-webpage-timestamps"]
}
}
}
直接使用
npm start
npm run dev
🔧 技術細節
API 參考
工具
extract_timestamps
從單個網頁提取時間戳。
參數:
url
(字符串,必需):要提取時間戳的網頁 URL。
config
(對象,可選):配置選項。
配置選項:
timeout
(數字):請求超時時間(毫秒,默認值:10000)。
userAgent
(字符串):請求的用戶代理字符串。
followRedirects
(布爾值):是否跟隨 HTTP 重定向(默認值:true)。
maxRedirects
(數字):最大重定向次數(默認值:5)。
enableHeuristics
(布爾值):是否啟用啟發式時間戳檢測(默認值:true)。
示例:
{
"name": "extract_timestamps",
"arguments": {
"url": "https://example.com/article",
"config": {
"timeout": 15000,
"enableHeuristics": true
}
}
}
batch_extract_timestamps
批量從多個網頁提取時間戳。
參數:
urls
(字符串數組,必需):要提取時間戳的 URL 數組。
config
(對象,可選):與 extract_timestamps
相同的配置選項。
示例:
{
"name": "batch_extract_timestamps",
"arguments": {
"urls": [
"https://example.com/article1",
"https://example.com/article2",
"https://example.com/article3"
],
"config": {
"timeout": 10000
}
}
}
響應格式
兩個工具都返回一個具有以下結構的 JSON 對象:
{
url: string;
createdAt?: Date;
modifiedAt?: Date;
publishedAt?: Date;
sources: TimestampSource[];
confidence: 'high' | 'medium' | 'low';
errors?: string[];
}
TimestampSource:
{
type: 'html-meta' | 'http-header' | 'json-ld' | 'microdata' | 'opengraph' | 'twitter' | 'heuristic';
field: string;
value: string;
confidence: 'high' | 'medium' | 'low';
}
支持的時間戳來源
HTML 元標籤
article:published_time
article:modified_time
date
pubdate
publishdate
last-modified
dc.date.created
dc.date.modified
dcterms.created
dcterms.modified
HTTP 頭部
JSON-LD 結構化數據
datePublished
dateModified
dateCreated
微數據
datePublished
dateModified
OpenGraph
og:article:published_time
og:article:modified_time
og:updated_time
Twitter 卡片
啟發式分析
- 帶有
datetime
屬性的時間元素
- 文本中的常見日期模式
- 與日期相關的 CSS 類
開發
腳本
npm run dev
npm run build
npm test
npm run test:watch
npm run lint
npm run lint:fix
npm run format
測試
項目包含全面的測試:
npm test
npm test -- --coverage
npm test -- extractor.test.ts
代碼質量
- TypeScript:全面支持 TypeScript 並進行嚴格的類型檢查。
- ESLint:使用推薦規則進行代碼檢查。
- Prettier:代碼格式化。
- Jest:單元和集成測試。
- 95% 以上的測試覆蓋率:全面的測試套件。
📄 許可證
本項目採用 MIT 許可證,詳情請參閱 LICENSE 文件。
支持
更新日誌
詳細的更新歷史請參閱 CHANGELOG.md。
致謝