@mavonengine/cli 0.0.7 → 0.0.8

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
@@ -391,7 +391,7 @@ Plugin tools:
391
391
  | `available_plugins` | The official plugins from [`mavonengine plugins`](#mavonengine-plugins): what each does, where it runs, the command that installs it, and whether the project already has it |
392
392
  | `plugin_readme` | The README of one of them as Markdown: its options, how a game hooks into it and its limits |
393
393
 
394
- With these an assistant can suggest a plugin instead of building what one already does, and set it up from its readme. It can't install one: every tool is read-only, so it hands you the command. `available_plugins` and `plugin_readme` read the list and the readmes from GitHub when they are used; `--plugins-url` or `MAVONENGINE_PLUGINS_URL` points them at another list and `--no-plugin-list` leaves them out.
394
+ With these an assistant can suggest a plugin instead of building what one already does, and set it up from its readme. It can't install one: these tools are read-only, so it hands you the command. `available_plugins` and `plugin_readme` read the list and the readmes from GitHub when they are used; `--plugins-url` or `MAVONENGINE_PLUGINS_URL` points them at another list and `--no-plugin-list` leaves them out.
395
395
 
396
396
  Database tools, for the project's database plugin such as [`@mavonengine/sqlite`](https://github.com/MavonEngine/Core/tree/main/packages/plugins/sqlite):
397
397
 
@@ -413,7 +413,15 @@ They connect to the site the first time one is used, so the other tools also wor
413
413
 
414
414
  Client tools take a `clientId` from `list_clients`. Without one they ask the only open tab, or the only one not running the editor.
415
415
 
416
- Every tool is read-only. It takes `--host`, `--port`, `--url` and `--token` like the dashboard, where `--url` is the server's base URL (`http://localhost:8050`). When Vite serves the client on its own port instead of through the game server, pass `--client-url`, e.g. `http://localhost:5173`.
416
+ Tools from your project's plugins, while the client's dev server runs:
417
+
418
+ | Tool | |
419
+ | --- | --- |
420
+ | `<plugin>_<tool>` | Whatever the project's plugins offer through their [dev entries](#dev-entries), e.g. `kenney_search_packs` and `kenney_import` from `@mavonengine/kenney`, or `mail_inbox` and `mail_read` from `@mavonengine/mail`. Each says in its description what it does |
421
+
422
+ They appear when the dev server starts and go when plugins are removed: `mavonengine mcp` asks the dev server every few seconds and tells your assistant when the list changes. Unlike the tools above, a plugin's tool may change your project, e.g. copy files into it or edit `mavonengine.json`. Each says whether it does, and your MCP client asks you before running one that changes something. `--read-only` leaves those out.
423
+
424
+ The engine's own tools are read-only. It takes `--host`, `--port`, `--url` and `--token` like the dashboard, where `--url` is the server's base URL (`http://localhost:8050`). When Vite serves the client on its own port instead of through the game server, pass `--client-url`, e.g. `http://localhost:5173`.
417
425
 
418
426
  The server scene and entity tools read `GET /api/game/dev/*` on the game server. Those routes are only registered when `NODE_ENV` is not `production`: a metrics token does not turn them on there. Otherwise they follow the [server access](#server-access) rules of the metrics endpoint.
419
427
 
@@ -452,6 +460,8 @@ To let `compare_entity` match your own player with the server's, set `game.local
452
460
 
453
461
  - `target`: `client`, `server` or `both`. The matching entries are required.
454
462
  - `assets`: paths relative to `dir` (default `assets`). They are served at `/plugins/<package>/<path>`: all of them in dev, and only the shared ones and those of used prefabs in a release.
463
+ - `dev`: optional, for any target. An entry that runs in the client's Vite dev server, see [Dev entries](#dev-entries).
464
+ - `reloadOnOptions`: default `true`. Set it to `false` when the plugin changes its own `options` while the editor is open and its client picks up the change without a reload.
455
465
 
456
466
  Each entry default-exports the plugin. Every hook gets the plugin's context last, which carries `package`, `options`, `game` and `logger`.
457
467
 
@@ -460,11 +470,19 @@ Each entry default-exports the plugin. Every hook gets the plugin's context last
460
470
  import { defineClientPlugin } from '@mavonengine/core/Plugins/types'
461
471
 
462
472
  export default defineClientPlugin({
463
- assets: ctx => [{ name: 'tree', type: 'gltfModel', path: ctx.assetUrl('models/tree.glb') }],
473
+ assets: ctx => [
474
+ {
475
+ name: 'tree',
476
+ type: 'gltfModel',
477
+ path: ctx.assetUrl('models/tree.glb')
478
+ }
479
+ ],
464
480
  setup(ctx) {
465
481
  ctx.registerPrefab({
466
482
  name: 'Tree',
467
- spawn: position => ({ object: new Tree(position) }),
483
+ spawn: position => ({
484
+ object: new Tree(position)
485
+ }),
468
486
  })
469
487
  },
470
488
  update(delta, ctx) {},
@@ -494,6 +512,77 @@ export default defineServerPlugin({
494
512
 
495
513
  A hook that throws is logged and turned off for that plugin, and the game keeps running.
496
514
 
515
+ ### Dev entries
516
+
517
+ A plugin's `dev` entry runs in the client's Vite dev server, only in dev: tooling for the editor that has to work with the project's files, like downloading something and writing it into `client/public/`. It is never part of a build, and the game server never loads it.
518
+
519
+ ```ts
520
+ // dev.ts
521
+ import { mkdirSync } from 'node:fs'
522
+ import { defineDevPlugin } from '@mavonengine/core/Plugins/types'
523
+
524
+ export default defineDevPlugin({
525
+ setup(ctx) {
526
+ mkdirSync(ctx.dataDir, { recursive: true })
527
+ },
528
+ // Answers under /__mavonengine/plugins/<package>/, with that prefix taken off req.url
529
+ middleware: ctx => (req, res, next) => {
530
+ if (req.url !== '/status')
531
+ return next() // 404
532
+ res.setHeader('Content-Type', 'application/json')
533
+ res.end(JSON.stringify({ options: ctx.options }))
534
+ },
535
+ destroy(ctx) {},
536
+ })
537
+ ```
538
+
539
+ The client side calls it with `` fetch(`${devPluginBase(ctx.package)}status`) ``, using `devPluginBase` from `@mavonengine/core/Plugins/types`. Only requests from localhost reach the middleware, and requests that change something (anything but GET and HEAD) only when they come from the game's own page, so another site open in the browser can't make them. Paths in `req.url` come from the browser: resolve them with `resolveInside()` from `@mavonengine/core/Plugins/ProjectConfig` before reading or writing files.
540
+
541
+ The context has `package`, `options` (read from `mavonengine.json` on every access), `projectRoot`, `clientRoot`, `publicDir`, `logger`, and:
542
+
543
+ - `dataDir`: `.mavonengine/plugins/<package>/` in the project, for downloads and caches. The project's `.gitignore` leaves out `.mavonengine`, so nothing there is committed or shipped.
544
+ - `updateOptions(change)`: changes the plugin's `options` in `mavonengine.json`. Use it to record what should be committed with the project.
545
+
546
+ A dev entry can also give AI assistants tools, which [`mavonengine mcp`](#mavonengine-mcp) offers as `<plugin>_<tool>`: the package name without its scope, then the tool's name.
547
+
548
+ ```ts
549
+ export default defineDevPlugin({
550
+ mcpTools: ctx => [
551
+ {
552
+ name: 'add_tree', // my-plugin_add_tree
553
+ title: 'Add a tree',
554
+ description: 'Adds a tree to the list in the plugin\'s options. Use it when the user asks for more trees',
555
+ input: {
556
+ type: 'object',
557
+ properties: {
558
+ kind: {
559
+ type: 'string',
560
+ enum: ['pine', 'oak']
561
+ }
562
+ },
563
+ required: ['kind']
564
+ },
565
+ run: ({ kind }) => {
566
+ ctx.updateOptions((options) => {
567
+ options.trees = [
568
+ ...(options.trees as string[] ?? []),
569
+ kind
570
+ ]
571
+ })
572
+ return { trees: ctx.options.trees }
573
+ },
574
+ },
575
+ ],
576
+ })
577
+ ```
578
+
579
+ - `input` is the JSON Schema of the arguments, an object; `mavonengine mcp` turns away calls that don't match it. The arguments still come from a model, so check them in `run()` as you would any input, e.g. paths with `resolveInside()`.
580
+ - What `run()` returns goes to the assistant as JSON. What it throws is reported as the tool's error.
581
+ - Set `readOnly: true` on tools that change nothing; the rest are taken to change something, so assistants ask first and `mavonengine mcp --read-only` leaves them out. `destructive: true` marks one that deletes or overwrites what can't be had back, `openWorld: true` one that reaches outside the project, e.g. a website.
582
+ - The dev server lists them on `GET /__mavonengine/mcp/tools` and runs them on `POST /__mavonengine/mcp/tools/<name>` with `{ "arguments": … }`, only for requests from this machine and never for another site open in the browser.
583
+
584
+ Dev entries start with the dev server and restart when plugins are added, removed, turned on or off in `mavonengine.json`. Changing options doesn't restart them. One that fails to start is logged, and its URLs answer 404 with the reason.
585
+
497
586
  Guard a plugin's admin routes with `ctx.requireAdmin`, which asks for the server's [admin token](#admin-token), instead of giving the plugin a token of its own:
498
587
 
499
588
  ```ts
@@ -519,12 +608,20 @@ export default defineServerPlugin({
519
608
  icon: 'chat', // dashboard, activity, routes, plugin, database, users, logs, settings, chart, mail, chat, bell or lock
520
609
  children: [
521
610
  { label: 'Live', href: '#live' }, // an anchor on the page
522
- { label: 'Mutes', href: 'mutes', render: () => '<p>…</p>' }, // a sub page, /admin/chat/mutes/
611
+ {
612
+ label: 'Mutes',
613
+ href: 'mutes',
614
+ render: () => '<p>…</p>'
615
+ }, // a sub page, /admin/chat/mutes/
523
616
  ],
524
617
  render: req => ({
525
618
  html: '<div class="adm-page">…</div>',
526
- styles: [ctx.admin.url('chat/style.css')],
527
- scripts: [ctx.admin.url('chat/app.js')],
619
+ styles: [
620
+ ctx.admin.url('chat/style.css')
621
+ ],
622
+ scripts: [
623
+ ctx.admin.url('chat/app.js')
624
+ ],
528
625
  }),
529
626
  })
530
627
 
@@ -547,7 +644,9 @@ An auth plugin decides who may connect, before a client gets a player. [`@mavone
547
644
  export default defineClientPlugin({
548
645
  authorization: () => {
549
646
  const token = localStorage.getItem('session')
550
- return token ? `Bearer ${token}` : undefined
647
+ return token
648
+ ? `Bearer ${token}`
649
+ : undefined
551
650
  },
552
651
  })
553
652
  ```
@@ -586,7 +685,9 @@ Game.usePlugins(plugins)
586
685
 
587
686
  ```ts
588
687
  // server: the directory with mavonengine.json
589
- const server = new MyServer(logger, physicsWorld, { plugins: { root: projectRoot } })
688
+ const server = new MyServer(logger, physicsWorld, {
689
+ plugins: { root: projectRoot }
690
+ })
590
691
  await server.start()
591
692
  ```
592
693
 
@@ -1,12 +1,7 @@
1
1
  #!/usr/bin/env node
2
- var __defProp = Object.defineProperty;
3
- var __export = (target, all) => {
4
- for (var name in all)
5
- __defProp(target, name, { get: all[name], enumerable: true });
6
- };
7
2
 
8
3
  // package.json
9
- var version = "0.0.7";
4
+ var version = "0.0.8";
10
5
 
11
6
  // src/mcp/config.ts
12
7
  import { existsSync, readFileSync, writeFileSync } from "fs";
@@ -35,14 +30,16 @@ function writeMcpConfig(dir) {
35
30
  const servers = config.mcpServers && typeof config.mcpServers === "object" ? config.mcpServers : {};
36
31
  if (MCP_SERVER_NAME in servers)
37
32
  return false;
38
- config.mcpServers = { ...servers, [MCP_SERVER_NAME]: mcpServerEntry() };
33
+ config.mcpServers = {
34
+ ...servers,
35
+ [MCP_SERVER_NAME]: mcpServerEntry()
36
+ };
39
37
  writeFileSync(file, `${JSON.stringify(config, null, 2)}
40
38
  `);
41
39
  return true;
42
40
  }
43
41
 
44
42
  export {
45
- __export,
46
43
  version,
47
44
  DEFAULT_DOCS_URL,
48
45
  MCP_CONFIG_FILE,
@@ -22,15 +22,17 @@ function normalizeRegistry(raw, url) {
22
22
  if (!pkg)
23
23
  return [];
24
24
  const target = plugin.target === "client" || plugin.target === "server" || plugin.target === "both" ? plugin.target : void 0;
25
- return [{
26
- package: pkg,
27
- name: text(plugin.name) ?? pkg,
28
- description: text(plugin.description),
29
- target,
30
- engine: text(plugin.engine),
31
- homepage: text(plugin.homepage),
32
- readme: text(plugin.readme)
33
- }];
25
+ return [
26
+ {
27
+ package: pkg,
28
+ name: text(plugin.name) ?? pkg,
29
+ description: text(plugin.description),
30
+ target,
31
+ engine: text(plugin.engine),
32
+ homepage: text(plugin.homepage),
33
+ readme: text(plugin.readme)
34
+ }
35
+ ];
34
36
  })
35
37
  };
36
38
  }
@@ -46,12 +48,16 @@ async function fetchPluginReadme(plugin, { timeoutMs = 1e4, fetch = globalThis.f
46
48
  throw new PluginRegistryError(`The list has no readme for ${plugin.package}`);
47
49
  let res;
48
50
  try {
49
- res = await fetch(url, { cache: "no-store", signal: AbortSignal.timeout(timeoutMs) });
51
+ res = await fetch(url, {
52
+ cache: "no-store",
53
+ signal: AbortSignal.timeout(timeoutMs)
54
+ });
50
55
  } catch (err) {
51
56
  throw new PluginRegistryError(`Can't reach ${url}: ${err.message}`);
52
57
  }
53
- if (!res.ok)
58
+ if (!res.ok) {
54
59
  throw new PluginRegistryError(res.status === 404 ? `${url} was not found` : `${url} answered ${res.status} ${res.statusText}`);
60
+ }
55
61
  const markdown = await res.text();
56
62
  return markdown.length > MAX_REMOTE_README_CHARS ? `${markdown.slice(0, MAX_REMOTE_README_CHARS)}
57
63
 
@@ -60,7 +66,10 @@ async function fetchPluginReadme(plugin, { timeoutMs = 1e4, fetch = globalThis.f
60
66
  async function fetchPluginRegistry({ url = PLUGIN_REGISTRY_URL, timeoutMs = 1e4, fetch = globalThis.fetch } = {}) {
61
67
  let res;
62
68
  try {
63
- res = await fetch(url, { cache: "no-store", signal: AbortSignal.timeout(timeoutMs) });
69
+ res = await fetch(url, {
70
+ cache: "no-store",
71
+ signal: AbortSignal.timeout(timeoutMs)
72
+ });
64
73
  } catch (err) {
65
74
  throw new PluginRegistryError(`Can't reach ${url}: ${err.message}`);
66
75
  }
@@ -2,29 +2,14 @@
2
2
  import {
3
3
  DEFAULT_DOCS_URL,
4
4
  version
5
- } from "./chunk-3VVGSO5T.js";
5
+ } from "./chunk-33OMMYNV.js";
6
+ import {
7
+ READ_ONLY
8
+ } from "./chunk-WMXVMJDM.js";
6
9
 
7
10
  // src/mcp/docs.ts
8
11
  import { Client } from "@modelcontextprotocol/sdk/client/index.js";
9
- import { z as z2 } from "zod";
10
-
11
- // src/mcp/result.ts
12
12
  import { z } from "zod";
13
- var READ_ONLY = { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false };
14
- var LOG_LEVELS = ["error", "warn", "info", "http", "verbose", "debug", "silly"];
15
- var vec3 = z.object({ x: z.number(), y: z.number(), z: z.number() });
16
- function json(data) {
17
- return { content: [{ type: "text", text: JSON.stringify(data, null, 2) }] };
18
- }
19
- async function run(body) {
20
- try {
21
- return json(await body());
22
- } catch (err) {
23
- return { isError: true, content: [{ type: "text", text: err.message }] };
24
- }
25
- }
26
-
27
- // src/mcp/docs.ts
28
13
  var REQUEST_TIMEOUT_MS = 15e3;
29
14
  var DocsClient = class {
30
15
  constructor(url = DEFAULT_DOCS_URL, connect = connectHttp) {
@@ -65,7 +50,12 @@ function registerDocsTools(server, docs) {
65
50
  try {
66
51
  return await docs.call(tool, args);
67
52
  } catch (err) {
68
- return { isError: true, content: [{ type: "text", text: err.message }] };
53
+ return {
54
+ isError: true,
55
+ content: [
56
+ { type: "text", text: err.message }
57
+ ]
58
+ };
69
59
  }
70
60
  };
71
61
  server.registerTool("docs_list_pages", {
@@ -76,16 +66,14 @@ function registerDocsTools(server, docs) {
76
66
  server.registerTool("docs_get_page", {
77
67
  title: "Read a MavonEngine docs page",
78
68
  description: "One page of the MavonEngine documentation as Markdown, by its path from docs_list_pages (e.g. /networking/state-sync).",
79
- inputSchema: { path: z2.string().min(1).describe("Page path, e.g. /getting-started/installation") },
69
+ inputSchema: {
70
+ path: z.string().min(1).describe("Page path, e.g. /getting-started/installation")
71
+ },
80
72
  annotations: { ...READ_ONLY, openWorldHint: true }
81
73
  }, ({ path }) => forward("get-page", { path }));
82
74
  }
83
75
 
84
76
  export {
85
- READ_ONLY,
86
- LOG_LEVELS,
87
- vec3,
88
- run,
89
77
  DocsClient,
90
78
  registerDocsTools
91
79
  };
@@ -0,0 +1,10 @@
1
+ #!/usr/bin/env node
2
+ var __defProp = Object.defineProperty;
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, { get: all[name], enumerable: true });
6
+ };
7
+
8
+ export {
9
+ __export
10
+ };
@@ -0,0 +1,53 @@
1
+ #!/usr/bin/env node
2
+
3
+ // src/mcp/result.ts
4
+ import { z } from "zod";
5
+ var READ_ONLY = {
6
+ readOnlyHint: true,
7
+ destructiveHint: false,
8
+ idempotentHint: true,
9
+ openWorldHint: false
10
+ };
11
+ var LOG_LEVELS = [
12
+ "error",
13
+ "warn",
14
+ "info",
15
+ "http",
16
+ "verbose",
17
+ "debug",
18
+ "silly"
19
+ ];
20
+ var vec3 = z.object({
21
+ x: z.number(),
22
+ y: z.number(),
23
+ z: z.number()
24
+ });
25
+ function json(data) {
26
+ return {
27
+ content: [
28
+ {
29
+ type: "text",
30
+ text: JSON.stringify(data, null, 2)
31
+ }
32
+ ]
33
+ };
34
+ }
35
+ async function run(body) {
36
+ try {
37
+ return json(await body());
38
+ } catch (err) {
39
+ return {
40
+ isError: true,
41
+ content: [
42
+ { type: "text", text: err.message }
43
+ ]
44
+ };
45
+ }
46
+ }
47
+
48
+ export {
49
+ READ_ONLY,
50
+ LOG_LEVELS,
51
+ vec3,
52
+ run
53
+ };
@@ -2,10 +2,12 @@
2
2
  import {
3
3
  DocsClient,
4
4
  registerDocsTools
5
- } from "./chunk-5YUDR7ZR.js";
5
+ } from "./chunk-HRMANFDB.js";
6
6
  import {
7
7
  DEFAULT_DOCS_URL
8
- } from "./chunk-3VVGSO5T.js";
8
+ } from "./chunk-33OMMYNV.js";
9
+ import "./chunk-WMXVMJDM.js";
10
+ import "./chunk-K3NQKI34.js";
9
11
  export {
10
12
  DEFAULT_DOCS_URL,
11
13
  DocsClient,