@neuctra/ui-mcp 0.2.1 → 0.2.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.
Files changed (2) hide show
  1. package/package.json +8 -1
  2. package/src/server.mjs +20 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuctra/ui-mcp",
3
- "version": "0.2.1",
3
+ "version": "0.2.2",
4
4
  "description": "MCP server exposing the @neuctra/ui component registry (props, defaults, examples, theme tokens) so AI coding tools generate accurate Neuctra UI code.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -21,6 +21,13 @@
21
21
  "bin": {
22
22
  "neuctra-ui-mcp": "./bin/cli.mjs"
23
23
  },
24
+ "main": "./src/server.mjs",
25
+ "exports": {
26
+ ".": "./src/server.mjs",
27
+ "./data/components.json": "./data/components.json",
28
+ "./data/theme.json": "./data/theme.json",
29
+ "./package.json": "./package.json"
30
+ },
24
31
  "files": [
25
32
  "bin",
26
33
  "src",
package/src/server.mjs CHANGED
@@ -4,15 +4,22 @@ import { fileURLToPath } from "node:url";
4
4
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
5
5
  import { z } from "zod";
6
6
 
7
- const __dirname = path.dirname(fileURLToPath(import.meta.url));
8
- const DATA_DIR = path.resolve(__dirname, "..", "data");
9
-
10
- const registry = JSON.parse(
11
- fs.readFileSync(path.join(DATA_DIR, "components.json"), "utf8"),
12
- );
13
- const theme = JSON.parse(fs.readFileSync(path.join(DATA_DIR, "theme.json"), "utf8"));
14
-
15
- const componentsByName = new Map(registry.components.map((c) => [c.name, c]));
7
+ // Reads data/*.json from disk. Only works on runtimes with a filesystem
8
+ // (Node, Bun, Deno) — callers on edge/serverless runtimes without one
9
+ // (Cloudflare Workers) must import the JSON files themselves at build time
10
+ // and pass them into createServer({ registry, theme }) instead. Resolving
11
+ // __dirname is deferred inside this function (not module top-level) because
12
+ // import.meta.url is unavailable in some bundled edge runtimes even when
13
+ // this function itself is never called there.
14
+ function loadDataFromDisk() {
15
+ const __dirname = path.dirname(fileURLToPath(import.meta.url));
16
+ const DATA_DIR = path.resolve(__dirname, "..", "data");
17
+ const registry = JSON.parse(
18
+ fs.readFileSync(path.join(DATA_DIR, "components.json"), "utf8"),
19
+ );
20
+ const theme = JSON.parse(fs.readFileSync(path.join(DATA_DIR, "theme.json"), "utf8"));
21
+ return { registry, theme };
22
+ }
16
23
 
17
24
  function summarize(component) {
18
25
  return {
@@ -31,7 +38,10 @@ function matchesQuery(component, query) {
31
38
  return component.props.some((p) => p.name.toLowerCase().includes(q));
32
39
  }
33
40
 
34
- export function createServer() {
41
+ export function createServer(data) {
42
+ const { registry, theme } = data ?? loadDataFromDisk();
43
+ const componentsByName = new Map(registry.components.map((c) => [c.name, c]));
44
+
35
45
  const server = new McpServer({
36
46
  name: "neuctra-ui",
37
47
  version: "0.1.0",