Skip to main content
Glama

extract_logo

Extract website logo icons automatically from a given URL using the Logo MCP server. Simplifies logo retrieval for analysis, branding, or reference purposes.

Instructions

从指定网站URL提取Logo图标链接

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes要提取Logo的网站URL

Implementation Reference

  • The main execution handler for the 'extract_logo' tool. It validates the input URL, extracts logo candidates using LogoExtractor, selects the best logo, and returns a JSON response with the logo details.
    private async handleExtractLogo(args: any) { const { url } = args; if (!url || typeof url !== 'string') { throw new Error('请提供有效的网站URL'); } // 提取Logo候选项 const candidates = await this.logoExtractor.extractLogoCandidates(url); if (candidates.length === 0) { return { content: [ { type: 'text', text: `未能从网站 ${url} 找到任何Logo图标。`, }, ], }; } // 选择最佳Logo const bestLogo = this.logoExtractor.selectBestLogo(candidates); // 直接返回Logo链接信息 const responseData = { message: 'Logo提取成功,已返回可直接下载的Logo链接。', websiteUrl: url, logoUrl: bestLogo.url, logoType: bestLogo.type, logoSource: bestLogo.source, logoScore: bestLogo.score, }; return { content: [ { type: 'text', text: JSON.stringify(responseData, null, 2), }, ], }; }
  • src/index.ts:33-45 (registration)
    Registration of the 'extract_logo' tool in the MCP server's listTools handler, including the tool name, description, and input schema.
    name: 'extract_logo', description: '从指定网站URL提取Logo图标链接', inputSchema: { type: 'object', properties: { url: { type: 'string', description: '要提取Logo的网站URL', }, }, required: ['url'], }, },
  • Core helper function in LogoExtractor class that fetches the website, parses HTML with cheerio, extracts various types of logo candidates (favicon, apple-touch-icon, og:image, logo images, common paths), deduplicates, scores, and returns sorted list.
    async extractLogoCandidates(websiteUrl: string): Promise<LogoCandidate[]> { try { const normalizedUrl = this.normalizeUrl(websiteUrl); const response = await axios.get(normalizedUrl, { headers: { 'User-Agent': this.userAgent }, timeout: 10000, maxRedirects: 5, }); const $ = cheerio.load(response.data); const candidates: LogoCandidate[] = []; const baseUrl = new URL(normalizedUrl); // 1. 提取favicon相关链接 await this.extractFaviconCandidates($, baseUrl, candidates); // 2. 提取Apple Touch Icon await this.extractAppleTouchIcons($, baseUrl, candidates); // 3. 提取OpenGraph图像 await this.extractOpenGraphImages($, baseUrl, candidates); // 4. 提取可能的Logo图像 await this.extractLogoImages($, baseUrl, candidates); // 5. 尝试常见的favicon路径 await this.extractCommonFaviconPaths(baseUrl, candidates); // 去重并评分 return this.deduplicateAndScore(candidates); } catch (error) { console.error(`提取Logo候选项时出错: ${error}`); return []; } }
  • Helper method to select the best logo candidate from the list, prioritizing SVG formats and higher scores.
    selectBestLogo(candidates: LogoCandidate[]): LogoCandidate { if (candidates.length === 0) { throw new Error('没有可用的Logo候选项'); } // 优先选择高分的SVG或高质量PNG const sortedCandidates = candidates.sort((a, b) => { // SVG格式加分 const aIsSvg = a.url.toLowerCase().includes('.svg') || a.attributes?.type?.includes('svg'); const bIsSvg = b.url.toLowerCase().includes('.svg') || b.attributes?.type?.includes('svg'); if (aIsSvg && !bIsSvg) return -1; if (!aIsSvg && bIsSvg) return 1; // 按分数排序 return b.score - a.score; }); return sortedCandidates[0]; }

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/xtdexw/logo-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server