analyze_logo
Analyze website logos to extract dimensions, format, quality, and other details, with an option to return only the best logo URL for immediate use.
Instructions
分析Logo的基本信息(尺寸、格式、质量等),支持onlyBestUrl参数只返回最佳Logo的URL
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| url | Yes | 要分析的网站URL | |
| onlyBestUrl | No | 是否只返回最佳Logo的URL,默认为false |
Implementation Reference
- src/logo-extractor.ts:52-103 (handler)Core handler implementation for logo analysis: fetches HTML, extracts candidates from favicon, apple-touch-icon, og:image, CSS classes, brand images; validates, scores based on type/dimensions/aspect ratio, selects best candidate.async analyzeLogo(url: string): Promise<LogoAnalysis> { const startTime = Date.now(); const analysis: LogoAnalysis = { url, candidates: [], extractionTime: 0, status: 'failed', }; try { // 标准化URL const normalizedUrl = this.normalizeUrl(url); // 获取网页内容 const html = await this.fetchHtml(normalizedUrl); const $ = cheerio.load(html); const baseUrl = this.getBaseUrl(normalizedUrl); // 提取各种类型的Logo候选 const candidates: LogoCandidate[] = []; // 1. 提取favicon await this.extractFavicons($, baseUrl, candidates); // 2. 提取Apple Touch图标 await this.extractAppleTouchIcons($, baseUrl, candidates); // 3. 提取OpenGraph图像 await this.extractOpenGraphImages($, baseUrl, candidates); // 4. 提取通过CSS类名识别的Logo await this.extractLogoByClass($, baseUrl, candidates); // 5. 提取品牌相关图像 await this.extractBrandImages($, baseUrl, candidates); // 过滤和评分候选Logo analysis.candidates = await this.filterAndScoreCandidates(candidates); // 选择最佳候选 analysis.bestCandidate = this.selectBestCandidate(analysis.candidates); analysis.status = analysis.bestCandidate ? 'success' : 'no-logo'; analysis.extractionTime = Date.now() - startTime; return analysis; } catch (error) { console.error('Logo分析失败:', error); analysis.extractionTime = Date.now() - startTime; return analysis; } }
- src/index.ts:143-180 (handler)MCP protocol handler for 'analyze_logo' tool: parses arguments, calls core analyzeLogo, handles onlyBestUrl option, returns formatted text response or error.private async handleAnalyzeLogo(args: any) { const { url, onlyBestUrl = false } = args; const analysis = await this.logoExtractor.analyzeLogo(url); if (onlyBestUrl) { // 只返回最佳Logo URL if (analysis.status === 'failed' || !analysis.bestCandidate) { return { content: [ { type: 'text', text: `无法从 ${url} 找到Logo。请检查网站是否存在Logo或网络连接是否正常。`, }, ], }; } return { content: [ { type: 'text', text: analysis.bestCandidate.url, }, ], }; } else { // 返回完整分析结果 return { content: [ { type: 'text', text: `Logo分析结果:\n${JSON.stringify(analysis, null, 2)}`, }, ], }; } }
- src/index.ts:64-82 (registration)Registration of 'analyze_logo' tool in ListToolsRequestHandler, including name, description, and input schema.{ name: 'analyze_logo', description: '分析Logo的基本信息(尺寸、格式、质量等),支持onlyBestUrl参数只返回最佳Logo的URL', inputSchema: { type: 'object', properties: { url: { type: 'string', description: '要分析的网站URL', }, onlyBestUrl: { type: 'boolean', description: '是否只返回最佳Logo的URL,默认为false', default: false, }, }, required: ['url'], }, },
- src/logo-extractor.ts:6-19 (schema)TypeScript interfaces defining the structure of logo candidates and analysis results used by the tool.export interface LogoCandidate { url: string; type: 'favicon' | 'apple-touch-icon' | 'og:image' | 'logo-class' | 'brand-image'; size?: { width: number; height: number }; score: number; // 评分,用于选择最佳Logo } export interface LogoAnalysis { url: string; candidates: LogoCandidate[]; bestCandidate?: LogoCandidate; extractionTime: number; status: 'success' | 'failed' | 'no-logo'; }