Skip to main content
Glama
21st-dev

Magic Component Platform (MCP)

by 21st-dev

logo_search

Search for company logos and retrieve them as React components (JSX/TSX) or SVG markup for UI development projects.

Instructions

Search and return logos in specified format (JSX, TSX, SVG). Supports single and multiple logo searches with category filtering. Can return logos in different themes (light/dark) if available.

When to use this tool:

  1. When user types "/logo" command (e.g., "/logo GitHub")

  2. When user asks to add a company logo that's not in the local project

Example queries:

  • Single company: ["discord"]

  • Multiple companies: ["discord", "github", "slack"]

  • Specific brand: ["microsoft office"]

  • Command style: "/logo GitHub" -> ["github"]

  • Request style: "Add Discord logo to the project" -> ["discord"]

Format options:

  • TSX: Returns TypeScript React component

  • JSX: Returns JavaScript React component

  • SVG: Returns raw SVG markup

Each result includes:

  • Component name (e.g., DiscordIcon)

  • Component code

  • Import instructions

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queriesYesList of company names to search for logos
formatYesOutput format

Implementation Reference

  • The `execute` method: core handler that processes multiple logo queries, fetches SVGs from SVGL API, converts to JSX/TSX/SVG formats, generates component code, handles failures, saves test results, and returns JSON-structured response with icons, not-found suggestions, and usage setup instructions.
    async execute({ queries, format }: z.infer<typeof this.schema>) {
      console.log(
        `[${LOGO_TOOL_NAME}] Starting logo search for: ${queries.join(
          ", "
        )} in ${format} format`
      );
      try {
        // Process all queries
        const results = await Promise.all(
          queries.map(async (query) => {
            try {
              console.log(`[${LOGO_TOOL_NAME}] Fetching logos for ${query}...`);
              const logos = await this.fetchLogos(query);
    
              if (logos.length === 0) {
                console.log(`[${LOGO_TOOL_NAME}] No logo found for ${query}`);
                return {
                  query,
                  success: false,
                  message: `No logo found for: "${query}"`,
                };
              }
    
              const logo = logos[0];
              console.log(
                `[${LOGO_TOOL_NAME}] Processing logo for: ${logo.title}`
              );
    
              const svgUrl =
                typeof logo.route === "string" ? logo.route : logo.route.light;
              console.log(`[${LOGO_TOOL_NAME}] Fetching SVG from: ${svgUrl}`);
              const svgContent = await this.fetchSVGContent(svgUrl);
    
              console.log(`[${LOGO_TOOL_NAME}] Converting to ${format} format`);
              const formattedContent = await this.convertToFormat(
                svgContent,
                format,
                logo.title + "Icon"
              );
    
              console.log(`[${LOGO_TOOL_NAME}] Successfully processed ${query}`);
              return {
                query,
                success: true,
                content: `// ${logo.title} (${logo.url})\n${formattedContent}`,
              };
            } catch (error) {
              console.error(
                `[${LOGO_TOOL_NAME}] Error processing ${query}:`,
                error
              );
              return {
                query,
                success: false,
                message: error instanceof Error ? error.message : "Unknown error",
              };
            }
          })
        );
    
        // Prepare summary
        const successful = results.filter((r) => r.success);
        const failed = results.filter((r) => !r.success);
    
        console.log(`[${LOGO_TOOL_NAME}] Results summary:`);
        console.log(
          `[${LOGO_TOOL_NAME}] Successfully processed: ${successful.length}`
        );
        console.log(`[${LOGO_TOOL_NAME}] Failed to process: ${failed.length}`);
    
        // Save test results
        await this.saveTestResult({
          queries,
          format,
          successful: successful
            .filter(
              (r): r is typeof r & { content: string } => r.content !== undefined
            )
            .map((r) => ({
              query: r.query,
              content: r.content,
            })),
          failed: failed
            .filter(
              (r): r is typeof r & { message: string } => r.message !== undefined
            )
            .map((r) => ({
              query: r.query,
              message: r.message,
            })),
        });
    
        // Format response as component structure
        const foundIcons = successful.map((r) => {
          const title =
            r.content?.split("\n")[0].replace("// ", "").split(" (")[0] || "";
          const componentName =
            title
              .split(" ")
              .map((word) => word.charAt(0).toUpperCase() + word.slice(1))
              .join("")
              .replace(/[^a-zA-Z0-9]/g, "") + "Icon";
    
          return {
            icon: componentName,
            code: r.content?.split("\n").slice(1).join("\n") || "",
          };
        });
    
        const missingIcons = failed.map((f) => ({
          icon: f.query,
          alternatives: [
            "Search for SVG version on the official website",
            "Check other icon libraries (e.g., heroicons, lucide)",
            "Request SVG file from the user",
          ],
        }));
    
        const response = {
          icons: foundIcons,
          notFound: missingIcons,
          setup: [
            "1. Add these icons to your project:",
            foundIcons
              .map((c) => `   ${c.icon}.${format.toLowerCase()}`)
              .join("\n"),
            "2. Import and use like this:",
            "```tsx",
            "import { " +
              foundIcons.map((c) => c.icon).join(", ") +
              " } from '@/icons';",
            "```",
          ].join("\n"),
        };
    
        // Log results
        return {
          content: [
            {
              type: "text" as const,
              text: JSON.stringify(response, null, 2),
            },
          ],
        };
      } catch (error) {
        // Log error
        console.error(`[${LOGO_TOOL_NAME}] Error:`, error);
        throw error;
      }
    }
  • LogoSearchTool class definition including name='logo_search', multi-line description, and Zod schema for inputs: queries (string array), format (enum: JSX/TSX/SVG).
    export class LogoSearchTool extends BaseTool {
      name = LOGO_TOOL_NAME;
      description = LOGO_TOOL_DESCRIPTION;
    
      schema = z.object({
        queries: z
          .array(z.string())
          .describe("List of company names to search for logos"),
        format: z.enum(["JSX", "TSX", "SVG"]).describe("Output format"),
      });
  • src/index.ts:22-25 (registration)
    Registration of LogoSearchTool (and other tools) to the MCP server instance via .register(server) method.
    new CreateUiTool().register(server);
    new LogoSearchTool().register(server);
    new FetchUiTool().register(server);
    new RefineUiTool().register(server);
  • src/index.ts:10-10 (registration)
    Import statement for LogoSearchTool from the implementation file.
    import { LogoSearchTool } from "./tools/logo-search.js";
  • Helper method to fetch logo metadata from SVGL API.
    private async fetchLogos(query: string): Promise<SVGLogo[]> {
      const baseUrl = "https://api.svgl.app";
      const url = `${baseUrl}?search=${encodeURIComponent(query)}`;
    
      try {
        const response = await fetch(url);
        if (!response.ok) {
          if (response.status === 404) {
            return []; // Return empty array for not found instead of throwing
          }
          throw new Error(`SVGL API error: ${response.statusText}`);
        }
        const data = await response.json();
        return Array.isArray(data) ? data : [];
      } catch (error) {
        console.error(
          `[${LOGO_TOOL_NAME}] Error fetching logos for ${query}:`,
          error
        );
        return []; // Return empty array on error
      }
    }
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure and does so effectively. It describes key behaviors: supporting single/multiple searches with category filtering, returning logos in different themes if available, and detailing what each result includes (component name, code, import instructions). However, it doesn't mention potential limitations like rate limits, authentication needs, or what happens when logos aren't found.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with clear sections (purpose, usage guidelines, examples, format options, result details) and front-loaded with the core functionality. While comprehensive, some sentences could be more concise (e.g., the example queries section is somewhat repetitive). Overall, it's efficiently organized with minimal wasted text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema, the description provides substantial context: purpose, usage scenarios, examples, format details, and result structure. It adequately covers the tool's functionality given its complexity. The main gap is the lack of output schema, but the description compensates by detailing what results include, making it mostly complete for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, so the schema already documents both parameters thoroughly. The description adds some value by explaining format options (TSX, JSX, SVG) and providing example queries that illustrate how to use the 'queries' parameter, but doesn't add significant semantic information beyond what's in the structured schema. This meets the baseline expectation for high schema coverage.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('search and return logos') and resources ('logos in specified format'), and distinguishes it from sibling tools by focusing on logo search functionality rather than component building, inspiration, or refinement. The opening sentence provides a complete, unambiguous statement of what the tool does.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides explicit guidance with a dedicated 'When to use this tool' section, listing two specific scenarios: when users type '/logo' commands and when they request logos not in the local project. It also includes five concrete example queries that demonstrate both command-style and request-style usage patterns, giving clear context for application.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/21st-dev/magic-mcp'

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