@coolicons/mcp 0.0.0-stage → 5.0.0-beta.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kryston Schwarze
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,39 @@
1
- # Temporary Holding Version
1
+ # @coolicons/mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An MCP server for [coolicons](https://coolicons.cool). Lets a coding agent search 1220 icons in five styles and three corner radii, read an icon's SVG and get the right import, without guessing names.
4
+
5
+ ## Install
6
+
7
+ Claude Code:
8
+
9
+ ```sh
10
+ claude mcp add coolicons -- npx -y @coolicons/mcp
11
+ ```
12
+
13
+ Any other client that speaks MCP over stdio:
14
+
15
+ ```json
16
+ {
17
+ "mcpServers": {
18
+ "coolicons": {
19
+ "command": "npx",
20
+ "args": ["-y", "@coolicons/mcp"]
21
+ }
22
+ }
23
+ }
24
+ ```
25
+
26
+ No API key, no network. The whole set ships inside the package.
27
+
28
+ ## Tools
29
+
30
+ | Tool | What it does |
31
+ | --- | --- |
32
+ | `describe_set` | Counts, styles, radii, categories, packages and naming rules. Worth calling first |
33
+ | `search_icons` | Find icons by name or meaning. Separate several searches with commas to resolve many names in one call |
34
+ | `get_icon` | SVG source of one icon in any style and corner radius, with size and stroke width |
35
+ | `get_usage` | Install command and import code for React, Vue, SVG or the shadcn/ui registry, with the entry for the chosen style and radius |
36
+
37
+ A name that does not exist is answered with the closest names, so a typo resolves in one turn. Names that clash with JavaScript or browser globals, like `map` or `file`, come back with the `Icon` suffix (`MapIcon`).
38
+
39
+ More in the [coolicons repository](https://github.com/krystonschwarze/coolicons#readme). MIT license.
package/dist/core.js ADDED
@@ -0,0 +1,163 @@
1
+ import { readFileSync } from "node:fs";
2
+
3
+ export const STYLES = ["line", "duocolor", "duotone", "fill", "bulk"];
4
+ export const RADII = ["sharp", "regular", "round"];
5
+ export const STROKED = new Set(["line", "duocolor", "duotone"]);
6
+ export const SITE = "https://coolicons.cool";
7
+
8
+ const read = (file) => JSON.parse(readFileSync(new URL(`./data/${file}`, import.meta.url), "utf8"));
9
+
10
+ let set;
11
+ const chunks = new Map();
12
+ let byName;
13
+
14
+ export function iconSet() {
15
+ set ??= read("index.json");
16
+ return set;
17
+ }
18
+
19
+ function lookup() {
20
+ byName ??= new Map(iconSet().icons.map((icon) => [icon.name, icon]));
21
+ return byName;
22
+ }
23
+
24
+ export class LookupError extends Error {
25
+ constructor(message, suggestions = []) {
26
+ super(message);
27
+ this.suggestions = suggestions;
28
+ }
29
+ }
30
+
31
+ export function toName(input) {
32
+ return String(input)
33
+ .trim()
34
+ .replace(/Icon$/, "")
35
+ .replace(/([a-z0-9])([A-Z])/g, "$1-$2")
36
+ .replace(/[\s_]+/g, "-")
37
+ .toLowerCase();
38
+ }
39
+
40
+ export function findIcon(input) {
41
+ const name = toName(input);
42
+ const icon = lookup().get(name);
43
+ if (icon) return icon;
44
+ const suggestions = suggest(name);
45
+ throw new LookupError(
46
+ `No coolicons icon is named "${name}".${suggestions.length ? ` Did you mean ${suggestions.join(", ")}?` : ""}`,
47
+ suggestions,
48
+ );
49
+ }
50
+
51
+ export function checkVariant(style = "line", radius = "regular") {
52
+ if (!STYLES.includes(style)) throw new LookupError(`Unknown style "${style}". Styles: ${STYLES.join(", ")}.`);
53
+ if (!RADII.includes(radius)) throw new LookupError(`Unknown radius "${radius}". Radii: ${RADII.join(", ")}.`);
54
+ return { style, radius };
55
+ }
56
+
57
+ function scoreIcon(icon, terms) {
58
+ let total = 0;
59
+ const tokens = icon.name.split("-");
60
+ const groups = icon.category.toLowerCase().split(/[^a-z0-9]+/);
61
+ for (const term of terms) {
62
+ let best = 0;
63
+ const exact = icon.keywords.indexOf(term);
64
+ const prefix = icon.keywords.findIndex((word) => word.startsWith(term));
65
+ if (icon.name === term) best = 100;
66
+ else if (icon.name.startsWith(term)) best = 80;
67
+ else if (tokens.includes(term)) best = 70;
68
+ else if (tokens.some((token) => token.startsWith(term))) best = 55;
69
+ else if ((term.length > 3 || term.includes("-")) && icon.name.includes(term)) best = 40;
70
+ else if (exact >= 0) best = 35 - Math.min(exact, 9);
71
+ else if (groups.includes(term)) best = 30;
72
+ else if (prefix >= 0) best = 25 - Math.min(prefix, 9);
73
+ else if (icon.category.toLowerCase().includes(term)) best = 15;
74
+ if (!best) return 0;
75
+ total += best;
76
+ }
77
+ return total;
78
+ }
79
+
80
+ export function search(query, limit = 10) {
81
+ const terms = String(query).toLowerCase().trim().split(/\s+/).filter(Boolean);
82
+ if (!terms.length) return [];
83
+ return iconSet()
84
+ .icons.map((icon) => ({ icon, rank: scoreIcon(icon, terms) }))
85
+ .filter((entry) => entry.rank)
86
+ .sort((a, b) => b.rank - a.rank || a.icon.name.length - b.icon.name.length || a.icon.name.localeCompare(b.icon.name))
87
+ .slice(0, limit)
88
+ .map((entry) => entry.icon);
89
+ }
90
+
91
+ function distance(a, b) {
92
+ const d = Array.from({ length: a.length + 1 }, (_, i) => Array.from({ length: b.length + 1 }, (_, j) => (i === 0 ? j : j === 0 ? i : 0)));
93
+ for (let i = 1; i <= a.length; i++) {
94
+ for (let j = 1; j <= b.length; j++) {
95
+ const cost = a[i - 1] === b[j - 1] ? 0 : 1;
96
+ d[i][j] = Math.min(d[i - 1][j] + 1, d[i][j - 1] + 1, d[i - 1][j - 1] + cost);
97
+ if (i > 1 && j > 1 && a[i - 1] === b[j - 2] && a[i - 2] === b[j - 1]) d[i][j] = Math.min(d[i][j], d[i - 2][j - 2] + 1);
98
+ }
99
+ }
100
+ return d[a.length][b.length];
101
+ }
102
+
103
+ export function suggest(input, limit = 5) {
104
+ const name = toName(input);
105
+ if (!name) return [];
106
+ const found = search(name.replaceAll("-", " "), limit).map((icon) => icon.name);
107
+ if (found.length >= limit) return found;
108
+ const near = iconSet()
109
+ .icons.map((icon) => ({ name: icon.name, cost: distance(name, icon.name) }))
110
+ .filter((entry) => entry.cost <= Math.max(2, Math.floor(name.length / 3)) && !found.includes(entry.name))
111
+ .sort((a, b) => a.cost - b.cost || a.name.localeCompare(b.name))
112
+ .map((entry) => entry.name);
113
+ return [...found, ...near].slice(0, limit);
114
+ }
115
+
116
+ export function component(icon) {
117
+ const pascal = icon.name
118
+ .split("-")
119
+ .map((part) => part.charAt(0).toUpperCase() + part.slice(1))
120
+ .join("");
121
+ return Object.hasOwn(iconSet().clashes, icon.name) ? `${pascal}Icon` : pascal;
122
+ }
123
+
124
+ export function svg(input, { style = "line", radius = "regular", size = 24, strokeWidth = 2 } = {}) {
125
+ const icon = findIcon(input);
126
+ checkVariant(style, radius);
127
+ const key = `${style}-${radius}`;
128
+ if (!chunks.has(key)) chunks.set(key, read(`${key}.json`));
129
+ let inner = chunks.get(key)[icon.name];
130
+ if (STROKED.has(style) && Number(strokeWidth) !== 2) inner = inner.replaceAll('stroke-width="2"', `stroke-width="${strokeWidth}"`);
131
+ return `<svg width="${size}" height="${size}" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">${inner}</svg>\n`;
132
+ }
133
+
134
+ const entry = (style, radius) => (style === "line" && radius === "regular" ? "" : radius === "regular" ? `/${style}` : `/${style}/${radius}`);
135
+
136
+ export function registryItem(icon, style = "line", radius = "regular") {
137
+ return [style === "line" && radius === "regular" ? "" : style, radius === "regular" ? "" : radius, icon.name].filter(Boolean).join("/");
138
+ }
139
+
140
+ export function usage(inputs, { framework = "react", style = "line", radius = "regular" } = {}) {
141
+ checkVariant(style, radius);
142
+ const icons = [inputs].flat().map(findIcon);
143
+ const names = icons.map(component);
144
+ if (framework === "react" || framework === "vue") {
145
+ const from = `@coolicons/${framework}${entry(style, radius)}`;
146
+ const imports = `import { ${names.join(", ")} } from "${from}";`;
147
+ const tags = names.map((name) => (framework === "react" ? `<${name} size={20} />` : `<${name} :size="20" />`)).join("\n");
148
+ const code = framework === "react" ? `${imports}\n\n${tags}` : `<script setup>\n${imports}\n</script>\n\n<template>\n${tags}\n</template>`;
149
+ return { install: `npm install @coolicons/${framework}`, code };
150
+ }
151
+ if (framework === "svg") {
152
+ return {
153
+ install: "npm install @coolicons/svg",
154
+ code: icons.map((icon) => `@coolicons/svg/${style}/${radius}/${icon.name}.svg`).join("\n"),
155
+ };
156
+ }
157
+ if (framework === "shadcn") {
158
+ const items = icons.map((icon) => `${SITE}/r/${registryItem(icon, style, radius)}.json`);
159
+ const files = icons.map((icon) => `components/icons/${registryItem(icon, style, radius)}.tsx`);
160
+ return { install: `npx shadcn@latest add ${items.join(" ")}`, code: `Adds ${files.join(", ")} exporting ${names.join(", ")}.` };
161
+ }
162
+ throw new LookupError(`Unknown framework "${framework}". Use react, vue, svg or shadcn.`);
163
+ }