astralis-mcp 0.1.0 → 0.3.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 +6 -4
- package/package.json +5 -5
- package/server.mjs +136 -16
package/README.md
CHANGED
|
@@ -2,11 +2,11 @@
|
|
|
2
2
|
|
|
3
3
|
MCP server for [Astralis UI](https://astralis-zeta.vercel.app) — lets AI
|
|
4
4
|
coding agents (Claude Code, Cursor, …) look up the library's **current**
|
|
5
|
-
component APIs, full props tables, runnable demo source
|
|
6
|
-
instead of guessing from training data.
|
|
5
|
+
component APIs, full props tables, runnable demo source, theming guides and
|
|
6
|
+
block sources instead of guessing from training data.
|
|
7
7
|
|
|
8
|
-
Reads the docs site's machine-readable endpoints
|
|
9
|
-
from what the documentation actually
|
|
8
|
+
Reads the docs site's machine-readable endpoints and its block registry, so
|
|
9
|
+
answers can never drift from what the documentation actually ships.
|
|
10
10
|
|
|
11
11
|
## Setup
|
|
12
12
|
|
|
@@ -37,6 +37,8 @@ No install step — `npx` fetches and runs it on demand.
|
|
|
37
37
|
| `get_guide` | A guide page: `installation`, `quick-start`, `theming`, `colors`, `responsive`, `style-props`, `tokens` |
|
|
38
38
|
| `search_docs` | Full-text search across everything, with snippets |
|
|
39
39
|
| `get_theming` | The complete theming + design-token reference in one call |
|
|
40
|
+
| `list_blocks` | Every block — prebuilt page sections — with id, description, category and the components it composes. Filterable by category |
|
|
41
|
+
| `get_block` | One block's metadata plus the complete source of its files, ready to write into a project |
|
|
40
42
|
|
|
41
43
|
## Options
|
|
42
44
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astralis-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "MCP server exposing Astralis UI docs to AI coding agents — current component APIs, props tables, demo sources, and theming guides instead of hallucinated ones.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -33,11 +33,11 @@
|
|
|
33
33
|
"engines": {
|
|
34
34
|
"node": ">=18"
|
|
35
35
|
},
|
|
36
|
-
"scripts": {
|
|
37
|
-
"start": "node server.mjs"
|
|
38
|
-
},
|
|
39
36
|
"dependencies": {
|
|
40
37
|
"@modelcontextprotocol/sdk": "^1.0.0",
|
|
41
38
|
"zod": "^3.23.0"
|
|
39
|
+
},
|
|
40
|
+
"scripts": {
|
|
41
|
+
"start": "node server.mjs"
|
|
42
42
|
}
|
|
43
|
-
}
|
|
43
|
+
}
|
package/server.mjs
CHANGED
|
@@ -4,31 +4,56 @@
|
|
|
4
4
|
* instead of hallucinated ones.
|
|
5
5
|
*
|
|
6
6
|
* Data source: the deployed docs site's machine-readable endpoints
|
|
7
|
-
* (/llms.txt, /docs/components/*.md, /docs/*.md)
|
|
8
|
-
*
|
|
7
|
+
* (/llms.txt, /docs/components/*.md, /docs/*.md) and its block registry
|
|
8
|
+
* (/r/index.json, /r/{id}.json) — the same single pipeline that renders the
|
|
9
|
+
* human docs, so answers can never drift from the site.
|
|
9
10
|
* Point ASTRALIS_DOCS_URL at a local dev server (http://localhost:3000)
|
|
10
11
|
* when working on unpublished docs.
|
|
11
12
|
*
|
|
12
13
|
* Register in an MCP client:
|
|
13
14
|
* { "command": "npx", "args": ["-y", "astralis-mcp"] }
|
|
14
15
|
*/
|
|
16
|
+
import { readFileSync } from "node:fs";
|
|
15
17
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
16
18
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
17
19
|
import { z } from "zod";
|
|
18
20
|
|
|
21
|
+
/** Single source of truth for the version — the handshake can't drift from what npm publishes. */
|
|
22
|
+
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
|
|
23
|
+
|
|
19
24
|
const SITE = (process.env.ASTRALIS_DOCS_URL ?? "https://astralis-zeta.vercel.app").replace(/\/$/, "");
|
|
20
25
|
|
|
21
|
-
/*
|
|
26
|
+
/*
|
|
27
|
+
* A localhost docs URL means someone is editing docs live — never hand them a
|
|
28
|
+
* stale copy. A deployed site is cached, but only briefly, so a long-lived
|
|
29
|
+
* server still picks up doc updates without a restart.
|
|
30
|
+
*/
|
|
31
|
+
const isLocal = /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(?::|\/|$)/.test(SITE);
|
|
32
|
+
const TTL_MS = 5 * 60_000;
|
|
33
|
+
const FETCH_TIMEOUT_MS = 10_000;
|
|
34
|
+
|
|
35
|
+
/* ---------- data: fetched on demand, cached with a short TTL ---------- */
|
|
22
36
|
|
|
23
|
-
const cache = new Map();
|
|
37
|
+
const cache = new Map(); // path -> { text, at }
|
|
24
38
|
|
|
25
39
|
async function fetchText(path) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
40
|
+
const hit = cache.get(path);
|
|
41
|
+
if (hit && !isLocal && Date.now() - hit.at < TTL_MS) return hit.text;
|
|
42
|
+
|
|
43
|
+
const ctrl = new AbortController();
|
|
44
|
+
const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS);
|
|
45
|
+
try {
|
|
46
|
+
const res = await fetch(`${SITE}${path}`, { signal: ctrl.signal });
|
|
47
|
+
if (!res.ok) throw new Error(`${res.status} for ${SITE}${path}`);
|
|
48
|
+
const text = await res.text();
|
|
49
|
+
cache.set(path, { text, at: Date.now() });
|
|
50
|
+
return text;
|
|
51
|
+
} catch (err) {
|
|
52
|
+
if (err.name === "AbortError") throw new Error(`timed out after ${FETCH_TIMEOUT_MS}ms for ${SITE}${path}`);
|
|
53
|
+
throw err;
|
|
54
|
+
} finally {
|
|
55
|
+
clearTimeout(timer);
|
|
56
|
+
}
|
|
32
57
|
}
|
|
33
58
|
|
|
34
59
|
/** Parse llms.txt into [{slug, title, description, section, kind}]. */
|
|
@@ -52,6 +77,29 @@ async function listPages() {
|
|
|
52
77
|
return pages;
|
|
53
78
|
}
|
|
54
79
|
|
|
80
|
+
/**
|
|
81
|
+
* The block registry, served as static JSON by the same docs deploy
|
|
82
|
+
* (astralis-docs/scripts/gen-block-registry.mjs). Reusing fetchText means
|
|
83
|
+
* blocks get the same cache, timeout and local-dev override as the docs.
|
|
84
|
+
*/
|
|
85
|
+
async function fetchJson(path) {
|
|
86
|
+
return JSON.parse(await fetchText(path));
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
async function blockCatalogue() {
|
|
90
|
+
return (await fetchJson("/r/index.json")).blocks;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** One registry item, source included. Null when the id is unknown. */
|
|
94
|
+
async function blockItem(id) {
|
|
95
|
+
if (!/^[a-z0-9-]+$/.test(id)) return null;
|
|
96
|
+
try {
|
|
97
|
+
return await fetchJson(`/r/${id}.json`);
|
|
98
|
+
} catch {
|
|
99
|
+
return null;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
55
103
|
async function pageMarkdown(slug, kind) {
|
|
56
104
|
if (!/^[a-z0-9-]+$/.test(slug)) return null;
|
|
57
105
|
try {
|
|
@@ -68,11 +116,11 @@ const offline = (err) =>
|
|
|
68
116
|
|
|
69
117
|
/* ---------- server ---------- */
|
|
70
118
|
|
|
71
|
-
const server = new McpServer({ name: "astralis-ui", version:
|
|
119
|
+
const server = new McpServer({ name: "astralis-ui", version: pkg.version });
|
|
72
120
|
|
|
73
121
|
server.tool(
|
|
74
122
|
"list_components",
|
|
75
|
-
"List every Astralis UI docs page — all
|
|
123
|
+
"List every Astralis UI docs page — all components plus every guide — each with slug, one-line description, category, and kind (component | guide). Call this first to discover valid slugs.",
|
|
76
124
|
{},
|
|
77
125
|
async () => {
|
|
78
126
|
try {
|
|
@@ -101,14 +149,14 @@ server.tool(
|
|
|
101
149
|
|
|
102
150
|
server.tool(
|
|
103
151
|
"get_guide",
|
|
104
|
-
"One
|
|
152
|
+
"One Astralis guide page as markdown — e.g. installation, theming, tokens. Use a guide slug from list_components for the full set.",
|
|
105
153
|
{ slug: z.string().describe("Guide slug, e.g. 'installation', 'theming', 'tokens'") },
|
|
106
154
|
async ({ slug }) => {
|
|
107
155
|
try {
|
|
108
156
|
const md = await pageMarkdown(slug, "guide");
|
|
109
|
-
return md
|
|
110
|
-
|
|
111
|
-
|
|
157
|
+
if (md) return asText(md);
|
|
158
|
+
const guides = (await listPages()).filter((p) => p.kind === "guide").map((p) => p.slug);
|
|
159
|
+
return asError(`Unknown guide "${slug}". Valid guides: ${guides.join(", ")}.`);
|
|
112
160
|
} catch (err) {
|
|
113
161
|
return offline(err);
|
|
114
162
|
}
|
|
@@ -153,5 +201,77 @@ server.tool(
|
|
|
153
201
|
},
|
|
154
202
|
);
|
|
155
203
|
|
|
204
|
+
/* ---------- blocks ---------- */
|
|
205
|
+
|
|
206
|
+
server.tool(
|
|
207
|
+
"list_blocks",
|
|
208
|
+
"List every Astralis block — prebuilt page sections (hero, pricing, dashboard, login…) composed from Astralis UI components. Each entry has id, name, description, category and the components it composes. Call this first to discover valid block ids. Pass a category to narrow the list.",
|
|
209
|
+
{
|
|
210
|
+
category: z
|
|
211
|
+
.string()
|
|
212
|
+
.optional()
|
|
213
|
+
.describe("Optional filter, e.g. 'hero', 'pricing', 'dashboard', 'login'"),
|
|
214
|
+
},
|
|
215
|
+
async ({ category }) => {
|
|
216
|
+
try {
|
|
217
|
+
const blocks = await blockCatalogue();
|
|
218
|
+
if (!category) return asText(JSON.stringify(blocks, null, 2));
|
|
219
|
+
|
|
220
|
+
const wanted = category.toLowerCase();
|
|
221
|
+
const filtered = blocks.filter((b) => b.category === wanted);
|
|
222
|
+
if (filtered.length) return asText(JSON.stringify(filtered, null, 2));
|
|
223
|
+
|
|
224
|
+
const categories = [...new Set(blocks.map((b) => b.category))].sort();
|
|
225
|
+
return asError(`No blocks in category "${category}". Categories: ${categories.join(", ")}.`);
|
|
226
|
+
} catch (err) {
|
|
227
|
+
return offline(err);
|
|
228
|
+
}
|
|
229
|
+
},
|
|
230
|
+
);
|
|
231
|
+
|
|
232
|
+
server.tool(
|
|
233
|
+
"get_block",
|
|
234
|
+
"One Astralis block: its metadata plus the complete source of every file it contains, ready to write into a project. A block depends only on astralis-ui — no other packages, no Tailwind config, no per-block setup. Use an id from list_blocks.",
|
|
235
|
+
{ id: z.string().describe("Block id, e.g. 'hero-01', 'pricing-02', 'dashboard-03'") },
|
|
236
|
+
async ({ id }) => {
|
|
237
|
+
try {
|
|
238
|
+
const block = await blockItem(id);
|
|
239
|
+
if (!block) {
|
|
240
|
+
const ids = (await blockCatalogue()).map((b) => b.id);
|
|
241
|
+
return asError(`Unknown block "${id}". Valid ids: ${ids.join(", ")}.`);
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/*
|
|
245
|
+
* Markdown rather than raw JSON: the payload is mostly source code, and
|
|
246
|
+
* fenced blocks keep an agent from having to unescape a JSON string
|
|
247
|
+
* before it can write the file.
|
|
248
|
+
*/
|
|
249
|
+
const sections = [
|
|
250
|
+
`# ${block.name}`,
|
|
251
|
+
"",
|
|
252
|
+
block.description,
|
|
253
|
+
"",
|
|
254
|
+
`- **id** \`${block.id}\` · **category** \`${block.category}\``,
|
|
255
|
+
`- **exports** \`${block.component}\``,
|
|
256
|
+
`- **composes** ${block.uses.map((u) => `\`${u}\``).join(", ")}`,
|
|
257
|
+
`- **preview** ${SITE}/blocks/${block.id}`,
|
|
258
|
+
"",
|
|
259
|
+
`Install with \`astralis add ${block.id}\`, or write the files below yourself —`,
|
|
260
|
+
`they belong to the project once copied. The only dependency is \`astralis-ui\`.`,
|
|
261
|
+
"",
|
|
262
|
+
];
|
|
263
|
+
|
|
264
|
+
for (const file of block.contents) {
|
|
265
|
+
const lang = file.path.endsWith(".tsx") || file.path.endsWith(".ts") ? "tsx" : "";
|
|
266
|
+
sections.push(`## ${file.path}`, "", `\`\`\`${lang}`, file.content.trimEnd(), "```", "");
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return asText(sections.join("\n"));
|
|
270
|
+
} catch (err) {
|
|
271
|
+
return offline(err);
|
|
272
|
+
}
|
|
273
|
+
},
|
|
274
|
+
);
|
|
275
|
+
|
|
156
276
|
const transport = new StdioServerTransport();
|
|
157
277
|
await server.connect(transport);
|