Skip to main content
Glama

extract_logo

Extract logo icon URLs from website URLs to identify and retrieve brand logos automatically from any given webpage.

Instructions

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

Input Schema

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

Implementation Reference

  • The primary handler function for the 'extract_logo' MCP tool. It validates the input URL, extracts logo candidates using LogoExtractor, selects the best one, and returns a JSON-formatted 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), }, ], }; }
  • The schema definition for the 'extract_logo' tool, specifying the required 'url' input parameter.
    { name: 'extract_logo', description: '从指定网站URL提取Logo图标链接', inputSchema: { type: 'object', properties: { url: { type: 'string', description: '要提取Logo的网站URL', }, }, required: ['url'], }, },
  • src/index.ts:64-86 (registration)
    Registration of the tool call handler, which dispatches to handleExtractLogo when 'extract_logo' is called.
    this.server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; try { switch (name) { case 'extract_logo': return await this.handleExtractLogo(args); case 'analyze_logo_candidates': return await this.handleAnalyzeCandidates(args); default: throw new Error(`未知的工具: ${name}`); } } catch (error) { return { content: [ { type: 'text', text: `错误: ${error instanceof Error ? error.message : '未知错误'}`, }, ], }; } });
  • src/index.ts:29-62 (registration)
    Registration in ListTools response, listing 'extract_logo' with its schema.
    this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'extract_logo', description: '从指定网站URL提取Logo图标链接', inputSchema: { type: 'object', properties: { url: { type: 'string', description: '要提取Logo的网站URL', }, }, required: ['url'], }, }, { name: 'analyze_logo_candidates', description: '分析网站的所有Logo候选项并返回详细信息', inputSchema: { type: 'object', properties: { url: { type: 'string', description: '要分析的网站URL', }, }, required: ['url'], }, }, ], }; });
  • Core helper function that implements the logo extraction logic: fetches website, parses with cheerio, collects candidates from favicons, apple icons, OG images, logo images, common paths, deduplicates and scores them.
    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 []; } }
Install Server

Other 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