get_icon_detail_by_prefix_and_name
Retrieve detailed SVG icon information by specifying a prefix and name, enabling precise or batch icon matching for FE/UI/Designers via PickAPIcon MCP.
Instructions
get icon detail by prefix and svg name
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prefix | No | icon prefix, default env.PREFIX | |
| svg_list | No | icon svg name list, match batch of icons fuzzily | |
| svg_name | No | icon svg name, match single icon exactly |
Implementation Reference
- src/index.ts:104-158 (handler)The handler function executes the tool logic, supporting both single icon by exact name or batch by list, fetching via getIconByPrefixAndName and returning JSON stringified SVG 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-based input schema defining optional parameters: svg_list (array of strings), svg_name (string), and prefix (string).{ 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-159 (registration)Registers the 'get_icon_detail_by_prefix_and_name' tool using server.tool() with name, description, input schema, and handler function.server.tool( "get_icon_detail_by_prefix_and_name", "get icon detail by prefix and svg name", { 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"), }, 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/fetcher.ts:42-62 (helper)Supporting utility function that fetches the SVG icon content from the Iconify API by prefix and name, returning the text content or null on error.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; } }