mdkg 0.3.5 → 0.3.6

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/CHANGELOG.md CHANGED
@@ -8,9 +8,35 @@ mdkg is pre-v1 public alpha software. Command, graph, cache, bundle, and DAL con
8
8
 
9
9
  ## Unreleased
10
10
 
11
- ### Planned
11
+ ## 0.3.6 - 2026-06-17
12
12
 
13
- - No changes yet.
13
+ ### Added
14
+
15
+ - Added `mdkg mcp serve --stdio` as a local read-only MCP server for status,
16
+ workspace/subgraph discovery, search, show, bounded in-memory packs, goal
17
+ current/next, and validation.
18
+ - Added packed `smoke:mcp` coverage that installs mdkg from a tarball in a
19
+ temp prefix, launches the stdio server, exercises root and subgraph reads,
20
+ and proves mutation-shaped tool calls fail closed.
21
+
22
+ ### Fixed
23
+
24
+ - Prepared `0.3.6` graph import hardening after the `0.3.5` publish:
25
+ `mdkg graph import-template --select-goal --apply` now activates the
26
+ rewritten imported start goal, pauses competing active root goals, validates,
27
+ and only then writes selected-goal state.
28
+
29
+ ### Changed
30
+
31
+ - Extended graph import dry-run/apply receipts with activation and paused-goal
32
+ details, and made active template imports fail before writing when
33
+ `--select-goal` is omitted and multiple active root goals would result.
34
+
35
+ ### Security
36
+
37
+ - The MCP server is stdio-only and exposes no task, goal activation, graph
38
+ import, queue, event, archive, format, SQL, shell, arbitrary file-read,
39
+ filesystem mutation, environment, or secret-access tools.
14
40
 
15
41
  ## 0.3.5 - 2026-06-17
16
42
 
@@ -1,7 +1,7 @@
1
1
  # CLI Command Matrix
2
2
 
3
3
  as_of: 2026-06-17
4
- package_version_in_source: 0.3.5
4
+ package_version_in_source: 0.3.6
5
5
  source: live help from `src/cli.ts`, runtime command handlers, and `dec-15`..`dec-18`
6
6
  status: canonical single-source command and flag reference for mdkg
7
7
 
@@ -36,6 +36,7 @@ Primary commands:
36
36
  - `next`
37
37
  - `validate`
38
38
  - `status`
39
+ - `mcp`
39
40
  - `fix`
40
41
 
41
42
  Advanced / maintenance commands:
@@ -64,6 +65,7 @@ Fresh init workspaces default to the SQLite access cache backend; existing migra
64
65
  Project application database foundation commands are accessed through `mdkg db ...`; `mdkg index` remains the compatibility shortcut for graph index rebuilds.
65
66
  Operator health summaries are accessed through read-only `mdkg status ...`; deeper diagnostics remain under `mdkg doctor ...`.
66
67
  Repair planning is accessed through read-only `mdkg fix plan ...`; duplicate-ID graph repairs can be applied through `mdkg fix apply --family ids ...` or the convenience `mdkg fix ids --apply ...`. Index/cache and graph-reference findings remain plan/manual-review only.
68
+ Local MCP integration is accessed through `mdkg mcp serve --stdio`; it exposes read-only graph/status/workspace/search/show/pack/goal/validate tools only.
67
69
 
68
70
  ## Global usage
69
71
 
@@ -647,13 +649,14 @@ Notes:
647
649
  - `graph import-template` defaults to dry-run unless `--apply` is supplied
648
650
  - same-repo template import rewrites canonical numeric IDs to the next unused ID by type prefix and rewrites structured refs plus safe body-local id/qid mentions
649
651
  - colliding semantic template IDs require `--id-prefix`
650
- - `--select-goal` requires `--start-goal` and writes selected-goal state only after apply validation
652
+ - `--select-goal` requires `--start-goal`; on apply it activates the imported start goal, pauses competing active root goals, validates, then writes selected-goal state
653
+ - importing active template goals without `--select-goal` fails before writing when it would create multiple active root goals
651
654
  - subgraphs remain read-only bundle projections for orchestration context; use `graph clone|fork|import-template` when authored graph state should be created
652
655
 
653
656
  JSON receipts:
654
657
  - `clone`: `{ action: "graph.clone", ok, mode, source, target, source_hash, preserved_ids, files_written, skipped_paths, index, validation, warnings }`
655
658
  - `fork`: `{ action: "graph.fork", ok, mode, source, target, source_hash, preserved_ids, files_written, skipped_paths, start_goal?, selected_goal?, index, validation, warnings }`
656
- - `import-template`: `{ action: "graph.import_template", ok, mode, source, source_hash, preserved_ids: false, rewritten_ids, rewritten_refs, planned_paths, files_written, skipped_paths, start_goal?, selected_goal?, index?, validation?, warnings }`
659
+ - `import-template`: `{ action: "graph.import_template", ok, mode, source, source_hash, preserved_ids: false, rewritten_ids, rewritten_refs, planned_paths, files_written, skipped_paths, start_goal?, selected_goal?, activated_goal?, paused_goals, index?, validation?, warnings }`
657
660
 
658
661
  ### `mdkg subgraph`
659
662
 
@@ -1086,6 +1089,34 @@ JSON receipt shape:
1086
1089
  - `generated` reports index, skills, capabilities, and subgraph cache existence/staleness
1087
1090
  - `summary` includes machine-readable warning and error counts plus messages
1088
1091
 
1092
+ ### `mdkg mcp`
1093
+
1094
+ Usage:
1095
+ - `mdkg mcp serve --stdio`
1096
+
1097
+ When to use:
1098
+ - expose one local mdkg root to an MCP-capable agent or orchestrator
1099
+ - let an external agent inspect mdkg status, workspace/subgraph aliases, search/show results, in-memory packs, goal current/next, and validation without shelling out to individual CLI commands
1100
+
1101
+ Flags:
1102
+ - `--stdio`
1103
+ - `--root`, `-r <path>`
1104
+
1105
+ Boundaries:
1106
+ - stdio is the only transport in this release; mdkg opens no HTTP listener
1107
+ - bind the server to one graph root with `--root <path>` when launching from outside the repo
1108
+ - tool calls are read-only and return MCP `structuredContent` plus text content
1109
+ - exposed tools: `mdkg_status`, `mdkg_workspace_list`, `mdkg_search`, `mdkg_show`, `mdkg_pack`, `mdkg_goal_current`, `mdkg_goal_next`, and `mdkg_validate`
1110
+ - `mdkg_pack` builds an in-memory bounded pack and does not write `.mdkg/pack`
1111
+ - no task, goal activation, graph import, queue, event, archive, format, SQL, shell, arbitrary file-read, filesystem mutation, environment, or secret-access tool is exposed
1112
+ - mutation allowlists and broader CLI parity are future design work, not part of this command surface
1113
+ - stdout is reserved for newline-delimited JSON-RPC MCP messages; diagnostics must stay off stdout
1114
+
1115
+ JSON-RPC receipt shapes:
1116
+ - initialize: `{ protocolVersion, capabilities: { tools }, serverInfo, instructions }`
1117
+ - `tools/list`: `{ tools: [{ name, title, description, inputSchema, annotations }] }`
1118
+ - `tools/call`: MCP tool result with `{ content, structuredContent, isError }`
1119
+
1089
1120
  ### `mdkg fix`
1090
1121
 
1091
1122
  When to use:
package/README.md CHANGED
@@ -14,7 +14,7 @@ mdkg stays deliberately boring:
14
14
  - first-class rebuildable SQLite cache through built-in `node:sqlite`
15
15
  - no daemon, hosted index, or vector DB
16
16
 
17
- Current package version in source: `0.3.5`
17
+ Current package version in source: `0.3.6`
18
18
 
19
19
  mdkg is still pre-v1 public alpha software. The public package is usable, but graph, cache, bundle, and DAL contracts may continue to change quickly while the project converges on a stable v1 surface.
20
20
 
@@ -167,9 +167,11 @@ mdkg graph import-template templates/website-template-mdkg --start-goal goal-1 -
167
167
  ```
168
168
 
169
169
  `graph clone` and `graph fork` preserve IDs; `graph import-template` rewrites
170
- canonical numeric IDs and internal links to avoid same-repo collisions. Subgraphs
171
- remain read-only planning views; use `mdkg graph ...` when authored graph state
172
- should be created.
170
+ canonical numeric IDs and internal links to avoid same-repo collisions. With
171
+ `--select-goal --apply`, import-template activates the rewritten imported start
172
+ goal, pauses competing active root goals, validates the graph, and then writes
173
+ selected-goal state. Subgraphs remain read-only planning views; use
174
+ `mdkg graph ...` when authored graph state should be created.
173
175
 
174
176
  Register a child repo bundle as a read-only subgraph planning view:
175
177
 
@@ -206,6 +208,20 @@ Materialized trees are generated local state, ignored by graph indexing/search/v
206
208
 
207
209
  Subgraph nodes are projected under the subgraph alias, for example `child_repo:task-1`. They are available to `list`, `search`, `show`, `pack`, capability discovery, and `capability resolve`, but remain read-only; mutate the child repo and sync its root-owned bundle snapshot to change subgraph content. Root-authored relationship and reference fields can point at configured subgraph qids such as `child_repo:work.example`; local ownership fields such as `epic`, `parent`, `prev`, and `next` stay local-only. Stale subgraphs warn during planning reads and fail `mdkg subgraph verify`. Public or internal subgraphs must be backed by public bundle profiles; private subgraphs stay private planning context.
208
210
 
211
+ Launch a local read-only MCP server when an MCP-capable agent should inspect a
212
+ specific mdkg graph without receiving mutation tools:
213
+
214
+ ```bash
215
+ mdkg mcp serve --stdio --root /path/to/repo
216
+ ```
217
+
218
+ The MCP surface is stdio-only in this release. It exposes read-only tools for
219
+ status, workspace/subgraph listing, search, show, in-memory pack generation,
220
+ goal current/next, and validation. It does not expose task updates, goal
221
+ activation, graph import, queue, event, archive, format, SQL, shell, arbitrary
222
+ file reads, filesystem mutation, environment variables, or secret access.
223
+ Future mutation allowlists remain design work.
224
+
209
225
  Validate before handoff or commit:
210
226
 
211
227
  ```bash
@@ -330,6 +346,7 @@ These are the commands new users and agents should learn first:
330
346
  - `mdkg task`
331
347
  - `mdkg validate`
332
348
  - `mdkg status`
349
+ - `mdkg mcp`
333
350
  - `mdkg fix`
334
351
 
335
352
  Advanced / maintenance commands still exist, but they are not the first-run story:
package/dist/cli.js CHANGED
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  };
6
6
  Object.defineProperty(exports, "__esModule", { value: true });
7
7
  exports.runCli = runCli;
8
+ exports.runCliAsync = runCliAsync;
8
9
  exports.main = main;
9
10
  const fs_1 = __importDefault(require("fs"));
10
11
  const path_1 = __importDefault(require("path"));
@@ -19,6 +20,7 @@ const validate_1 = require("./commands/validate");
19
20
  const format_1 = require("./commands/format");
20
21
  const doctor_1 = require("./commands/doctor");
21
22
  const status_1 = require("./commands/status");
23
+ const mcp_1 = require("./commands/mcp");
22
24
  const fix_1 = require("./commands/fix");
23
25
  const db_1 = require("./commands/db");
24
26
  const capability_1 = require("./commands/capability");
@@ -78,6 +80,7 @@ function printUsage(log) {
78
80
  log(" next Suggest the next work item");
79
81
  log(" validate Validate frontmatter + graph");
80
82
  log(" status Show read-only operator health summary");
83
+ log(" mcp Serve local read-only MCP tools over stdio");
81
84
  log(" fix Plan read-only repairs with receipt-shaped JSON");
82
85
  log("\nAdvanced / maintenance commands:");
83
86
  log(" db Project database and index-cache commands");
@@ -581,7 +584,7 @@ function printGraphHelp(log, subcommand) {
581
584
  log(" - imports authored .mdkg/work template nodes into the current graph");
582
585
  log(" - defaults to dry-run unless --apply is supplied");
583
586
  log(" - rewrites canonical numeric IDs and structured graph links deterministically");
584
- log(" - --select-goal requires --start-goal and writes selected-goal state only after apply validation");
587
+ log(" - --select-goal requires --start-goal; on apply it activates the imported start goal, pauses competing active root goals, validates, then writes selected-goal state");
585
588
  break;
586
589
  default:
587
590
  log("Usage:");
@@ -923,6 +926,29 @@ function printStatusHelp(log) {
923
926
  log(" --json Emit machine-readable JSON output");
924
927
  printGlobalOptions(log);
925
928
  }
929
+ function printMcpHelp(log, subcommand) {
930
+ switch ((subcommand ?? "").toLowerCase()) {
931
+ case "serve":
932
+ log("Usage:");
933
+ log(" mdkg mcp serve --stdio");
934
+ log("\nBoundary:");
935
+ log(" - starts one local Model Context Protocol server bound to the selected --root");
936
+ log(" - stdio is the only transport in this release; no HTTP listener is opened");
937
+ log(" - exposes read-only tools for status, workspace list, search, show, pack, goal current/next, and validate");
938
+ log(" - exposes no task, goal, graph, queue, event, archive, format, SQL, shell, filesystem, or environment mutation tools");
939
+ log(" - stdout is reserved for newline-delimited JSON-RPC MCP messages");
940
+ printGlobalOptions(log);
941
+ return;
942
+ default:
943
+ log("Usage:");
944
+ log(" mdkg mcp serve --stdio");
945
+ log("\nBoundary:");
946
+ log(" - local read-only MCP server for mdkg graph inspection");
947
+ log(" - use --root <path> to select the mdkg graph explicitly");
948
+ log(" - phase one is stdio-only and does not expose mutation tools");
949
+ printGlobalOptions(log);
950
+ }
951
+ }
926
952
  function printFixHelp(log, subcommand) {
927
953
  switch ((subcommand ?? "").toLowerCase()) {
928
954
  case "plan":
@@ -1091,6 +1117,9 @@ function printCommandHelp(log, command, subcommand) {
1091
1117
  case "status":
1092
1118
  printStatusHelp(log);
1093
1119
  return;
1120
+ case "mcp":
1121
+ printMcpHelp(log, subcommand);
1122
+ return;
1094
1123
  case "fix":
1095
1124
  printFixHelp(log, subcommand);
1096
1125
  return;
@@ -2788,6 +2817,8 @@ function runCommand(parsed, root, runtime) {
2788
2817
  (0, status_1.runStatusCommand)({ root, json });
2789
2818
  return 0;
2790
2819
  }
2820
+ case "mcp":
2821
+ throw new errors_1.UsageError("mcp serve requires the async CLI entrypoint");
2791
2822
  case "fix": {
2792
2823
  const sub = (parsed.positionals[1] ?? "").toLowerCase();
2793
2824
  if (!sub) {
@@ -2838,6 +2869,18 @@ function runCommand(parsed, root, runtime) {
2838
2869
  return 1;
2839
2870
  }
2840
2871
  }
2872
+ async function runMcpSubcommand(parsed, root) {
2873
+ const sub = (parsed.positionals[1] ?? "").toLowerCase();
2874
+ if (sub !== "serve") {
2875
+ throw new errors_1.UsageError("mcp requires serve --stdio");
2876
+ }
2877
+ if (parsed.positionals.length > 2) {
2878
+ throw new errors_1.UsageError("mcp serve does not accept positional arguments");
2879
+ }
2880
+ const stdio = parseBooleanFlag("--stdio", parsed.flags["--stdio"]);
2881
+ await (0, mcp_1.runMcpServeCommand)({ root, stdio });
2882
+ return 0;
2883
+ }
2841
2884
  function runCli(argv, runtime = {}) {
2842
2885
  const io = resolveRuntime(runtime);
2843
2886
  const parsed = (0, argparse_1.parseArgs)(argv);
@@ -2875,8 +2918,53 @@ function runCli(argv, runtime = {}) {
2875
2918
  return handleCommandError(err, command, io);
2876
2919
  }
2877
2920
  }
2921
+ async function runCliAsync(argv, runtime = {}) {
2922
+ const io = resolveRuntime(runtime);
2923
+ const parsed = (0, argparse_1.parseArgs)(argv);
2924
+ if (parsed.error) {
2925
+ io.error(parsed.error);
2926
+ printUsage(io.log);
2927
+ return 1;
2928
+ }
2929
+ if (parsed.help) {
2930
+ printCommandHelp(io.log, parsed.positionals[0], parsed.positionals[1]);
2931
+ return 0;
2932
+ }
2933
+ if (parsed.version) {
2934
+ io.log(readPackageVersion());
2935
+ return 0;
2936
+ }
2937
+ const command = (parsed.positionals[0] ?? "").toLowerCase();
2938
+ if (!command) {
2939
+ printUsage(io.log);
2940
+ return 0;
2941
+ }
2942
+ if (command === "help") {
2943
+ printCommandHelp(io.log, parsed.positionals[1], parsed.positionals[2]);
2944
+ return 0;
2945
+ }
2946
+ const root = parsed.root ? path_1.default.resolve(parsed.root) : io.cwd();
2947
+ if (shouldRequireConfig(command, parsed.flags) && !hasConfig(root)) {
2948
+ printRootError(io.error, root);
2949
+ return 1;
2950
+ }
2951
+ try {
2952
+ if (command === "mcp") {
2953
+ return await runMcpSubcommand(parsed, root);
2954
+ }
2955
+ return runCommand(parsed, root, io);
2956
+ }
2957
+ catch (err) {
2958
+ return handleCommandError(err, command, io);
2959
+ }
2960
+ }
2878
2961
  function main(argv = process.argv.slice(2)) {
2879
- process.exit(runCli(argv, { cwd: () => process.cwd() }));
2962
+ runCliAsync(argv, { cwd: () => process.cwd() })
2963
+ .then((code) => process.exit(code))
2964
+ .catch((err) => {
2965
+ console.error(err instanceof Error ? err.message : String(err));
2966
+ process.exit(4);
2967
+ });
2880
2968
  }
2881
2969
  if (require.main === module) {
2882
2970
  main();
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "schema_version": 1,
3
3
  "tool": "mdkg",
4
- "package_version": "0.3.5",
4
+ "package_version": "0.3.6",
5
5
  "source": {
6
6
  "help_targets": "scripts/cli_help_targets.js",
7
7
  "command_matrix": "CLI_COMMAND_MATRIX.md"
@@ -4012,13 +4012,13 @@
4012
4012
  "name": "--select-goal",
4013
4013
  "value": "requires",
4014
4014
  "required": false,
4015
- "description": "- --select-goal requires --start-goal and writes selected-goal state only after apply validation"
4015
+ "description": "- --select-goal requires --start-goal; on apply it activates the imported start goal, pauses competing active root goals, validates, then writes selected-goal state"
4016
4016
  },
4017
4017
  {
4018
4018
  "name": "--start-goal",
4019
- "value": "and",
4019
+ "value": null,
4020
4020
  "required": false,
4021
- "description": "- --select-goal requires --start-goal and writes selected-goal state only after apply validation"
4021
+ "description": "- --select-goal requires --start-goal; on apply it activates the imported start goal, pauses competing active root goals, validates, then writes selected-goal state"
4022
4022
  },
4023
4023
  {
4024
4024
  "name": "--version",
@@ -4404,6 +4404,159 @@
4404
4404
  "command_matrix": "CLI_COMMAND_MATRIX.md"
4405
4405
  }
4406
4406
  },
4407
+ {
4408
+ "key": "mcp",
4409
+ "path": [
4410
+ "mcp"
4411
+ ],
4412
+ "category": "mcp",
4413
+ "status": "stable",
4414
+ "visibility": "public",
4415
+ "summary": "mdkg mcp command",
4416
+ "usage": [
4417
+ " mdkg mcp serve --stdio"
4418
+ ],
4419
+ "args": [],
4420
+ "flags": [
4421
+ {
4422
+ "name": "--help",
4423
+ "value": null,
4424
+ "required": false,
4425
+ "description": "--help, -h Show help"
4426
+ },
4427
+ {
4428
+ "name": "--root",
4429
+ "value": "<path>",
4430
+ "required": false,
4431
+ "description": "- use --root <path> to select the mdkg graph explicitly"
4432
+ },
4433
+ {
4434
+ "name": "--stdio",
4435
+ "value": null,
4436
+ "required": false,
4437
+ "description": "mdkg mcp serve --stdio"
4438
+ },
4439
+ {
4440
+ "name": "--version",
4441
+ "value": null,
4442
+ "required": false,
4443
+ "description": "--version, -V Show version"
4444
+ }
4445
+ ],
4446
+ "output_formats": [
4447
+ "text"
4448
+ ],
4449
+ "json_schema_ref": null,
4450
+ "side_effects": [
4451
+ "none"
4452
+ ],
4453
+ "read_paths": [
4454
+ ".mdkg/**"
4455
+ ],
4456
+ "write_paths": [],
4457
+ "dry_run": {
4458
+ "supported": false
4459
+ },
4460
+ "lock_policy": "none-read-only",
4461
+ "atomic_write_policy": "none-read-only",
4462
+ "receipts": [],
4463
+ "danger_level": "read-only",
4464
+ "aliases": [],
4465
+ "exit_codes": [
4466
+ {
4467
+ "code": 0,
4468
+ "meaning": "success"
4469
+ },
4470
+ {
4471
+ "code": 1,
4472
+ "meaning": "validation-or-runtime-error"
4473
+ }
4474
+ ],
4475
+ "examples": [
4476
+ " mdkg mcp serve --stdio"
4477
+ ],
4478
+ "docs": {
4479
+ "help_target": "mdkg help mcp",
4480
+ "command_matrix": "CLI_COMMAND_MATRIX.md"
4481
+ }
4482
+ },
4483
+ {
4484
+ "key": "mcp serve",
4485
+ "path": [
4486
+ "mcp",
4487
+ "serve"
4488
+ ],
4489
+ "category": "mcp",
4490
+ "status": "stable",
4491
+ "visibility": "public",
4492
+ "summary": "mdkg mcp serve command",
4493
+ "usage": [
4494
+ " mdkg mcp serve --stdio"
4495
+ ],
4496
+ "args": [],
4497
+ "flags": [
4498
+ {
4499
+ "name": "--help",
4500
+ "value": null,
4501
+ "required": false,
4502
+ "description": "--help, -h Show help"
4503
+ },
4504
+ {
4505
+ "name": "--root",
4506
+ "value": null,
4507
+ "required": false,
4508
+ "description": "- starts one local Model Context Protocol server bound to the selected --root"
4509
+ },
4510
+ {
4511
+ "name": "--stdio",
4512
+ "value": null,
4513
+ "required": false,
4514
+ "description": "mdkg mcp serve --stdio"
4515
+ },
4516
+ {
4517
+ "name": "--version",
4518
+ "value": null,
4519
+ "required": false,
4520
+ "description": "--version, -V Show version"
4521
+ }
4522
+ ],
4523
+ "output_formats": [
4524
+ "text"
4525
+ ],
4526
+ "json_schema_ref": null,
4527
+ "side_effects": [
4528
+ "none"
4529
+ ],
4530
+ "read_paths": [
4531
+ ".mdkg/**"
4532
+ ],
4533
+ "write_paths": [],
4534
+ "dry_run": {
4535
+ "supported": false
4536
+ },
4537
+ "lock_policy": "none-read-only",
4538
+ "atomic_write_policy": "none-read-only",
4539
+ "receipts": [],
4540
+ "danger_level": "read-only",
4541
+ "aliases": [],
4542
+ "exit_codes": [
4543
+ {
4544
+ "code": 0,
4545
+ "meaning": "success"
4546
+ },
4547
+ {
4548
+ "code": 1,
4549
+ "meaning": "validation-or-runtime-error"
4550
+ }
4551
+ ],
4552
+ "examples": [
4553
+ " mdkg mcp serve --stdio"
4554
+ ],
4555
+ "docs": {
4556
+ "help_target": "mdkg help mcp serve",
4557
+ "command_matrix": "CLI_COMMAND_MATRIX.md"
4558
+ }
4559
+ },
4407
4560
  {
4408
4561
  "key": "new",
4409
4562
  "path": [
@@ -8215,5 +8368,5 @@
8215
8368
  }
8216
8369
  }
8217
8370
  ],
8218
- "contract_hash": "2fd862666a24adc363a0912822b639f7e437bf5fd31dea13e6f4d87bf0a57d60"
8371
+ "contract_hash": "130236f8a2c5c757528f82acf95f43fb67809a0ddb333ebffa5d69b452a20146"
8219
8372
  }