astralis-mcp 0.1.0 → 0.2.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/package.json +5 -5
- package/server.mjs +38 -14
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "astralis-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.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
|
@@ -12,23 +12,47 @@
|
|
|
12
12
|
* Register in an MCP client:
|
|
13
13
|
* { "command": "npx", "args": ["-y", "astralis-mcp"] }
|
|
14
14
|
*/
|
|
15
|
+
import { readFileSync } from "node:fs";
|
|
15
16
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
16
17
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
17
18
|
import { z } from "zod";
|
|
18
19
|
|
|
20
|
+
/** Single source of truth for the version — the handshake can't drift from what npm publishes. */
|
|
21
|
+
const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url), "utf8"));
|
|
22
|
+
|
|
19
23
|
const SITE = (process.env.ASTRALIS_DOCS_URL ?? "https://astralis-zeta.vercel.app").replace(/\/$/, "");
|
|
20
24
|
|
|
21
|
-
/*
|
|
25
|
+
/*
|
|
26
|
+
* A localhost docs URL means someone is editing docs live — never hand them a
|
|
27
|
+
* stale copy. A deployed site is cached, but only briefly, so a long-lived
|
|
28
|
+
* server still picks up doc updates without a restart.
|
|
29
|
+
*/
|
|
30
|
+
const isLocal = /^https?:\/\/(localhost|127\.0\.0\.1|\[::1\])(?::|\/|$)/.test(SITE);
|
|
31
|
+
const TTL_MS = 5 * 60_000;
|
|
32
|
+
const FETCH_TIMEOUT_MS = 10_000;
|
|
33
|
+
|
|
34
|
+
/* ---------- data: fetched on demand, cached with a short TTL ---------- */
|
|
22
35
|
|
|
23
|
-
const cache = new Map();
|
|
36
|
+
const cache = new Map(); // path -> { text, at }
|
|
24
37
|
|
|
25
38
|
async function fetchText(path) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
39
|
+
const hit = cache.get(path);
|
|
40
|
+
if (hit && !isLocal && Date.now() - hit.at < TTL_MS) return hit.text;
|
|
41
|
+
|
|
42
|
+
const ctrl = new AbortController();
|
|
43
|
+
const timer = setTimeout(() => ctrl.abort(), FETCH_TIMEOUT_MS);
|
|
44
|
+
try {
|
|
45
|
+
const res = await fetch(`${SITE}${path}`, { signal: ctrl.signal });
|
|
46
|
+
if (!res.ok) throw new Error(`${res.status} for ${SITE}${path}`);
|
|
47
|
+
const text = await res.text();
|
|
48
|
+
cache.set(path, { text, at: Date.now() });
|
|
49
|
+
return text;
|
|
50
|
+
} catch (err) {
|
|
51
|
+
if (err.name === "AbortError") throw new Error(`timed out after ${FETCH_TIMEOUT_MS}ms for ${SITE}${path}`);
|
|
52
|
+
throw err;
|
|
53
|
+
} finally {
|
|
54
|
+
clearTimeout(timer);
|
|
55
|
+
}
|
|
32
56
|
}
|
|
33
57
|
|
|
34
58
|
/** Parse llms.txt into [{slug, title, description, section, kind}]. */
|
|
@@ -68,11 +92,11 @@ const offline = (err) =>
|
|
|
68
92
|
|
|
69
93
|
/* ---------- server ---------- */
|
|
70
94
|
|
|
71
|
-
const server = new McpServer({ name: "astralis-ui", version:
|
|
95
|
+
const server = new McpServer({ name: "astralis-ui", version: pkg.version });
|
|
72
96
|
|
|
73
97
|
server.tool(
|
|
74
98
|
"list_components",
|
|
75
|
-
"List every Astralis UI docs page — all
|
|
99
|
+
"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
100
|
{},
|
|
77
101
|
async () => {
|
|
78
102
|
try {
|
|
@@ -101,14 +125,14 @@ server.tool(
|
|
|
101
125
|
|
|
102
126
|
server.tool(
|
|
103
127
|
"get_guide",
|
|
104
|
-
"One
|
|
128
|
+
"One Astralis guide page as markdown — e.g. installation, theming, tokens. Use a guide slug from list_components for the full set.",
|
|
105
129
|
{ slug: z.string().describe("Guide slug, e.g. 'installation', 'theming', 'tokens'") },
|
|
106
130
|
async ({ slug }) => {
|
|
107
131
|
try {
|
|
108
132
|
const md = await pageMarkdown(slug, "guide");
|
|
109
|
-
return md
|
|
110
|
-
|
|
111
|
-
|
|
133
|
+
if (md) return asText(md);
|
|
134
|
+
const guides = (await listPages()).filter((p) => p.kind === "guide").map((p) => p.slug);
|
|
135
|
+
return asError(`Unknown guide "${slug}". Valid guides: ${guides.join(", ")}.`);
|
|
112
136
|
} catch (err) {
|
|
113
137
|
return offline(err);
|
|
114
138
|
}
|