@iconaut/mcp 0.0.0-stage → 1.7.3
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 +21 -0
- package/README.md +52 -2
- package/icons.json.br +0 -0
- package/package.json +43 -4
- package/server.js +317 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Iconaut
|
|
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,53 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @iconaut/mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
An [MCP](https://modelcontextprotocol.io) server for the 1,263 free Iconaut icons. It
|
|
4
|
+
lets a coding agent look an icon up instead of guessing its name, and hands back the exact SVG,
|
|
5
|
+
the `iconaut-react` import and the shadcn/ui command.
|
|
6
|
+
|
|
7
|
+
Everything runs locally from data bundled in the package: no network, no account, no API key.
|
|
8
|
+
|
|
9
|
+
## Set up
|
|
10
|
+
|
|
11
|
+
Claude Code:
|
|
12
|
+
|
|
13
|
+
```bash
|
|
14
|
+
claude mcp add iconaut -- npx -y @iconaut/mcp
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
Cursor, Windsurf, Claude Desktop and other clients take the same command in their MCP config:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"iconaut": { "command": "npx", "args": ["-y", "@iconaut/mcp"] }
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
## Tools
|
|
28
|
+
|
|
29
|
+
| Tool | What it does |
|
|
30
|
+
|---|---|
|
|
31
|
+
| `search_icons` | Search by name, keyword or meaning (`"settings"`, `"arrow left"`, `"delete"`). Filter by `category` or `style`. |
|
|
32
|
+
| `get_icon` | One icon by name: the SVG at 16, 20 or 24px in line, solid or duo, the React import, the shadcn command and the CDN URL. |
|
|
33
|
+
| `list_categories` | The 27 categories and how many icons each holds. |
|
|
34
|
+
|
|
35
|
+
## Tuned for each size
|
|
36
|
+
|
|
37
|
+
16, 20 and 24 are native sizes, each with its own stroke weight, so `get_icon` takes the size
|
|
38
|
+
the icon will be shown at. 16 also gets a simplified drawing that drops fine detail; 20 and 24
|
|
39
|
+
share the full drawing:
|
|
40
|
+
|
|
41
|
+
| size | drawing | stroke |
|
|
42
|
+
|---|---|---|
|
|
43
|
+
| 16 | compact | 1.25 |
|
|
44
|
+
| 20 | default | 1.5 |
|
|
45
|
+
| 24 | default | 1.75 |
|
|
46
|
+
|
|
47
|
+
## What is in here
|
|
48
|
+
|
|
49
|
+
The free, MIT-licensed set only: the same icons as [`iconaut-react`](https://www.npmjs.com/package/iconaut-react)
|
|
50
|
+
and [github.com/iconaut-design/icons](https://github.com/iconaut-design/icons), at the same
|
|
51
|
+
version. The Pro packs live in the [Figma plugin](https://iconaut.design).
|
|
52
|
+
|
|
53
|
+
Browse the set at [iconaut.design/icons](https://iconaut.design/icons).
|
package/icons.json.br
ADDED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iconaut/mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "1.7.3",
|
|
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
|
+
"license": "MIT",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"bin": {
|
|
8
|
+
"iconaut-mcp": "server.js"
|
|
9
|
+
},
|
|
10
|
+
"main": "server.js",
|
|
11
|
+
"files": [
|
|
12
|
+
"server.js",
|
|
13
|
+
"icons.json.br",
|
|
14
|
+
"README.md",
|
|
15
|
+
"LICENSE"
|
|
16
|
+
],
|
|
17
|
+
"engines": {
|
|
18
|
+
"node": ">=18"
|
|
19
|
+
},
|
|
20
|
+
"publishConfig": {
|
|
21
|
+
"access": "public"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"mcp",
|
|
25
|
+
"model-context-protocol",
|
|
26
|
+
"mcp-server",
|
|
27
|
+
"icons",
|
|
28
|
+
"svg-icons",
|
|
29
|
+
"icon-library",
|
|
30
|
+
"iconaut",
|
|
31
|
+
"react",
|
|
32
|
+
"shadcn",
|
|
33
|
+
"claude",
|
|
34
|
+
"cursor",
|
|
35
|
+
"ai"
|
|
36
|
+
],
|
|
37
|
+
"homepage": "https://iconaut.design",
|
|
38
|
+
"repository": {
|
|
39
|
+
"type": "git",
|
|
40
|
+
"url": "git+https://github.com/iconaut-design/icons.git"
|
|
41
|
+
},
|
|
42
|
+
"bugs": {
|
|
43
|
+
"url": "https://github.com/iconaut-design/icons/issues"
|
|
44
|
+
}
|
|
45
|
+
}
|
package/server.js
ADDED
|
@@ -0,0 +1,317 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// @iconaut/mcp: an MCP server over the free Iconaut icons.
|
|
3
|
+
//
|
|
4
|
+
// Hand-written, unlike the rest of this package: scripts/gen-mcp.mjs writes package.json,
|
|
5
|
+
// README.md, LICENSE and icons.json.br next to it, and leaves this file alone.
|
|
6
|
+
//
|
|
7
|
+
// What it is for. A coding agent asked for "a settings icon" otherwise guesses: an icon name
|
|
8
|
+
// that does not exist, or a lucide import in a project that uses Iconaut. These tools let it
|
|
9
|
+
// look the icon up instead, and hand back the exact SVG, React import and shadcn command.
|
|
10
|
+
//
|
|
11
|
+
// No dependencies on purpose. The MCP stdio transport is newline-delimited JSON-RPC 2.0, and
|
|
12
|
+
// the four methods a tools-only server answers (initialize, ping, tools/list, tools/call) fit
|
|
13
|
+
// in this file. Nothing to install means nothing to audit and nothing to go stale under it.
|
|
14
|
+
//
|
|
15
|
+
// Free set only. icons.json.br holds the 1,263 MIT icons and nothing else; the Pro icons are
|
|
16
|
+
// not in this package in any form, names included. scripts/mcp-verify.mjs checks that.
|
|
17
|
+
import { readFileSync, realpathSync } from 'node:fs';
|
|
18
|
+
import { brotliDecompressSync } from 'node:zlib';
|
|
19
|
+
import { dirname, join } from 'node:path';
|
|
20
|
+
import { fileURLToPath } from 'node:url';
|
|
21
|
+
import { createInterface } from 'node:readline';
|
|
22
|
+
|
|
23
|
+
const HERE = dirname(fileURLToPath(import.meta.url));
|
|
24
|
+
const PKG = JSON.parse(readFileSync(join(HERE, 'package.json'), 'utf8'));
|
|
25
|
+
const SITE = 'https://iconaut.design';
|
|
26
|
+
const CDN = 'https://cdn.jsdelivr.net/gh/iconaut-design/icons/icons';
|
|
27
|
+
const REACT_PKG = 'iconaut-react';
|
|
28
|
+
|
|
29
|
+
// Newest first. A client asking for one of these gets it back; anything else gets the newest,
|
|
30
|
+
// which the spec lets the client accept or disconnect over.
|
|
31
|
+
const PROTOCOLS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
32
|
+
|
|
33
|
+
// ── The catalog ────────────────────────────────────────────────────────────────────────────
|
|
34
|
+
let DATA = null;
|
|
35
|
+
function data() {
|
|
36
|
+
if (DATA) return DATA;
|
|
37
|
+
const raw = JSON.parse(brotliDecompressSync(readFileSync(join(HERE, 'icons.json.br'))).toString('utf8'));
|
|
38
|
+
const byName = new Map();
|
|
39
|
+
for (const i of raw.icons) {
|
|
40
|
+
i.nameTokens = i.name.split('-');
|
|
41
|
+
i.kw = i.keywords.map((k) => k.toLowerCase());
|
|
42
|
+
i.kwTokens = [...new Set(i.kw.flatMap((k) => k.split(/[\s-]+/)))];
|
|
43
|
+
byName.set(i.name, i);
|
|
44
|
+
}
|
|
45
|
+
const labels = Object.fromEntries(raw.categories.map((c) => [c.id, c.label]));
|
|
46
|
+
return (DATA = { ...raw, byName, labels });
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const pascal = (n) => n.split('-').map((p) => p[0].toUpperCase() + p.slice(1)).join('');
|
|
50
|
+
const SUFFIX = { line: '', solid: 'Solid', duo: 'Duo' };
|
|
51
|
+
const component = (name, style) => pascal(name) + SUFFIX[style];
|
|
52
|
+
const slug = (name, style) => name + (style === 'line' ? '' : '-' + style);
|
|
53
|
+
// The sizes come in two detail tiers (design/GRID.md): 16 draws a simplified version, 20 and 24
|
|
54
|
+
// share the full drawing and differ in stroke. Said plainly, because "default drawing" read to an
|
|
55
|
+
// agent as if 20px were not a native size at all.
|
|
56
|
+
function tierNote(size) {
|
|
57
|
+
const d = data();
|
|
58
|
+
const tier = d.sizeTokens[size].tier;
|
|
59
|
+
const peers = d.sizes.filter((s) => s !== size && d.sizeTokens[s].tier === tier);
|
|
60
|
+
if (!peers.length) return `The ${size}px drawing, simplified for small sizes`;
|
|
61
|
+
return `The full drawing, shared with ${peers.map((s) => s + 'px').join(' and ')}`;
|
|
62
|
+
}
|
|
63
|
+
const nearestSize = (n, sizes) => sizes.reduce((a, b) => (Math.abs(b - n) < Math.abs(a - n) ? b : a));
|
|
64
|
+
|
|
65
|
+
// ── Search ─────────────────────────────────────────────────────────────────────────────────
|
|
66
|
+
// Ranked by where the words land: the name beats a keyword, a whole word beats a prefix. Every
|
|
67
|
+
// query word has to match something, so "arrow left" does not return every arrow; when nothing
|
|
68
|
+
// matches all of them, the best partial matches come back instead of nothing.
|
|
69
|
+
const tokenize = (q) => String(q || '').toLowerCase().trim().split(/[\s,_/-]+/).filter(Boolean);
|
|
70
|
+
|
|
71
|
+
function scoreIcon(icon, q, words) {
|
|
72
|
+
let score = 0, matched = 0;
|
|
73
|
+
const joined = words.join('-');
|
|
74
|
+
if (icon.name === joined) score += 100;
|
|
75
|
+
else if (icon.name.startsWith(joined)) score += 40;
|
|
76
|
+
// Keywords are written closest-synonym first, so an exact hit early in the list is worth more:
|
|
77
|
+
// "house" is home's first keyword and door's seventh.
|
|
78
|
+
const at = icon.kw.indexOf(q);
|
|
79
|
+
if (at >= 0) score += 30 - Math.min(at, 10) * 2;
|
|
80
|
+
for (const w of words) {
|
|
81
|
+
let best = 0;
|
|
82
|
+
if (icon.nameTokens.includes(w)) best = 12;
|
|
83
|
+
else if (icon.nameTokens.some((t) => t.startsWith(w))) best = 7;
|
|
84
|
+
if (icon.kwTokens.includes(w)) best = Math.max(best, 8);
|
|
85
|
+
else if (w.length >= 3 && icon.kwTokens.some((t) => t.startsWith(w))) best = Math.max(best, 4);
|
|
86
|
+
if (!best && icon.category === w) best = 2;
|
|
87
|
+
if (best) matched++;
|
|
88
|
+
score += best;
|
|
89
|
+
}
|
|
90
|
+
return { score, matched };
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
function search({ query = '', category, style, limit = 20 }) {
|
|
94
|
+
const d = data();
|
|
95
|
+
const words = tokenize(query);
|
|
96
|
+
const q = words.join(' ');
|
|
97
|
+
const max = Math.max(1, Math.min(100, Number(limit) || 20));
|
|
98
|
+
let pool = d.icons;
|
|
99
|
+
if (category) pool = pool.filter((i) => i.category === category);
|
|
100
|
+
if (style) pool = pool.filter((i) => i.styles.includes(style));
|
|
101
|
+
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);
|
|
104
|
+
const use = full.length ? full : scored;
|
|
105
|
+
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
|
+
return { results: use.slice(0, max).map((r) => r.i), total: use.length, partial: !full.length };
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
// Closest names for a lookup that missed: shared words first, then edit distance.
|
|
110
|
+
function suggest(name) {
|
|
111
|
+
const d = data();
|
|
112
|
+
const words = tokenize(name);
|
|
113
|
+
const found = search({ query: words.join(' '), limit: 5 });
|
|
114
|
+
if (found.results.length && !found.partial) return found.results.map((i) => i.name);
|
|
115
|
+
const dist = (a, b) => {
|
|
116
|
+
const m = Array.from({ length: b.length + 1 }, (_, j) => j);
|
|
117
|
+
for (let i = 1; i <= a.length; i++) {
|
|
118
|
+
let prev = m[0]; m[0] = i;
|
|
119
|
+
for (let j = 1; j <= b.length; j++) {
|
|
120
|
+
const t = m[j];
|
|
121
|
+
m[j] = Math.min(m[j] + 1, m[j - 1] + 1, prev + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
122
|
+
prev = t;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
return m[b.length];
|
|
126
|
+
};
|
|
127
|
+
return d.icons.map((i) => [i.name, dist(name, i.name)]).sort((a, b) => a[1] - b[1]).slice(0, 5).map((x) => x[0]);
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
// ── Tools ──────────────────────────────────────────────────────────────────────────────────
|
|
131
|
+
const STYLE_ENUM = ['line', 'solid', 'duo'];
|
|
132
|
+
const TOOLS = [
|
|
133
|
+
{
|
|
134
|
+
name: 'search_icons',
|
|
135
|
+
title: 'Search Iconaut icons',
|
|
136
|
+
description:
|
|
137
|
+
'Search the free Iconaut icon set (MIT) by name, keyword or meaning, e.g. "settings", ' +
|
|
138
|
+
'"arrow left", "delete", "notification". Returns icon names ranked by relevance, with ' +
|
|
139
|
+
'their category, the styles each comes in (line, solid, duo) and the React component ' +
|
|
140
|
+
'names. Call this before using an icon name you have not looked up: guessed names often ' +
|
|
141
|
+
'do not exist. Leave query empty and pass a category to list that category.',
|
|
142
|
+
inputSchema: {
|
|
143
|
+
type: 'object',
|
|
144
|
+
properties: {
|
|
145
|
+
query: { type: 'string', description: 'Words to search for. Empty lists everything (narrow it with category).' },
|
|
146
|
+
category: { type: 'string', description: 'Only icons in this category id (see list_categories).' },
|
|
147
|
+
style: { type: 'string', enum: STYLE_ENUM, description: 'Only icons that come in this style. Marks like arrows and check have no duo.' },
|
|
148
|
+
limit: { type: 'integer', minimum: 1, maximum: 100, default: 20, description: 'How many results to return.' },
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
152
|
+
},
|
|
153
|
+
{
|
|
154
|
+
name: 'get_icon',
|
|
155
|
+
title: 'Get an Iconaut icon',
|
|
156
|
+
description:
|
|
157
|
+
'Get one Iconaut icon by its exact name: the SVG source at a native size, the iconaut-react ' +
|
|
158
|
+
'import, the shadcn/ui registry command and the CDN URL. 16, 20 and 24 are native sizes, each ' +
|
|
159
|
+
'with its own stroke weight; 16 is also a simplified drawing with less detail, while 20 and 24 ' +
|
|
160
|
+
'share the full drawing. Ask for the size the icon will be shown at. ' +
|
|
161
|
+
'Colors come from currentColor.',
|
|
162
|
+
inputSchema: {
|
|
163
|
+
type: 'object',
|
|
164
|
+
properties: {
|
|
165
|
+
name: { type: 'string', description: 'Exact icon name, e.g. "settings" or "arrow-left". Find it with search_icons.' },
|
|
166
|
+
style: { type: 'string', enum: STYLE_ENUM, default: 'line', description: 'line (stroked), solid (filled) or duo (25% tint under the line).' },
|
|
167
|
+
size: { type: 'integer', default: 24, description: 'Pixel size. 16, 20 and 24 are native sizes; any other value returns the nearest one.' },
|
|
168
|
+
},
|
|
169
|
+
required: ['name'],
|
|
170
|
+
},
|
|
171
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: 'list_categories',
|
|
175
|
+
title: 'List Iconaut categories',
|
|
176
|
+
description: 'List the categories of the free Iconaut icon set, with how many icons each holds.',
|
|
177
|
+
inputSchema: { type: 'object', properties: {} },
|
|
178
|
+
annotations: { readOnlyHint: true, openWorldHint: false },
|
|
179
|
+
},
|
|
180
|
+
];
|
|
181
|
+
|
|
182
|
+
class ToolError extends Error {}
|
|
183
|
+
|
|
184
|
+
const line = (i) =>
|
|
185
|
+
`- ${i.name} (${i.category}; ${i.styles.join(', ')}) → ${i.styles.map((s) => component(i.name, s)).join(', ')}` +
|
|
186
|
+
(i.keywords.length ? `\n keywords: ${i.keywords.slice(0, 8).join(', ')}` : '');
|
|
187
|
+
|
|
188
|
+
const handlers = {
|
|
189
|
+
search_icons(args) {
|
|
190
|
+
const d = data();
|
|
191
|
+
if (args.style && !STYLE_ENUM.includes(args.style)) throw new ToolError(`style must be one of ${STYLE_ENUM.join(', ')}`);
|
|
192
|
+
if (args.category && !d.labels[args.category]) {
|
|
193
|
+
throw new ToolError(`No category "${args.category}". Categories: ${Object.keys(d.labels).join(', ')}`);
|
|
194
|
+
}
|
|
195
|
+
const { results, total, partial } = search(args);
|
|
196
|
+
if (!results.length) {
|
|
197
|
+
return `No Iconaut icon matches "${args.query || ''}". Try a broader or different word (e.g. "delete" instead of "remove-item"), or list_categories.`;
|
|
198
|
+
}
|
|
199
|
+
const head = partial
|
|
200
|
+
? `No icon matches every word of "${args.query}"; the closest ${results.length} of ${total}:`
|
|
201
|
+
: `${results.length} of ${total} icon${total === 1 ? '' : 's'}${args.query ? ` for "${args.query}"` : ''}:`;
|
|
202
|
+
return `${head}\n${results.map(line).join('\n')}\n\nUse get_icon with a name for its SVG and import.`;
|
|
203
|
+
},
|
|
204
|
+
|
|
205
|
+
get_icon(args) {
|
|
206
|
+
const d = data();
|
|
207
|
+
const name = String(args.name || '').trim().toLowerCase();
|
|
208
|
+
if (!name) throw new ToolError('name is required.');
|
|
209
|
+
const icon = d.byName.get(name);
|
|
210
|
+
if (!icon) {
|
|
211
|
+
throw new ToolError(`No free Iconaut icon is named "${name}". Closest: ${suggest(name).join(', ')}.`);
|
|
212
|
+
}
|
|
213
|
+
const style = args.style || 'line';
|
|
214
|
+
if (!STYLE_ENUM.includes(style)) throw new ToolError(`style must be one of ${STYLE_ENUM.join(', ')}`);
|
|
215
|
+
if (!icon.styles.includes(style)) {
|
|
216
|
+
throw new ToolError(`"${name}" has no ${style} style; it comes in ${icon.styles.join(' and ')}.`);
|
|
217
|
+
}
|
|
218
|
+
const asked = args.size == null ? 24 : Number(args.size);
|
|
219
|
+
if (!Number.isFinite(asked) || asked <= 0) throw new ToolError('size must be a positive number.');
|
|
220
|
+
const size = d.sizes.includes(asked) ? asked : nearestSize(asked, d.sizes);
|
|
221
|
+
const svg = icon.svg[style][size].trimEnd();
|
|
222
|
+
const comp = component(name, style);
|
|
223
|
+
const tok = d.sizeTokens[size];
|
|
224
|
+
return [
|
|
225
|
+
`${name} · ${style} · ${size}px · category ${icon.category}`,
|
|
226
|
+
`${tierNote(size)}, tuned to a ${tok.stroke}px stroke at this size.`,
|
|
227
|
+
asked !== size ? `${asked}px is not a native size; this is the ${size}px drawing. Render it at ${asked}px by changing width and height.` : null,
|
|
228
|
+
'',
|
|
229
|
+
'SVG:',
|
|
230
|
+
svg,
|
|
231
|
+
'',
|
|
232
|
+
'React (npm i iconaut-react):',
|
|
233
|
+
`import { ${comp} } from "${REACT_PKG}";`,
|
|
234
|
+
`<${comp} size={${asked}} />`,
|
|
235
|
+
`Per-icon import: import ${comp} from "${REACT_PKG}/${slug(name, style)}";`,
|
|
236
|
+
'',
|
|
237
|
+
'shadcn/ui (copies the component into your project):',
|
|
238
|
+
`npx shadcn@latest add @iconaut/${slug(name, style)}`,
|
|
239
|
+
'',
|
|
240
|
+
`CDN: ${CDN}/${icon.category}/${name}/${size}/${style}.svg`,
|
|
241
|
+
`Page: ${SITE}/icon/${name}`,
|
|
242
|
+
style === 'duo' ? '\nDuo: the tint is the .secondary path (fill-opacity 0.25), the line is g.primary; style either with CSS.' : null,
|
|
243
|
+
].filter((x) => x !== null).join('\n');
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
list_categories() {
|
|
247
|
+
const d = data();
|
|
248
|
+
const counts = {};
|
|
249
|
+
for (const i of d.icons) counts[i.category] = (counts[i.category] || 0) + 1;
|
|
250
|
+
return `${d.icons.length} free icons in ${d.categories.length} categories:\n` +
|
|
251
|
+
d.categories.map((c) => `- ${c.id} (${c.label}): ${counts[c.id] || 0}`).join('\n');
|
|
252
|
+
},
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
// ── JSON-RPC over stdio ────────────────────────────────────────────────────────────────────
|
|
256
|
+
const send = (msg) => process.stdout.write(JSON.stringify({ jsonrpc: '2.0', ...msg }) + '\n');
|
|
257
|
+
const reply = (id, result) => send({ id, result });
|
|
258
|
+
const fail = (id, code, message) => send({ id, error: { code, message } });
|
|
259
|
+
|
|
260
|
+
function handle(msg) {
|
|
261
|
+
if (!msg || typeof msg !== 'object' || msg.jsonrpc !== '2.0' || typeof msg.method !== 'string') {
|
|
262
|
+
if (msg && msg.id !== undefined && msg.method === undefined) return; // a response to us; we send no requests
|
|
263
|
+
return fail(msg && msg.id !== undefined ? msg.id : null, -32600, 'Invalid Request');
|
|
264
|
+
}
|
|
265
|
+
const { id, method, params = {} } = msg;
|
|
266
|
+
const isNotification = id === undefined;
|
|
267
|
+
if (isNotification) return; // notifications/initialized, notifications/cancelled: nothing to do
|
|
268
|
+
|
|
269
|
+
switch (method) {
|
|
270
|
+
case 'initialize': {
|
|
271
|
+
const v = PROTOCOLS.includes(params.protocolVersion) ? params.protocolVersion : PROTOCOLS[0];
|
|
272
|
+
return reply(id, {
|
|
273
|
+
protocolVersion: v,
|
|
274
|
+
capabilities: { tools: { listChanged: false } },
|
|
275
|
+
serverInfo: { name: 'iconaut', title: 'Iconaut icons', version: PKG.version },
|
|
276
|
+
instructions:
|
|
277
|
+
'Iconaut is an icon set in line, solid and duotone on a 24px grid, with three native sizes (16, 20 and 24px), ' +
|
|
278
|
+
'each with its own stroke weight, and a simplified drawing at 16px. ' +
|
|
279
|
+
'This server covers the free MIT set. Look icons up with search_icons before naming one, then use get_icon ' +
|
|
280
|
+
'for the SVG or the iconaut-react import. Do not invent icon names.',
|
|
281
|
+
});
|
|
282
|
+
}
|
|
283
|
+
case 'ping':
|
|
284
|
+
return reply(id, {});
|
|
285
|
+
case 'tools/list':
|
|
286
|
+
return reply(id, { tools: TOOLS });
|
|
287
|
+
case 'tools/call': {
|
|
288
|
+
const fn = handlers[params.name];
|
|
289
|
+
if (!fn) return fail(id, -32602, `Unknown tool: ${params.name}`);
|
|
290
|
+
try {
|
|
291
|
+
const text = fn(params.arguments || {});
|
|
292
|
+
return reply(id, { content: [{ type: 'text', text }] });
|
|
293
|
+
} catch (e) {
|
|
294
|
+
if (e instanceof ToolError) return reply(id, { content: [{ type: 'text', text: e.message }], isError: true });
|
|
295
|
+
process.stderr.write(`iconaut-mcp: ${e.stack || e}\n`);
|
|
296
|
+
return fail(id, -32603, 'Internal error');
|
|
297
|
+
}
|
|
298
|
+
}
|
|
299
|
+
default:
|
|
300
|
+
return fail(id, -32601, `Method not found: ${method}`);
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
export { handlers, search, TOOLS, PROTOCOLS };
|
|
305
|
+
|
|
306
|
+
// Run as a server unless imported (the verifier imports the handlers directly as well).
|
|
307
|
+
if (process.argv[1] && fileURLToPath(import.meta.url) === realpathSync(process.argv[1])) {
|
|
308
|
+
const rl = createInterface({ input: process.stdin, crlfDelay: Infinity });
|
|
309
|
+
rl.on('line', (l) => {
|
|
310
|
+
if (!l.trim()) return;
|
|
311
|
+
let msg;
|
|
312
|
+
try { msg = JSON.parse(l); } catch { return fail(null, -32700, 'Parse error'); }
|
|
313
|
+
if (Array.isArray(msg)) return fail(null, -32600, 'Batches are not supported');
|
|
314
|
+
handle(msg);
|
|
315
|
+
});
|
|
316
|
+
rl.on('close', () => process.exit(0));
|
|
317
|
+
}
|