@iconaut/mcp 1.7.5 → 2.0.0

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/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # @iconaut/mcp
2
2
 
3
- An [MCP](https://modelcontextprotocol.io) server for the 1,263 free Iconaut icons. It
3
+ An [MCP](https://modelcontextprotocol.io) server for the 1,297 free Iconaut icons. It
4
4
  lets a coding agent look an icon up instead of guessing its name, and hands back the exact SVG,
5
5
  the `iconaut-react` import and the shadcn/ui command.
6
6
 
package/icons.json.br CHANGED
Binary file
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@iconaut/mcp",
3
- "version": "1.7.5",
3
+ "version": "2.0.0",
4
4
  "description": "MCP server for the free Iconaut icons: search the set, get the SVG at its native size, get the React import and shadcn command.",
5
5
  "license": "MIT",
6
6
  "type": "module",
package/server.js CHANGED
@@ -40,6 +40,8 @@ function data() {
40
40
  i.nameTokens = i.name.split('-');
41
41
  i.kw = i.keywords.map((k) => k.toLowerCase());
42
42
  i.kwTokens = [...new Set(i.kw.flatMap((k) => k.split(/[\s-]+/)))];
43
+ i.squashName = squash(i.name);
44
+ i.kwSquash = i.kw.map(squash);
43
45
  byName.set(i.name, i);
44
46
  }
45
47
  const labels = Object.fromEntries(raw.categories.map((c) => [c.id, c.label]));
@@ -67,11 +69,17 @@ const nearestSize = (n, sizes) => sizes.reduce((a, b) => (Math.abs(b - n) < Math
67
69
  // query word has to match something, so "arrow left" does not return every arrow; when nothing
68
70
  // matches all of them, the best partial matches come back instead of nothing.
69
71
  const tokenize = (q) => String(q || '').toLowerCase().trim().split(/[\s,_/-]+/).filter(Boolean);
72
+ const squash = (s) => s.replace(/[\s_-]+/g, '');
70
73
 
71
- function scoreIcon(icon, q, words) {
74
+ // Words people add to an icon search that name the format, not the drawing: "settings icon",
75
+ // "arrow svg". They are only dropped when the query as typed finds nothing, so "svg" on its own
76
+ // still finds file-type-svg.
77
+ const FILLER = new Set(['icon', 'icons', 'svg', 'svgs']);
78
+
79
+ function scoreIcon(icon, q, words, loose = false) {
72
80
  let score = 0, matched = 0;
73
81
  const joined = words.join('-');
74
- if (icon.name === joined) score += 100;
82
+ if (icon.name === joined || (loose && icon.squashName === squash(joined))) score += 100;
75
83
  else if (icon.name.startsWith(joined)) score += 40;
76
84
  // Keywords are written closest-synonym first, so an exact hit early in the list is worth more:
77
85
  // "house" is home's first keyword and door's seventh.
@@ -83,6 +91,12 @@ function scoreIcon(icon, q, words) {
83
91
  else if (icon.nameTokens.some((t) => t.startsWith(w))) best = 7;
84
92
  if (icon.kwTokens.includes(w)) best = Math.max(best, 8);
85
93
  else if (w.length >= 3 && icon.kwTokens.some((t) => t.startsWith(w))) best = Math.max(best, 4);
94
+ // Loose pass only: a word typed without its hyphen or space, "arrowleft" for arrow-left,
95
+ // "thumbsup" for the keyword "thumbs up".
96
+ if (!best && loose && w.length >= 4) {
97
+ if (icon.squashName === w || icon.kwSquash.includes(w)) best = 10;
98
+ else if (icon.squashName.startsWith(w) || icon.kwSquash.some((k) => k.startsWith(w))) best = 5;
99
+ }
86
100
  if (!best && icon.category === w) best = 2;
87
101
  if (best) matched++;
88
102
  score += best;
@@ -90,17 +104,26 @@ function scoreIcon(icon, q, words) {
90
104
  return { score, matched };
91
105
  }
92
106
 
107
+ function rank(pool, words, loose) {
108
+ const q = words.join(' ');
109
+ return pool.map((i) => ({ i, ...scoreIcon(i, q, words, loose) })).filter((r) => r.score > 0);
110
+ }
111
+
93
112
  function search({ query = '', category, style, limit = 20 }) {
94
113
  const d = data();
95
114
  const words = tokenize(query);
96
- const q = words.join(' ');
97
115
  const max = Math.max(1, Math.min(100, Number(limit) || 20));
98
116
  let pool = d.icons;
99
117
  if (category) pool = pool.filter((i) => i.category === category);
100
118
  if (style) pool = pool.filter((i) => i.styles.includes(style));
101
119
  if (!words.length) return { results: pool.slice(0, max), total: pool.length, partial: false };
102
- const scored = pool.map((i) => ({ i, ...scoreIcon(i, q, words) })).filter((r) => r.score > 0);
103
- const full = scored.filter((r) => r.matched === words.length);
120
+ const scored = rank(pool, words, false);
121
+ let full = scored.filter((r) => r.matched === words.length);
122
+ // Nothing matched every word as typed: retry without filler words and with joined words
123
+ // allowed, before falling back to partial matches.
124
+ // A query of nothing but filler ("icon") has nothing left to retry with.
125
+ const kept = words.filter((w) => !FILLER.has(w));
126
+ if (!full.length && kept.length) full = rank(pool, kept, true).filter((r) => r.matched === kept.length);
104
127
  const use = full.length ? full : scored;
105
128
  use.sort((a, b) => b.score - a.score || b.matched - a.matched || a.i.name.length - b.i.name.length || a.i.name.localeCompare(b.i.name));
106
129
  return { results: use.slice(0, max).map((r) => r.i), total: use.length, partial: !full.length };