get_icons_by_desc_and_prefix
Retrieve SVG icons from Iconify API using descriptive keywords and prefix filters, enabling designers and developers to find UI icons programmatically instead of manual website searches.
Instructions
get icons by desc and prefix (LIKE AS ant-design)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| desc | Yes | desc of icon, only English | |
| prefix | No | icon prefix, default env.PREFIX |
Implementation Reference
- src/index.ts:56-86 (handler)The inline asynchronous handler function for the MCP tool. It receives desc and optional prefix, calls the searchIconsByPrefixAndDesc helper, handles null response with error message, otherwise maps icon names to SVG names by splitting on ':', stringifies the array as JSON, and returns it wrapped in MCP content format.async ({ desc, prefix = process.env.PREFIX as string }) => { const res: { icons: string[] } | null = await searchIconsByPrefixAndDesc( prefix, desc ); if (!res) { return { content: [ { type: "text", text: "Failed to Get Icon Collection", }, ], }; } return { content: [ { type: "text", text: JSON.stringify( res.icons.map((iconName) => { const [_, svgName] = iconName.split(":"); return svgName; }) ), }, ], }; }
- src/index.ts:52-55 (schema)Zod schema defining the input parameters for the tool: 'desc' as required string (English description), 'prefix' as optional string (defaults to env.PREFIX).{ desc: z.string().describe("desc of icon, only English"), prefix: z.string().optional().describe("icon prefix, default env.PREFIX"), },
- src/index.ts:49-87 (registration)MCP tool registration via server.tool() call, specifying the tool name, description, input schema, and handler function.server.tool( "get_icons_by_desc_and_prefix", "get icons by desc and prefix (LIKE AS ant-design)", { desc: z.string().describe("desc of icon, only English"), prefix: z.string().optional().describe("icon prefix, default env.PREFIX"), }, async ({ desc, prefix = process.env.PREFIX as string }) => { const res: { icons: string[] } | null = await searchIconsByPrefixAndDesc( prefix, desc ); if (!res) { return { content: [ { type: "text", text: "Failed to Get Icon Collection", }, ], }; } return { content: [ { type: "text", text: JSON.stringify( res.icons.map((iconName) => { const [_, svgName] = iconName.split(":"); return svgName; }) ), }, ], }; } );
- src/fetcher.ts:18-39 (helper)Supporting utility function that queries the Iconify API search endpoint (`https://api.iconify.design/search?query=${desc}&prefix=${prefix}`), returns parsed JSON response typed as T or null on failure./** get icon collection by prefix And desc (LIKE AS ant-design) */ export async function searchIconsByPrefixAndDesc<T>( prefix: string, desc: string ): Promise<T | null> { try { const res = await fetch( `https://api.iconify.design/search?query=${desc}&prefix=${prefix}`, { method: "GET", } ); if (!res.ok) { throw new Error(`HTTP error! status: ${res.status}`); } return (await res.json()) as T; } catch (error) { console.error("Error making request:", error); return null; } }