get_icon_detail_by_prefix_and_name
Retrieve SVG icon details from the Iconify API by specifying a prefix and icon name. Use this tool to fetch exact icon data for single icons or batch process multiple icons with fuzzy matching.
Instructions
get icon detail by prefix and svg name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| svg_list | No | icon svg name list, match batch of icons fuzzily | |
| svg_name | No | icon svg name, match single icon exactly | |
| prefix | No | icon prefix, default env.PREFIX |
Implementation Reference
- src/index.ts:104-158 (handler)MCP tool handler that handles single svg_name or batch svg_list by calling getIconByPrefixAndName and returning JSON stringified content.async ({ svg_list, svg_name = "", prefix = process.env.PREFIX as string, }) => { if (svg_name) { const icon = await getIconByPrefixAndName(prefix, svg_name); if (!icon) { return { content: [ { type: "text", text: "Failed to Get Icon", }, ], }; } return { content: [ { type: "text", text: JSON.stringify(icon), }, ], }; } const icons = await Promise.all( (svg_list || []).map((svg_name) => getIconByPrefixAndName(prefix, svg_name) ) ); if (!icons) { return { content: [ { type: "text", text: "Failed to Get Icon", }, ], }; } return { content: [ { type: "text", text: JSON.stringify(icons), }, ], }; }
- src/index.ts:93-103 (schema)Zod input schema defining parameters for the tool: svg_list (array), svg_name (string), prefix (string optional).{ svg_list: z .array(z.string()) .optional() .describe("icon svg name list, match batch of icons fuzzily"), svg_name: z .string() .optional() .describe("icon svg name, match single icon exactly"), prefix: z.string().optional().describe("icon prefix, default env.PREFIX"), },
- src/index.ts:90-92 (registration)Registration of the MCP tool 'get_icon_detail_by_prefix_and_name' with description.server.tool( "get_icon_detail_by_prefix_and_name", "get icon detail by prefix and svg name",
- src/fetcher.ts:41-62 (helper)Helper function that fetches the SVG icon content from Iconify API by prefix and name, returns text or null on error./** get icon by prefix and svg name */ export async function getIconByPrefixAndName<T>( prefix: string, svgName: string ): Promise<T | null> { try { const res = await fetch( `https://api.iconify.design/${prefix}/${svgName}.svg`, { method: "GET", } ); if (!res.ok) { throw new Error(`HTTP error! status: ${res.status}`); } return (await res.text()) as T; } catch (error) { console.error("Error making request:", error); return null; } }