drupal-mcp-connector 2.25.0 → 2.26.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.
@@ -19,7 +19,7 @@ Parse the arguments supplied with this command into this tool's parameters:
19
19
  - `langcode` (string): Target language for an unpublished working translation (nodes). Continues that translation via Sentinel.
20
20
  - `attributes` (object (pass as JSON))
21
21
  - `relationships` (object (pass as JSON))
22
- - `dryRun` (boolean (true/false)): Validate, resolve ERR identifiers, run the server-side preflight when one applies, and return a preview without the real write. The result's `checks` block says what was checked; `caveat` names what was not. Only an existing node draft (or a langcode translation draft) is checked with the real payload: Sentinel's non-saving draft endpoint applies the submitted fields through field access and validates the entity (`serverPreflight: sentinel_draft`). On other moderated targets an id-mismatch core PATCH with no fields checks entity update access and core's working-copy guard only; field access and entity validation are NOT checked (`core_patch_guard`), so the real write can still fail with a field-access 403 or a 422. Unmoderated targets get no server-side check at all (`none`). A published node with no distinct working copy whose changed timestamp is later than revision_timestamp (possiblyPatchBlocked) fails dryRun the same as the real write (#273). Any refusal fails the dryRun.
22
+ - `dryRun` (boolean (true/false)): Validate, resolve ERR identifiers, run the server-side preflight when one applies, and return a preview without the real write. The result's `checks` block says what was checked; `caveat` names what was not. Only an existing node draft (or a langcode translation draft) is checked with the real payload: Sentinel's non-saving draft endpoint applies the submitted fields through field access and validates the entity (`serverPreflight: sentinel_draft`). On other moderated targets an id-mismatch core PATCH with no fields checks entity update access and core's working-copy guard only; field access and entity validation are NOT checked (`core_patch_guard`), so the real write can still fail with a field-access 403 or a 422. Unmoderated targets get no server-side check at all (`none`). A changed/revision_timestamp gap on the default revision (possiblyPatchBlocked) is a warning on list_revisions, not a local dryRun refusal — the write proceeds to the core probe / Sentinel (#405). An actual Sentinel stale-copy refusal is still rewritten. Any refusal fails the dryRun.
23
23
  - `returning` (one of: full, minimal): Response verbosity. "full" (default) returns the complete saved entity; "minimal" returns just identity + state (id, type, bundle, title, status, changed, url) — much smaller, recommended for bulk writes where the echoed body would dominate the response.
24
24
 
25
25
  If a required parameter is missing, ask before calling — do not invent values. Coerce each value to its JSON type (booleans → true/false, numbers → numeric, object/array → parse JSON), then make the single tool call and summarize the result.
@@ -1,11 +1,11 @@
1
1
  ---
2
- description: "Schedule a content node to publish and/or unpublish at a future time using the Drupal Scheduler module. Sets the publish_on and unpublish_on fields on the node. Requires the Scheduler module to be installed and enabled for the content type, with the publish_on / unpublish_on fields present on the bundle — otherwise the call fails with a clear capability error. Timestamps accept ISO 8601 (e.g. '2026-07-01T12:00:00Z') or a Unix epoch and are passed through unchanged. Provide at least one of publishOn or unpublishOn."
3
- argument-hint: "<type> <id> [site] [publishOn] [unpublishOn]"
2
+ description: "Schedule a content node to publish and/or unpublish at a future time using the Drupal Scheduler module. Sets the publish_on and unpublish_on fields on the node. On a bundle under Content Moderation, also set publishState / unpublishState (written as publish_state / unpublish_state) — dates alone never go live. Requires the Scheduler module to be installed and enabled for the content type, with the publish_on / unpublish_on fields present on the bundle — otherwise the call fails with a clear capability error. Moderated bundles additionally need Scheduler Content Moderation Integration; when those state fields exist, the matching state is required whenever a date is set. Timestamps accept ISO 8601 (e.g. '2026-07-01T12:00:00Z') or a Unix epoch and are passed through unchanged. Provide at least one of publishOn or unpublishOn."
3
+ argument-hint: "<type> <id> [site] [publishOn] [unpublishOn] [publishState] [unpublishState]"
4
4
  ---
5
5
 
6
6
  Call the MCP tool `drupal_schedule_publish`.
7
7
 
8
- Schedule a content node to publish and/or unpublish at a future time using the Drupal Scheduler module. Sets the publish_on and unpublish_on fields on the node. Requires the Scheduler module to be installed and enabled for the content type, with the publish_on / unpublish_on fields present on the bundle — otherwise the call fails with a clear capability error. Timestamps accept ISO 8601 (e.g. '2026-07-01T12:00:00Z') or a Unix epoch and are passed through unchanged. Provide at least one of publishOn or unpublishOn.
8
+ Schedule a content node to publish and/or unpublish at a future time using the Drupal Scheduler module. Sets the publish_on and unpublish_on fields on the node. On a bundle under Content Moderation, also set publishState / unpublishState (written as publish_state / unpublish_state) — dates alone never go live. Requires the Scheduler module to be installed and enabled for the content type, with the publish_on / unpublish_on fields present on the bundle — otherwise the call fails with a clear capability error. Moderated bundles additionally need Scheduler Content Moderation Integration; when those state fields exist, the matching state is required whenever a date is set. Timestamps accept ISO 8601 (e.g. '2026-07-01T12:00:00Z') or a Unix epoch and are passed through unchanged. Provide at least one of publishOn or unpublishOn.
9
9
 
10
10
  Parse the arguments supplied with this command into this tool's parameters:
11
11
 
@@ -17,5 +17,7 @@ Parse the arguments supplied with this command into this tool's parameters:
17
17
  - `site` (string): Named site from connector config. Omit only on reads: multi-site configs fall back to defaultSite (often local/dev, not production). Writes require an explicit site when more than one site is configured. Every response includes `_target` { name, baseUrl, source } (`hint` when you passed site, `default` when you did not).
18
18
  - `publishOn` (string): When to publish — ISO 8601 datetime or Unix epoch. Sets the Scheduler publish_on field.
19
19
  - `unpublishOn` (string): When to unpublish — ISO 8601 datetime or Unix epoch. Sets the Scheduler unpublish_on field.
20
+ - `publishState` (string): Moderation state to enter at publishOn (e.g. 'published'). Required on moderated bundles when publishOn is set.
21
+ - `unpublishState` (string): Moderation state to enter at unpublishOn (e.g. 'draft'). Required on moderated bundles when unpublishOn is set.
20
22
 
21
23
  If a required parameter is missing, ask before calling — do not invent values. Coerce each value to its JSON type (booleans → true/false, numbers → numeric, object/array → parse JSON), then make the single tool call and summarize the result.
@@ -24,7 +24,7 @@ Parse the arguments supplied with this command into this tool's parameters:
24
24
  - `langcode` (string): Target language for an unpublished working translation (e.g. 'es'). Continues that translation via Sentinel; does not create a missing translation and does not PATCH canonical langcode.
25
25
  - `fields` (object (pass as JSON)): Scalar/attribute field values keyed by machine name. Formatted text: a string or { value, format?, summary? }. format must be in the field's allowed_formats; a single allowed format is used when omitted. Entity-reference fields go in `relationships`, not here.
26
26
  - `relationships` (object (pass as JSON)): Entity-reference fields as JSON:API relationships, keyed by field machine name. Single-value uses { data: { type, id } }; multi-value uses { data: [{ type, id }, …] }. Paragraph / ERR items must carry meta.target_revision_id — the connector injects it when missing, and fails the write if it cannot. Image alt on a translation uses the existing file UUID plus meta.alt; replacing the file is refused.
27
- - `dryRun` (boolean (true/false)): Validate, resolve ERR identifiers, run the server-side preflight when one applies, and return a preview without the real write. The result's `checks` block says what was checked; `caveat` names what was not. Only an existing node draft (or a langcode translation draft) is checked with the real payload: Sentinel's non-saving draft endpoint applies the submitted fields through field access and validates the entity (`serverPreflight: sentinel_draft`). On other moderated targets an id-mismatch core PATCH with no fields checks entity update access and core's working-copy guard only; Drupal does not check field access or entity validation on that probe (`core_patch_guard`). Text format is resolved before the preview returns, including on that path: a known allowed_formats list is enforced, and an unknown list reuses the format stored on the field. Other fields can still fail the real write with a field-access 403 or a validation 422. Unmoderated targets get no server-side check at all (`none`). A published node with no distinct working copy whose changed timestamp is later than revision_timestamp (possiblyPatchBlocked) fails dryRun the same as the real write (#273). Any refusal fails the dryRun.
27
+ - `dryRun` (boolean (true/false)): Validate, resolve ERR identifiers, run the server-side preflight when one applies, and return a preview without the real write. The result's `checks` block says what was checked; `caveat` names what was not. Only an existing node draft (or a langcode translation draft) is checked with the real payload: Sentinel's non-saving draft endpoint applies the submitted fields through field access and validates the entity (`serverPreflight: sentinel_draft`). On other moderated targets an id-mismatch core PATCH with no fields checks entity update access and core's working-copy guard only; Drupal does not check field access or entity validation on that probe (`core_patch_guard`). Text format is resolved before the preview returns, including on that path: a known allowed_formats list is enforced, and an unknown list reuses the format stored on the field. Other fields can still fail the real write with a field-access 403 or a validation 422. Unmoderated targets get no server-side check at all (`none`). A changed/revision_timestamp gap on the default revision (possiblyPatchBlocked) is a warning on list_revisions, not a local dryRun refusal — the write proceeds to the core probe / Sentinel (#405). An actual Sentinel stale-copy refusal is still rewritten. Any refusal fails the dryRun.
28
28
  - `returning` (one of: full, minimal): Response verbosity. "full" (default) returns the complete saved entity; "minimal" returns just identity + state (id, type, bundle, title, status, changed, url) — much smaller, recommended for bulk writes where the echoed body would dominate the response.
29
29
 
30
30
  If a required parameter is missing, ask before calling — do not invent values. Coerce each value to its JSON type (booleans → true/false, numbers → numeric, object/array → parse JSON), then make the single tool call and summarize the result.
package/CHANGELOG.md CHANGED
@@ -7,6 +7,74 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## [Unreleased]
9
9
 
10
+ ## [2.26.0] - 2026-10-01
11
+
12
+ ### Changed
13
+ - **Nightly leftover cleanup (#399).** CI pins Node 20 (no 1-cell matrix) and
14
+ runs `npm run syntax-check` recursively over `src/`. The two
15
+ `resources/read` URIs (`content-types`, `security-policy`) go through
16
+ `invokeReadTool` → `callTool`. AGENTS, CONTRIBUTING, threat-model, and
17
+ ops docs point middleware at `src/lib/dispatch.js`.
18
+
19
+ ### Removed
20
+ - **Production-dead `redactResource`.** Canonical `redactCanonicalEntity` is
21
+ the only redaction path; JSON:API-shape tests folded into it.
22
+ - **Leftover public exports** from `workflow-prompts.js`, `server-tools.js`,
23
+ and `allModules` (module-private after #395).
24
+
25
+ ### Added
26
+ - **Terminal install wizard (`wizard` / `init`).**
27
+ `npx drupal-mcp-connector init` (also `wizard`, `npm run init`,
28
+ `drupal-mcp-wizard`) collects transport (stdio vs remote HTTPS), auth
29
+ (OAuth vs sealed token), and agent client id, then prints Cursor
30
+ `.cursor/mcp.json` and Claude Code `mcpServers` snippets. Files are
31
+ written only with `--write` and never clobbered without confirm unless
32
+ `--yes`. Post-config `whoami` + `contract_ready` print pass/fail with a
33
+ next fix, or a clear skip when the host is unreachable. Remote HTTPS is
34
+ Tailscale / local-VPN only — not a public SaaS path.
35
+ - **`doctor` CLI.** `npx drupal-mcp-connector doctor` runs ordered
36
+ gates (reachability → auth/401 → agent client → allowlist →
37
+ `contract_ready` → version skew), prints one primary failure plus the
38
+ exact next fix, exits non-zero on fail, and supports `--json` with no
39
+ secrets.
40
+ - **Transport presets.** Wizard `--preset local-stdio|tailscale|public-https`
41
+ and docs table. Public HTTPS is listed as a preset and is not a hosted service.
42
+ - **Version skew.** Doctor and wizard print “you are on X;
43
+ site needs Y” when readiness reports versions. No auto-upgrade.
44
+ - **Happy-path recipe.** README walkthrough using
45
+ `drupal_mcp_whoami` → `drupal_list_sites` → unpublished
46
+ `drupal_list_nodes` / `dryRun` `drupal_create_node`.
47
+
48
+ ### Fixed
49
+ - **A `changed` / `revision_timestamp` gap on the default revision no longer blocks the next draft (#405).**
50
+ `#273` treated `possiblyPatchBlocked` as local proof of a hidden revision and
51
+ refused before Sentinel ran. When inventory `working` is null and both
52
+ JSON:API aliases report the same published vid, a `moderationState: draft`
53
+ write now proceeds to the core probe / Sentinel. An actual Sentinel
54
+ stale-copy refusal is still rewritten. `drupal_list_revisions` still reports
55
+ the warning.
56
+ - **`drupal_report_scheduled_content` no longer reports Scheduler fields missing when every date is empty (#403).**
57
+ Field presence is the key on the JSON:API attributes, not a non-empty value.
58
+ Keys present and all null: `summary: { pending: 0, overdue: 0 }`. `gated`
59
+ only when the keys are actually absent.
60
+ - **`drupal_schedule_publish` writes `publish_state` / `unpublish_state` on moderated bundles (#402).**
61
+ Optional `publishState` / `unpublishState` are accepted. When the bundle is
62
+ moderated and those fields exist, the matching state is required whenever a
63
+ date is set. Dates alone were accepted by Drupal and then failed at cron.
64
+ - **Revise guard uses `moderation_state`, not `status: false`, to decide "already a draft" (#400).**
65
+ After revising a translation over a working copy, Sentinel copies the live
66
+ published moderation record onto the carried default language (`status: false`
67
+ + `moderation_state: published`). Neither `drupal_update_node` nor
68
+ `drupal_create_translation` revise can open a draft of that language while
69
+ the other translation draft exists (drupal.org #3626919). Both tools now
70
+ say so and name the manual path: publish or discard the translation draft,
71
+ or edit in the UI.
72
+ - **Config reads accept the read-only `mcp_config_read` scope (#397).**
73
+ `drupal_config_get` / `drupal_config_list`, config reports, and codegen
74
+ inspect/diff accept `mcp_config` or `mcp_config_read`. Writes still require
75
+ `mcp_config`. `drupal_mcp_whoami` reports `configRead: true` for a
76
+ read-scope token. A token with neither scope is still refused.
77
+
10
78
  ## [2.25.0] - 2026-10-01
11
79
 
12
80
  ### Added
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Drupal MCP Connector
2
2
 
3
- > Drupal MCP Connector — multi-site MCP server for Drupal with JSON:API and GraphQL, governed writes, draft translations, content tools, audit reports, and an SSH Drush bridge.
3
+ > Multi-site MCP server for Drupal over JSON:API and GraphQL, with governed writes and an SSH Drush bridge. `init` writes a stdio or Tailscale client config from a transport preset. `doctor` checks reachability, auth, and readiness, and reports version skew. A timestamp gap on a published revision no longer blocks the next draft.
4
4
 
5
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
6
6
  [![Node.js](https://img.shields.io/badge/node-%3E%3D20-green)](https://nodejs.org)
@@ -205,6 +205,62 @@ Full detail: **[docs/security.md](docs/security.md)** and **[docs/security-harde
205
205
 
206
206
  ## Quick Start
207
207
 
208
+ ### One-liner (recommended for operators)
209
+
210
+ ```bash
211
+ npx -y drupal-mcp-connector init
212
+ # aliases: npx -y drupal-mcp-connector wizard
213
+ # npx -y drupal-mcp-wizard
214
+ # CI / dogfood: npx -y drupal-mcp-connector init --yes --json
215
+ npx -y drupal-mcp-connector doctor
216
+ # CI: npx -y drupal-mcp-connector doctor --json
217
+ ```
218
+
219
+ The wizard prints Cursor (`.cursor/mcp.json`) and Claude Code `mcpServers`
220
+ snippets, optional `auth.grants` allowlist hints, and a whoami / contract_ready
221
+ check. It writes files only with `--write` (never clobbers without confirm
222
+ unless `--yes`). Doctor prints **one** primary failing gate and the exact next
223
+ fix (exit non-zero on fail; `--json` is secret-free).
224
+
225
+ ### Transport presets
226
+
227
+ | Preset | URL shape | Notes |
228
+ |--------|-----------|--------|
229
+ | **Local stdio** (`--preset local-stdio`) | `https://drupal.ddev.site` | Client launches this connector as a subprocess. Drupal must be reachable from this machine. |
230
+ | **Tailscale VPN** (`--preset tailscale`) | `https://drupal.<tailnet>.ts.net` | VPN-required. The MCP client host must be on the same tailnet. Not a public internet path. |
231
+ | **Public HTTPS** (`--preset public-https`) | `https://mcp.example.com/mcp` | **Gated / later.** Operator-run `MCP_TRANSPORT=https` + TLS + inbound OAuth. There is **no** hosted Wilkes & Liberty SaaS MCP URL. |
232
+
233
+ **Remote HTTPS is Tailscale / local-VPN only.** This package does not ship a
234
+ public SaaS remote endpoint. stdio is the default: the client launches the
235
+ connector on your machine and inherits VPN/Tailscale/localhost reachability to
236
+ Drupal. See **[docs/mcp-clients.md](docs/mcp-clients.md)**.
237
+
238
+ `requireGovernance: true` remains the listing default for a later marketplace
239
+ entry — this repo does not submit listings. If the client only shows
240
+ `drupal_list_sites` and `drupal_governance_status`, run `doctor`.
241
+
242
+ ### Two-minute happy path
243
+
244
+ After `init` and a green `doctor`, in the MCP client (real tool names):
245
+
246
+ 1. **Who am I?** Call `drupal_mcp_whoami`. Confirm `tier`, `preset`, and
247
+ `capabilities.publish` (false on `production-strict` / `content-editor`).
248
+ 2. **What can I see?** Call `drupal_list_sites`, then `drupal_list_nodes` with
249
+ `{ "type": "article", "status": false, "limit": 5 }` (unpublished only) or
250
+ `drupal_get_node` on a staging UUID. Prefer `drupal_search_content` for a
251
+ title substring.
252
+ 3. **Safe unpublished write (optional, non-prod):** Preview with
253
+ `drupal_create_node`
254
+ `{ "type": "article", "title": "MCP draft", "status": false, "dryRun": true }`.
255
+ Commit without `dryRun` only on staging, still `status: false` (or
256
+ `moderationState: "draft"`). Never set `status: true` or
257
+ `moderationState: "published"` unless `drupal_mcp_whoami` shows
258
+ `capabilities.publish: true` **and** you intend to go live.
259
+
260
+ Fail-closed: default `production-strict` is read-only. A deny is expected when
261
+ the allowlist or Sentinel profile excludes the type — run `doctor` and
262
+ `drupal_governance_status`; do not auto-widen allowlists.
263
+
208
264
  ### From npm (recommended for operators)
209
265
 
210
266
  ```bash
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Connection doctor (DEV-759).
4
+ *
5
+ * npx drupal-mcp-connector doctor
6
+ * node bin/drupal-mcp-doctor.js --json
7
+ */
8
+
9
+ import { runDoctorCli } from "../src/lib/doctor.js";
10
+
11
+ runDoctorCli(process.argv.slice(2))
12
+ .then((code) => process.exit(code))
13
+ .catch((err) => {
14
+ process.stderr.write(`doctor: ${err?.message ?? err}\n`);
15
+ process.exit(2);
16
+ });
@@ -0,0 +1,17 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Operator install wizard (DEV-758).
4
+ *
5
+ * npx drupal-mcp-connector init
6
+ * npx drupal-mcp-connector wizard
7
+ * node bin/drupal-mcp-wizard.js --yes
8
+ */
9
+
10
+ import { runWizardCli } from "../src/lib/wizard.js";
11
+
12
+ runWizardCli(process.argv.slice(2))
13
+ .then((code) => process.exit(code))
14
+ .catch((err) => {
15
+ process.stderr.write(`wizard: ${err?.message ?? err}\n`);
16
+ process.exit(2);
17
+ });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "drupal-mcp-connector",
3
- "version": "2.25.0",
4
- "description": "Drupal MCP Connector — multi-site MCP server for Drupal with JSON:API and GraphQL, governed writes, draft translations, content tools, audit reports, and an SSH Drush bridge.",
3
+ "version": "2.26.0",
4
+ "description": "Multi-site MCP server for Drupal over JSON:API and GraphQL, with governed writes and an SSH Drush bridge. init writes a stdio or Tailscale client config from a transport preset. doctor checks reachability, auth, and readiness, and reports version skew. A timestamp gap on a published revision no longer blocks the next draft.",
5
5
  "type": "module",
6
6
  "main": "src/index.js",
7
7
  "bin": {
@@ -9,7 +9,9 @@
9
9
  "drupal-mcp-verify": "bin/drupal-mcp-verify.js",
10
10
  "drupal-mcp-edge": "bin/drupal-mcp-edge.js",
11
11
  "drupal-mcp-agent": "bin/drupal-mcp-agent.js",
12
- "drupal-mcp-anchor": "bin/drupal-mcp-anchor.js"
12
+ "drupal-mcp-anchor": "bin/drupal-mcp-anchor.js",
13
+ "drupal-mcp-wizard": "bin/drupal-mcp-wizard.js",
14
+ "drupal-mcp-doctor": "bin/drupal-mcp-doctor.js"
13
15
  },
14
16
  "files": [
15
17
  "src/",
@@ -61,9 +63,12 @@
61
63
  "test:watch": "vitest",
62
64
  "audit": "npm audit --audit-level=high",
63
65
  "check": "npm run lint && npm run audit",
64
- "syntax-check": "for f in src/lib/*.js src/tools/*.js src/index.js; do node --input-type=module --check < $f && echo \"$f ✓\"; done",
66
+ "syntax-check": "find src -name '*.js' -exec sh -c 'node --input-type=module --check < \"$1\" && echo \"$1 ✓\"' _ {} \\;",
65
67
  "verify": "node bin/drupal-mcp-verify.js",
66
- "verify:example": "node bin/drupal-mcp-verify.js --config config/config.example.json"
68
+ "verify:example": "node bin/drupal-mcp-verify.js --config config/config.example.json",
69
+ "wizard": "node bin/drupal-mcp-wizard.js",
70
+ "init": "node bin/drupal-mcp-wizard.js",
71
+ "doctor": "node bin/drupal-mcp-doctor.js"
67
72
  },
68
73
  "dependencies": {
69
74
  "@modelcontextprotocol/node": "^2.0.0",
package/src/index.js CHANGED
@@ -23,6 +23,10 @@
23
23
  * MCP_RATE_LIMIT Max /mcp requests per window per client IP (0/unset = off)
24
24
  * MCP_RATE_WINDOW_SEC Rate-limit window in seconds (default: 60)
25
25
  * MCP_LEGACY_TRANSPORT "serve" (default) | "reject" for 2025-era clients
26
+ *
27
+ * CLI subcommands (anything else starts the MCP server):
28
+ * wizard | init Operator install wizard — see src/lib/wizard.js
29
+ * doctor Connection doctor — see src/lib/doctor.js
26
30
  */
27
31
 
28
32
  import { createServer as createHttpsServer } from "https";
@@ -45,10 +49,9 @@ import {
45
49
  import { createLegacySessionHandler, createMcpRequestHandler } from "./lib/http-handler.js";
46
50
  import { createConnectorServerFactory } from "./lib/mcp-server.js";
47
51
  import { createRateLimiter } from "./lib/rate-limit.js";
48
- import { callTool, listResolvableSiteConfigs } from "./lib/dispatch.js";
52
+ import { callTool, invokeReadTool, listResolvableSiteConfigs } from "./lib/dispatch.js";
49
53
  import { filterDiscoverableTools } from "./lib/governance.js";
50
54
  import {
51
- assertPrincipalEntitlement,
52
55
  filterPromptsByPrincipal,
53
56
  filterResourcesByPrincipal,
54
57
  filterToolsByPrincipal,
@@ -57,7 +60,7 @@ import {
57
60
  } from "./lib/principal.js";
58
61
 
59
62
  // Tools — aggregated (single source of truth, side-effect-free) and per-tool prompts
60
- import { allDefinitions, allHandlers, definitionsByName } from "./tools/index.js";
63
+ import { allDefinitions, definitionsByName } from "./tools/index.js";
61
64
  import { createModuleToolRegistry, isModuleTool } from "./lib/module-tools.js";
62
65
  import { buildToolPrompts, createPromptSurface } from "./lib/tool-prompts.js";
63
66
  import {
@@ -69,6 +72,16 @@ import {
69
72
  replaceModuleWorkflows,
70
73
  } from "./lib/workflow-prompts.js";
71
74
  import { builtinWorkflowProvider } from "./lib/workflows/builtin.js";
75
+ import { runWizardCli } from "./lib/wizard.js";
76
+ import { runDoctorCli } from "./lib/doctor.js";
77
+
78
+ const cliCommand = process.argv[2];
79
+ if (cliCommand === "wizard" || cliCommand === "init") {
80
+ process.exit(await runWizardCli(process.argv.slice(3)));
81
+ }
82
+ if (cliCommand === "doctor") {
83
+ process.exit(await runDoctorCli(process.argv.slice(3)));
84
+ }
72
85
 
73
86
  // Apply config/secrets.map (or the shipped example table) before any site
74
87
  // resolution. MCP clients spawn this file directly; the shell launcher is
@@ -129,8 +142,7 @@ async function discoverableTools() {
129
142
  /**
130
143
  * Resolve a resource URI to its JSON payload. URIs are matched in order; the
131
144
  * templated forms (content-types, security-policy) capture the site name and
132
- * delegate to the corresponding read-only tool handler so resources and tools
133
- * always return the same shape.
145
+ * go through {@link invokeReadTool} so resources and tools share middleware.
134
146
  *
135
147
  * @param {string} uri - A drupal:// resource URI.
136
148
  * @returns {Promise<object>} The resource data (later JSON-serialized).
@@ -148,25 +160,13 @@ async function readResource(uri) {
148
160
  // drupal://{site}/content-types
149
161
  const ctMatch = uri.match(/^drupal:\/\/([^/]+)\/content-types$/);
150
162
  if (ctMatch) {
151
- assertPrincipalEntitlement({
152
- toolName: "drupal_list_content_types",
153
- args: { site: ctMatch[1] },
154
- identity,
155
- sites,
156
- });
157
- return allHandlers.drupal_list_content_types({ site: ctMatch[1] });
163
+ return invokeReadTool("drupal_list_content_types", { site: ctMatch[1] });
158
164
  }
159
165
 
160
166
  // drupal://{site}/security-policy
161
167
  const spMatch = uri.match(/^drupal:\/\/([^/]+)\/security-policy$/);
162
168
  if (spMatch) {
163
- assertPrincipalEntitlement({
164
- toolName: "drupal_security_info",
165
- args: { site: spMatch[1] },
166
- identity,
167
- sites,
168
- });
169
- return allHandlers.drupal_security_info({ site: spMatch[1] });
169
+ return invokeReadTool("drupal_security_info", { site: spMatch[1] });
170
170
  }
171
171
 
172
172
  throw new Error(`Unknown resource URI: ${uri}`);
@@ -236,3 +236,25 @@ export async function callTool(name, args, context = {}) {
236
236
  return toolError(err);
237
237
  }
238
238
  }
239
+
240
+ /**
241
+ * Run a read tool through {@link callTool} and unwrap the MCP envelope.
242
+ * `resources/read` uses this so those URIs cannot skip middleware.
243
+ *
244
+ * @param {string} name Tool name.
245
+ * @param {object} args Tool arguments.
246
+ * @param {object} [context] Optional inbound identity / grant overrides.
247
+ * @returns {Promise<*>} The tool payload.
248
+ * @throws {Error} When the tool is missing, denied, or returns isError.
249
+ */
250
+ export async function invokeReadTool(name, args, context = {}) {
251
+ const result = await callTool(name, args, context);
252
+ if (result?.isError) {
253
+ throw new Error(result.content?.[0]?.text ?? `Tool "${name}" failed`);
254
+ }
255
+ const text = result?.content?.[0]?.text;
256
+ if (typeof text !== "string") {
257
+ throw new Error(`Tool "${name}" returned no payload`);
258
+ }
259
+ return JSON.parse(text);
260
+ }