@aikdna/kdna-mcp-server 0.4.1 → 0.5.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.
Files changed (3) hide show
  1. package/README.md +204 -91
  2. package/bin/kdna-mcp.mjs +1351 -181
  3. package/package.json +18 -10
package/README.md CHANGED
@@ -1,115 +1,228 @@
1
1
  # KDNA MCP Server
2
2
 
3
- `@aikdna/kdna-mcp-server` exposes KDNA as MCP tools so agent runtimes can use
4
- packaged `.kdna` assets without learning the container internals. Stdio-only,
5
- minimal footprint. The npm package source lives in this repository under
6
- [`mcp-server/`](./); there is no separate public `kdna-mcp-server` repository.
7
-
8
- ## Why MCP instead of the kdna-loader skill?
9
-
10
- The `kdna-loader` skill teaches an agent the full toolchain-only protocol:
11
- routing, planning, Capsule loading, application, and boundary respect. The MCP
12
- server provides a lower-level bridge for structured tool calls.
13
-
14
- | Approach | Best for |
15
- |----------|----------|
16
- | `kdna-loader` skill | Full KDNA protocol: routing, fit evaluation, silent application |
17
- | MCP server | Programmatic inspect/verify/load/match from any MCP-compatible runtime |
18
-
19
- ## Tools
20
-
21
- | Tool | Purpose | Input | Output |
22
- |------|---------|-------|--------|
23
- | `kdna.inspect` | Inspect a `.kdna` asset | File path | Structured metadata |
24
- | `kdna.verify` | Verify asset integrity state | File path | Pass/fail with reasons |
25
- | `kdna.plan-load` | Return Core LoadPlan before loading | File path, optional password or entitlement state | LoadPlan JSON |
26
- | `kdna.load` | Load an authorized `.kdna` profile | File path, optional profile, password, or entitlement state | Runtime Capsule |
27
- | `kdna.available-local` | List local `.kdna` assets | Root directory | Local asset inventory |
28
- | `kdna.match` | Rank candidate assets for a task string | Task description | Scored list with fit signals |
29
-
30
- ## Install & Run
3
+ `@aikdna/kdna-mcp-server` is a thin stdio MCP adapter for user-approved
4
+ workspace attachments. It delegates integrity, authorization, resolver, plan,
5
+ and load decisions to the pinned KDNA CLI/Core runtime. A user-selected
6
+ explicit file uses the official CLI through the loader Skill, not an
7
+ arbitrary-path MCP tool.
8
+
9
+ ## Source status
10
+
11
+ The `0.5.0` source tree is a Development Preview candidate whose component tests
12
+ bind the exact `@aikdna/kdna-cli@0.36.0` candidate and its single
13
+ `@aikdna/kdna-core@0.21.0` runtime. Host delivery and semantic adoption pass on
14
+ the OpenCode `1.18.11` ordinary-task single-Host loop
15
+ (`VERIFIED_SINGLE_HOST_ORDINARY_TASK`); the Codex ordinary-task rerun remains
16
+ `RECHECK_REQUIRED` pending account recovery, Creation-to-Consumption
17
+ integration is `RECHECK_REQUIRED`, and real-human acceptance is `NOT_RUN`.
18
+ Those two dependency versions are not yet registry releases, so this source
19
+ checkpoint is not installable from npm and makes no publication claim.
20
+
21
+ The retained CLI tar has one exact 32-file package allowlist and no Eval
22
+ dependency, retired command source, global Store path, or bundled legacy
23
+ Skill. MCP consumes that closed tar without adding another CLI capability
24
+ surface.
25
+
26
+ The npm registry still serves MCP `0.4.2`; that historical package is not the
27
+ workspace-attachment candidate described here.
28
+
29
+ ## Tool boundary
30
+
31
+ | Tool | Purpose |
32
+ | ------------------------ | ------------------------------------------------------------------- |
33
+ | `kdna.workspace-status` | Show only approved attachments for the supplied workspace |
34
+ | `kdna.workspace-resolve` | Resolve one task against that approved set |
35
+ | `kdna.workspace-load` | Resolve, plan, authorize, and load only when the decision is `load` |
36
+
37
+ There is no global discovery, task-to-asset matching, attachment mutation,
38
+ password tool argument, or caller-supplied entitlement state. The adapter
39
+ cannot attach, enable, disable, switch, roll back, or remove a workspace
40
+ attachment.
41
+
42
+ The candidate does not expose generic explicit-file inspect, verify, plan, or
43
+ load tools. Standard Codex/OpenCode MCP clients do not supply a native,
44
+ model-hidden file-selection broker, so a model-supplied path cannot prove user
45
+ intent. The public loader Skill instead performs one official CLI `kdna load`
46
+ after one meaningful use-once file approval; that call validates and plans
47
+ internally and creates no persistent attachment.
48
+
49
+ The three workspace tools are the automatic project flow because every result
50
+ remains bound to the immutable root, approved attachment record, policy scope,
51
+ and snapshot. Host configurations must enumerate those three exact tools and
52
+ must not use a server-wide wildcard.
53
+
54
+ ## Host processing consent
55
+
56
+ Attachment approval makes exact workspace bytes eligible for resolution. It
57
+ does **not** authorize a Host to deliver a decrypted Runtime Capsule to an
58
+ unknown processor. Before the first successful load, the Host must turn one
59
+ plain-language approval into a private machine document. The adapter starts
60
+ with the fixed Host identity and fixed private document path:
61
+
62
+ - `KDNA_MCP_HOST_ID`, the fixed Host identity;
63
+ - `KDNA_MCP_HOST_PROCESSING_CONSENT_FILE`, a regular mode-`0600` document in a
64
+ mode-`0700` Host-private directory.
65
+
66
+ The machine document binds the exact workspace root, asset digest, attachment
67
+ and scope, named remote processor, and least
68
+ Capsule profile. The user sees the asset name, purpose and boundary, Host,
69
+ named destination, and Allow/Decline action. The Host—not the user—handles
70
+ attachment IDs, record/task/plan digests, schema versions, scope modes,
71
+ approval-source values, and profile identifiers.
72
+
73
+ The CLI `0.36.0` source candidate includes a low-level `kdna host-consent`
74
+ broker for validating a private Host draft, interactive Allow/Decline, atomic
75
+ installation, rotation, status and revocation. A real Host launcher must derive
76
+ that draft from trusted attachment/LoadPlan facts; neither a user nor a model
77
+ should handcraft it. The current broker terminal prompt still displays the
78
+ exact digest and role/scope mechanics, so direct CLI use is an evaluator path,
79
+ not yet the human-only default surface described above.
80
+
81
+ The consent is reusable only inside those exact declared coordinates. Asset
82
+ bytes, attachment scope, Host, destination, workspace, profile, or user-control
83
+ drift requires a new meaningful approval. A Host can atomically replace the
84
+ document at the same fixed private path, so a long-running MCP process accepts
85
+ the newly approved coordinates without restart. A change during one load
86
+ suppresses that result; the request must be retried against the new consent.
87
+ Tool arguments cannot select or replace this authority. The adapter rejects an
88
+ unknown destination and will not accept a remote Host's self-asserted
89
+ `verified_local_only` label. Verifiable local-model processing is deferred in
90
+ this source candidate; only a named processing destination is implemented.
91
+ Consent files are adapter-private coordinates, not Runtime Capsule fields, and
92
+ the adapter never writes a decrypted Capsule copy to disk.
93
+
94
+ For an exact password-protected workspace attachment, the Host process may set
95
+ `KDNA_MCP_AUTHORIZATION_FILE` to one absolute, regular, non-symlink file owned
96
+ by the current user and private to that user. The adapter reads the bounded
97
+ value only when the selected LoadPlan requires a password, passes it only to
98
+ the pinned CLI through `load --password-stdin`, removes the coordinate from
99
+ the CLI child environment, and never returns it. The caller owns creation and
100
+ destruction of this process-scoped file on success, cancellation, or Host
101
+ exit; do not place it in the workspace or Host configuration repository.
102
+ Without a provider, a protected workspace load returns
103
+ structured `authorization_required`. A wrong value returns
104
+ `authorization_rejected` without echoing it. Ordinary public assets neither
105
+ require nor consume the provider. `pass` is a development credential source,
106
+ not a user product requirement.
107
+
108
+ This authorization-file contract is a component integration boundary, not a
109
+ manual user workflow. A user must not create the file, export the coordinate,
110
+ or send a password through model chat. Codex and OpenCode have not yet proven
111
+ a native model-hidden secret provider, so protected workspace loading in those
112
+ Host guides remains deferred. The ordinary unencrypted workspace path is
113
+ independent and does not consume this provider.
114
+
115
+ `kdna.workspace-load` visibly returns the `load`, `ask`, `skip`, or `block`
116
+ decision, exact identity/version/digest, configured scope, reason, integrity
117
+ and authorization conclusions, CLI control commands, LoadPlan, and—only after
118
+ a permitted load—the Runtime Capsule. When the loaded Capsule carries judgment
119
+ axioms, the adoption result also includes `judgment_decision` at the top level:
120
+ the rules with their `applies_when`, `does_not_apply_when`, and `failure_risk`
121
+ are surfaced there so a Host can bind them as decision criteria instead of
122
+ treating the projection as a mere task-direction hint.
123
+
124
+ ## Candidate development
125
+
126
+ The checked-in lock uses exact merged CLI and Core tarballs only for source and
127
+ CI acceptance. Candidate artifacts are excluded from the published MCP pack.
31
128
 
32
129
  ```bash
33
- npm install -g @aikdna/kdna-mcp-server
34
- kdna-mcp
35
- ```
36
-
37
- ### Configure in your MCP client
38
-
39
- **Claude App / Claude Code (`claude_desktop_config.json`):**
40
-
41
- ```json
42
- {
43
- "mcpServers": {
44
- "kdna": {
45
- "command": "npx",
46
- "args": ["-y", "@aikdna/kdna-mcp-server"]
47
- }
48
- }
49
- }
130
+ cd mcp-server
131
+ npm ci --ignore-scripts
132
+ npm test
133
+ node bin/kdna-mcp.mjs
50
134
  ```
51
135
 
52
- **Codex:**
136
+ The release dependency guard intentionally rejects the candidate lock. A
137
+ future registry release requires the exact CLI and Core versions to exist on
138
+ the official npm registry and a freshly generated lock with no `file:`
139
+ resolution before MCP publication can proceed.
53
140
 
54
- ```json
55
- {
56
- "mcpServers": {
57
- "kdna": {
58
- "command": "npx",
59
- "args": ["-y", "@aikdna/kdna-mcp-server"]
60
- }
61
- }
62
- }
63
- ```
141
+ ## Host configuration candidate
64
142
 
65
- **OpenCode (`opencode.json`):**
143
+ During source acceptance, configure exactly one Host with the local server
144
+ entry, then test it before configuring another Host:
66
145
 
67
146
  ```json
68
147
  {
69
148
  "mcpServers": {
70
149
  "kdna": {
71
- "command": "npx",
72
- "args": ["-y", "@aikdna/kdna-mcp-server"]
150
+ "command": "node",
151
+ "args": ["/absolute/path/to/kdna-skills/mcp-server/bin/kdna-mcp.mjs"],
152
+ "env": {
153
+ "KDNA_MCP_WORKSPACE_ROOT": "/absolute/path/to/one/project",
154
+ "KDNA_MCP_HOST_ID": "one-host",
155
+ "KDNA_MCP_HOST_PROCESSING_CONSENT_FILE": "/absolute/private/host/processing-consent.json"
156
+ }
73
157
  }
74
158
  }
75
159
  }
76
160
  ```
77
161
 
78
- ## Environment Variables
162
+ Configuration location, approval policy, and shape remain Host-specific. Do
163
+ not copy this entry into every installed Host automatically. The
164
+ [Codex](../integrations/codex/README.md) and
165
+ [OpenCode](../integrations/opencode/README.md) guides are benchmark
166
+ configuration candidates; OpenCode is verified at `1.18.11` for the
167
+ ordinary-task single-Host loop and Codex remains `RECHECK_REQUIRED` pending
168
+ account recovery.
79
169
 
80
- | Variable | Purpose |
81
- |----------|---------|
82
- | `KDNA_ASSET_DIR` | Root directory for `kdna.available-local`; overrides the default |
83
- | `KDNA_PACKAGE_DIR` | Package directory fallback for `kdna.available-local` |
84
- | `KDNA_DATA_ROOT` | Override KDNA data directory (default: `~/.kdna`) |
170
+ ## Workspace flow
85
171
 
86
- When no override is provided, `kdna.available-local` scans
87
- `~/.kdna/packages`. Explicit local roots can be provided when a user keeps
88
- assets elsewhere.
89
-
90
- ## Local Development
172
+ The user creates the relationship through the CLI, outside MCP:
91
173
 
92
174
  ```bash
93
- cd mcp-server
94
- npm install
95
- node bin/kdna-mcp.mjs
175
+ secure-host-attachment-json | kdna attach ./judgment.kdna \
176
+ --cwd ./my-project --attachment-stdin --preview
177
+ secure-host-attachment-json | kdna attach ./judgment.kdna \
178
+ --cwd ./my-project --attachment-stdin --yes \
179
+ --consent-digest sha256:<digest-from-preview>
180
+ kdna attachments --cwd ./my-project
96
181
  ```
97
182
 
98
- ## Example: Verify and Load a Domain via MCP
99
-
100
- ```
101
- # Client calls kdna.available-local { root: "./dist" }
102
- # Client calls kdna.verify { assetPath: "./dist/writing.kdna" }
103
- # Client calls kdna.plan-load { assetPath: "./dist/writing.kdna" }
104
- # Or kdna.plan-load { assetPath: "./dist/writing.kdna", entitlementStatus: "active" }
105
- # Client calls kdna.load { assetPath: "./dist/writing.kdna", profile: "compact" }
106
- # Agent consumes only the returned Runtime Capsule context
107
- ```
108
-
109
- ## Relationship to kdna-loader skill
110
-
111
- The MCP server and kdna-loader skill are complementary:
112
- - **kdna-loader** = agents that can run CLI commands (Codex, Claude Code, OpenCode, Cursor)
113
- - **MCP server** = any MCP-compatible runtime (including the above, plus custom agents)
114
-
115
- For most users, the kdna-loader skill (installed by `kdna setup`) is the recommended path. Use the MCP server when you need programmatic, tool-based access.
183
+ The Host's bounded stdin producer supplies identical final policy bytes to
184
+ preview and confirmation. Agent/MCP guidance must not expose private role or
185
+ scope in argv, and an unbound `--yes` is not consent.
186
+
187
+ For each task, the Host passes its current workspace and task to
188
+ `kdna.workspace-load`. The adapter passes bounded strict-UTF-8 task bytes to
189
+ the official resolver over stdin and never places them in argv, environment,
190
+ an incidental task file, or the attachment record. If the resolver returns
191
+ `ask`, `skip`, or `block`, no plan or capsule is produced. An `ask` includes a
192
+ receipt-bound one-task selection plan; after the user chooses, the Host repeats
193
+ the exact task and current root with that selection so the same request can
194
+ load exactly one candidate.
195
+
196
+ When the process authorization file is configured, the adapter asks the
197
+ official resolver to evaluate only the protected attachment's public scope
198
+ while authorization remains `required`. It then obtains the ordinary
199
+ pre-authorization LoadPlan and invokes the real password-verified load. Only a
200
+ successful decryption upgrades the delivered adoption result to
201
+ `authorization: "satisfied"` and includes a Runtime Capsule.
202
+
203
+ The workspace argument must resolve inside the MCP process's mandatory
204
+ `KDNA_MCP_WORKSPACE_ROOT`. That absolute root is fixed at process launch,
205
+ cannot be supplied or changed by a tool call, and must not be HOME or a
206
+ filesystem root, or symlink. The adapter passes the same root to every CLI status/resolver lookup,
207
+ rejects sibling or parent escapes and home-level attachment authority, and
208
+ selects only the nearest record inside the boundary. One load remains bound to
209
+ the same exact workspace record, selected attachment, scope, and snapshot
210
+ through result delivery. If any of those facts changes, the adapter returns
211
+ `workspace_binding_changed` without a Runtime Capsule and does not re-resolve
212
+ against another workspace.
213
+
214
+ One qualified Host can complete one functional consumption loop. The current
215
+ Codex+OpenCode pair is a separate portability benchmark, not a requirement for
216
+ every installation. Studio product integration is deferred and must later
217
+ reuse the CLI/Core state rather than introduce another attachment authority.
218
+
219
+ ## Host responsibility
220
+
221
+ The Host must keep adoption visible and preserve current facts, explicit user
222
+ intent, law, safety policy, system instructions, and Host permissions above
223
+ asset content. It must not treat output quality as authorization or use an
224
+ unattached file merely because it exists.
225
+
226
+ The MCP transport protocol coordinate `2024-11-05` is independent of KDNA's
227
+ runtime contracts. Returning a Runtime Capsule does not claim Host execution,
228
+ fabricate a receipt, or create a Judgment Trace.