get_icons_by_desc_and_prefix
Retrieve SVG icons using descriptions and prefixes from the Iconify API. Designed for FE/UI designers to simplify icon searches without manual website browsing.
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 handler function for the MCP tool 'get_icons_by_desc_and_prefix'. It calls the helper to search icons and returns a JSON string of matching icon names (stripped of 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/index.ts:52-55 (schema)Zod schema defining the input parameters: required 'desc' (string) and optional 'prefix' (string).{ 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 call via server.tool(), including name, description, input schema, and inline 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:19-39 (helper)Helper function that performs the HTTP fetch to Iconify API search endpoint with prefix and description query, returns parsed JSON or null on error.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; } }