@aikdna/kdna-mcp-server 0.4.2 → 0.5.1

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/NOTICE CHANGED
@@ -5,5 +5,11 @@ http://www.apache.org/licenses/LICENSE-2.0
5
5
 
6
6
  Copyright (c) 2026 KDNA Team
7
7
 
8
- This repository contains KDNA skill files (kdna-loader, kdna-create) and
9
- the install.sh installer. Skill files are licensed under Apache-2.0.
8
+ This package contains a local stdio Read MCP adapter for one explicitly
9
+ operator-bound KDNA asset. Its parent repository contains the kdna-loader
10
+ and kdna-creator Skill guides and explicit installers.
11
+ Skill files are licensed under Apache-2.0.
12
+
13
+ The fixed runtime archives retain their own package licenses and notices.
14
+ Synthetic native regression data and its generator are Apache-2.0 source
15
+ fixtures, excluded from the runtime package.
package/README.md CHANGED
@@ -1,128 +1 @@
1
- # KDNA MCP Server
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-presence 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
31
-
32
- The commands below currently resolve the published MCP 0.4.1 package. They do
33
- not install or prove the MCP 0.4.2 / Core 0.20.0 source checkpoint described in
34
- this repository's current changelog; those candidates must remain a coordinated
35
- package set and must not be mixed with the published wave.
36
-
37
- ```bash
38
- npm install -g @aikdna/kdna-mcp-server
39
- kdna-mcp
40
- ```
41
-
42
- ### Configure in your MCP client
43
-
44
- **Claude App / Claude Code (`claude_desktop_config.json`):**
45
-
46
- ```json
47
- {
48
- "mcpServers": {
49
- "kdna": {
50
- "command": "npx",
51
- "args": ["-y", "@aikdna/kdna-mcp-server"]
52
- }
53
- }
54
- }
55
- ```
56
-
57
- **Codex:**
58
-
59
- ```json
60
- {
61
- "mcpServers": {
62
- "kdna": {
63
- "command": "npx",
64
- "args": ["-y", "@aikdna/kdna-mcp-server"]
65
- }
66
- }
67
- }
68
- ```
69
-
70
- **OpenCode (`opencode.json`):**
71
-
72
- ```json
73
- {
74
- "mcpServers": {
75
- "kdna": {
76
- "command": "npx",
77
- "args": ["-y", "@aikdna/kdna-mcp-server"]
78
- }
79
- }
80
- }
81
- ```
82
-
83
- ## Environment Variables
84
-
85
- | Variable | Purpose |
86
- |----------|---------|
87
- | `KDNA_ASSET_DIR` | Root directory for `kdna.available-local`; overrides the default |
88
- | `KDNA_PACKAGE_DIR` | Package directory fallback for `kdna.available-local` |
89
- | `KDNA_DATA_ROOT` | Override KDNA data directory (default: `~/.kdna`) |
90
-
91
- When no override is provided, `kdna.available-local` scans
92
- `~/.kdna/packages`. Explicit local roots can be provided when a user keeps
93
- assets elsewhere.
94
-
95
- ## Local Development
96
-
97
- ```bash
98
- cd mcp-server
99
- npm install
100
- node bin/kdna-mcp.mjs
101
- ```
102
-
103
- ## Example: Verify and Load a Domain via MCP
104
-
105
- ```
106
- # Client calls kdna.available-local { root: "./dist" }
107
- # Client calls kdna.verify { assetPath: "./dist/writing.kdna" }
108
- # Client calls kdna.plan-load { assetPath: "./dist/writing.kdna" }
109
- # Or kdna.plan-load { assetPath: "./dist/writing.kdna", entitlementStatus: "active" }
110
- # Client calls kdna.load { assetPath: "./dist/writing.kdna", profile: "compact" }
111
- # Agent consumes only the returned Runtime Capsule context
112
- ```
113
-
114
- In the 0.4.2 source checkpoint, the returned Capsule uses
115
- `type: "kdna.runtime-capsule"` and
116
- `contract_version: "0.1.0"`. The KDNA Agent Host protocol has the independent
117
- coordinate `protocol_version: "0.1.0"`; it is not the MCP transport's
118
- `protocolVersion`. This bridge does not execute an Agent Host and therefore
119
- does not create or claim a Host receipt or Judgment Trace. A consuming Host
120
- must use Core's correlated runtime-contract APIs for that boundary.
121
-
122
- ## Relationship to kdna-loader skill
123
-
124
- The MCP server and kdna-loader skill are complementary:
125
- - **kdna-loader** = agents that can run CLI commands (Codex, Claude Code, OpenCode, Cursor)
126
- - **MCP server** = any MCP-compatible runtime (including the above, plus custom agents)
127
-
128
- 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.
1
+ This npm coordinate is retired. The current KDNA MCP server is delivered from the Git channel aikdna/kdna-skills and is not published to npm. The supported stable npm surface is the five stable packages (Core, Read, CLI, Studio Core, Studio CLI). This coordinate is not an install path and is not a sixth stable package.
package/bin/kdna-mcp.mjs CHANGED
@@ -1,405 +1,7 @@
1
1
  #!/usr/bin/env node
2
- import fs from 'node:fs';
3
- import os from 'node:os';
4
- import path from 'node:path';
5
- import readline from 'node:readline';
6
- import { spawnSync } from 'node:child_process';
7
- import { createRequire } from 'node:module';
8
-
9
- const require = createRequire(import.meta.url);
10
- const Ajv = require('ajv');
11
- const Ajv2020 = require('ajv/dist/2020');
12
- const addFormats = require('ajv-formats');
13
- const loadPlanSchema = require('@aikdna/kdna-core/schema/load-plan.schema.json');
14
- const packageInfo = require('../package.json');
15
- const {
16
- detectContainerFormat,
17
- inspect,
18
- load,
19
- matchDomain,
20
- planLoad,
21
- validate,
22
- } = require('@aikdna/kdna-core');
23
-
24
- const tools = [
25
- {
26
- name: 'kdna.inspect',
27
- description: 'Inspect a .kdna asset without extracting it.',
28
- inputSchema: {
29
- type: 'object',
30
- additionalProperties: false,
31
- required: ['assetPath'],
32
- properties: { assetPath: { type: 'string' }, verify: { type: 'boolean' } },
33
- },
34
- },
35
- {
36
- name: 'kdna.verify',
37
- description: 'Verify a .kdna asset integrity state.',
38
- inputSchema: {
39
- type: 'object',
40
- additionalProperties: false,
41
- required: ['assetPath'],
42
- properties: {
43
- assetPath: { type: 'string' },
44
- asset_digest: { type: 'string' },
45
- content_digest: { type: 'string' },
46
- requireSignature: { type: 'boolean' },
47
- },
48
- },
49
- },
50
- {
51
- name: 'kdna.load',
52
- description: 'Load a .kdna profile and return agent context.',
53
- inputSchema: {
54
- type: 'object',
55
- additionalProperties: false,
56
- required: ['assetPath'],
57
- properties: {
58
- assetPath: { type: 'string' },
59
- profile: { type: 'string', enum: ['index', 'compact', 'scenario', 'full'] },
60
- input: { type: 'string' },
61
- password: { type: 'string' },
62
- entitlementStatus: { type: 'string', enum: ['active', 'expired', 'revoked', 'offline_grace'] },
63
- },
64
- },
65
- },
66
- {
67
- name: 'kdna.plan-load',
68
- description: 'Return the Core LoadPlan for a .kdna asset before loading.',
69
- inputSchema: {
70
- type: 'object',
71
- additionalProperties: false,
72
- required: ['assetPath'],
73
- properties: {
74
- assetPath: { type: 'string' },
75
- hasPassword: { type: 'boolean' },
76
- entitlementStatus: { type: 'string', enum: ['active', 'expired', 'revoked', 'offline_grace'] },
77
- },
78
- },
79
- },
80
- {
81
- name: 'kdna.available-local',
82
- description: 'List local .kdna files without using a registry.',
83
- inputSchema: {
84
- type: 'object',
85
- additionalProperties: false,
86
- properties: {
87
- root: { type: 'string' },
88
- maxDepth: { type: 'integer', minimum: 0 },
89
- },
90
- },
91
- },
92
- {
93
- name: 'kdna.match',
94
- description: 'Rank .kdna assets for a task string.',
95
- inputSchema: {
96
- type: 'object',
97
- additionalProperties: false,
98
- required: ['input', 'assetPaths'],
99
- properties: {
100
- input: { type: 'string' },
101
- assetPaths: { type: 'array', items: { type: 'string' } },
102
- },
103
- },
104
- },
105
- ];
106
-
107
- const ajv = new Ajv({ allErrors: true, strict: false });
108
- const toolValidators = new Map(tools.map((tool) => [tool.name, ajv.compile(tool.inputSchema)]));
109
- const contractAjv = new Ajv2020({ allErrors: true, strict: false });
110
- addFormats(contractAjv);
111
- const validateLoadPlan = contractAjv.compile(loadPlanSchema);
112
-
113
- class JsonRpcError extends Error {
114
- constructor(code, message) {
115
- super(message);
116
- this.code = code;
117
- }
118
- }
119
-
120
- function validatedJsonRpcMessage(message) {
121
- if (!message || typeof message !== 'object' || Array.isArray(message)) {
122
- throw new JsonRpcError(-32600, 'Invalid Request');
123
- }
124
- if (message.jsonrpc !== '2.0' || typeof message.method !== 'string') {
125
- throw new JsonRpcError(-32600, 'Invalid Request');
126
- }
127
-
128
- const hasId = Object.prototype.hasOwnProperty.call(message, 'id');
129
- if (hasId) {
130
- const validId =
131
- typeof message.id === 'string' ||
132
- (typeof message.id === 'number' && Number.isFinite(message.id));
133
- if (!validId) throw new JsonRpcError(-32600, 'Invalid Request');
134
- }
135
-
136
- return {
137
- id: message.id,
138
- method: message.method,
139
- params: message.params === undefined ? {} : message.params,
140
- paramsValid:
141
- message.params === undefined ||
142
- (message.params !== null && typeof message.params === 'object' && !Array.isArray(message.params)),
143
- isNotification: !hasId,
144
- };
145
- }
146
-
147
- function sendResult(id, result) {
148
- process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, result })}\n`);
149
- }
150
-
151
- function sendError(id, code, message) {
152
- process.stdout.write(`${JSON.stringify({ jsonrpc: '2.0', id, error: { code, message } })}\n`);
153
- }
154
-
155
- function textResult(value) {
156
- return {
157
- content: [{ type: 'text', text: typeof value === 'string' ? value : JSON.stringify(value, null, 2) }],
158
- };
159
- }
160
-
161
- function toolErrorResult(error) {
162
- return {
163
- content: [{ type: 'text', text: error?.message || String(error) }],
164
- isError: true,
165
- };
166
- }
167
-
168
- function validatedToolCall(params) {
169
- if (!params || typeof params !== 'object' || Array.isArray(params)) {
170
- throw new JsonRpcError(-32602, 'Invalid params');
171
- }
172
- if (typeof params.name !== 'string' || !toolValidators.has(params.name)) {
173
- throw new JsonRpcError(-32602, 'Invalid params');
174
- }
175
- const args = params.arguments === undefined ? {} : params.arguments;
176
- const validateInput = toolValidators.get(params.name);
177
- if (!validateInput(args)) throw new JsonRpcError(-32602, 'Invalid params');
178
- return { name: params.name, args };
179
- }
180
-
181
- function isKdnaAsset(assetPath) {
182
- if (!assetPath) return false;
183
- try {
184
- if (!fs.existsSync(assetPath) || !fs.statSync(assetPath).isFile()) return false;
185
- return assetPath.endsWith('.kdna') && detectContainerFormat(assetPath) === 'kdna';
186
- } catch {
187
- return false;
188
- }
189
- }
190
-
191
- function defaultAssetRoot() {
192
- return process.env.KDNA_ASSET_DIR || process.env.KDNA_PACKAGE_DIR || path.join(os.homedir(), '.kdna', 'packages');
193
- }
194
-
195
- function findLocalAssets(root = defaultAssetRoot(), maxDepth = 3) {
196
- if (!root || !fs.existsSync(root)) return [];
197
- const found = [];
198
-
199
- function visit(dir, depth) {
200
- if (depth > maxDepth) return;
201
- let entries;
202
- try {
203
- entries = fs.readdirSync(dir, { withFileTypes: true });
204
- } catch {
205
- return;
206
- }
207
-
208
- for (const entry of entries) {
209
- if (entry.name === 'node_modules' || entry.name === '.git') continue;
210
- const full = path.join(dir, entry.name);
211
- if (entry.isDirectory()) {
212
- visit(full, depth + 1);
213
- } else if (entry.isFile() && entry.name.endsWith('.kdna')) {
214
- try {
215
- if (detectContainerFormat(full) !== 'kdna') continue;
216
- const inspection = inspect(full);
217
- const validation = validate(full);
218
- found.push({
219
- path: full,
220
- kind: 'kdna_asset',
221
- asset_id: inspection.asset_id,
222
- title: inspection.title,
223
- version: inspection.version,
224
- judgment_version: inspection.judgment_version,
225
- checksums_present: Boolean(inspection.checksums_present),
226
- loadable: Boolean(validation.overall_valid),
227
- problems: validation.overall_valid ? [] : validation.problems || [],
228
- });
229
- } catch {
230
- found.push({
231
- path: full,
232
- kind: 'kdna_asset',
233
- asset_id: null,
234
- title: null,
235
- version: null,
236
- judgment_version: null,
237
- checksums_present: false,
238
- loadable: false,
239
- problems: ['KDNA_ASSET_INVALID'],
240
- });
241
- }
242
- }
243
- }
244
- }
245
-
246
- visit(path.resolve(root), 0);
247
- return found;
248
- }
249
-
250
- function runCliPlanLoad(args = {}) {
251
- const cliArgs = ['plan-load', args.assetPath, '--json'];
252
- if (args.hasPassword) cliArgs.push('--has-password');
253
- if (args.entitlementStatus) cliArgs.push('--entitlement-status', args.entitlementStatus);
254
-
255
- const result = spawnSync('kdna', cliArgs, {
256
- encoding: 'utf8',
257
- timeout: 30_000,
258
- });
259
-
260
- if (result.error) {
261
- throw new Error(`Core planLoad is unavailable and kdna CLI failed: ${result.error.message}`);
262
- }
263
- if (result.status !== 0 && result.status !== 3) {
264
- throw new Error(`Core planLoad is unavailable and kdna CLI exited ${result.status}`);
265
- }
266
- let plan;
267
- try {
268
- if (result.stdout && result.stdout.trim()) plan = JSON.parse(result.stdout);
269
- } catch (error) {
270
- throw new Error(`Core planLoad is unavailable and kdna CLI returned non-JSON output: ${error.message}`);
271
- }
272
- if (!validateLoadPlan(plan)) {
273
- throw new Error('Core planLoad is unavailable and kdna CLI returned an invalid LoadPlan');
274
- }
275
- if (
276
- plan.source.kind !== 'file' ||
277
- path.resolve(plan.source.path) !== path.resolve(args.assetPath)
278
- ) {
279
- throw new Error('Core planLoad is unavailable and kdna CLI returned an uncorrelated LoadPlan');
280
- }
281
- if (result.status === 0 && plan.can_load_now !== true) {
282
- throw new Error('Core planLoad is unavailable and kdna CLI returned a non-loadable success');
283
- }
284
- if (result.status === 3 && plan.can_load_now !== false) {
285
- throw new Error('Core planLoad is unavailable and kdna CLI returned a loadable denial');
286
- }
287
- return plan;
288
- }
289
-
290
- function planLoadThroughCoreOrCli(args = {}) {
291
- if (!args.assetPath) throw new Error('assetPath is required');
292
-
293
- if (typeof planLoad === 'function' && process.env.KDNA_MCP_FORCE_CLI_PLAN_LOAD !== '1') {
294
- return planLoad(args.assetPath, {
295
- hasPassword: Boolean(args.hasPassword),
296
- entitlement: args.entitlementStatus ? { status: args.entitlementStatus } : undefined,
297
- });
298
- }
299
-
300
- return runCliPlanLoad(args);
301
- }
302
-
303
- async function callTool(name, args = {}) {
304
- if (name === 'kdna.inspect') {
305
- if (!isKdnaAsset(args.assetPath)) throw new Error('assetPath is not a current KDNA asset');
306
- return textResult(inspect(args.assetPath, { verify: args.verify !== false }));
307
- }
308
- if (name === 'kdna.verify') {
309
- if (!isKdnaAsset(args.assetPath)) throw new Error('assetPath is not a current KDNA asset');
310
- return textResult(validate(args.assetPath, {
311
- asset_digest: args.asset_digest,
312
- content_digest: args.content_digest,
313
- requireSignature: Boolean(args.requireSignature),
314
- }));
315
- }
316
- if (name === 'kdna.load') {
317
- if (!isKdnaAsset(args.assetPath)) throw new Error('assetPath is not a current KDNA asset');
318
- return textResult(load(args.assetPath, {
319
- profile: args.profile || 'compact',
320
- as: 'json',
321
- input: args.input || '',
322
- password: args.password,
323
- entitlement: args.entitlementStatus ? { status: args.entitlementStatus } : undefined,
324
- }));
325
- }
326
- if (name === 'kdna.plan-load') {
327
- return textResult(planLoadThroughCoreOrCli(args));
328
- }
329
- if (name === 'kdna.match') {
330
- return textResult(await matchDomain(args.input || '', args.assetPaths || []));
331
- }
332
- if (name === 'kdna.available-local') {
333
- return textResult(findLocalAssets(args.root, args.maxDepth ?? 3));
334
- }
335
- throw new Error(`Unknown tool: ${name}`);
336
- }
337
-
338
- async function handle({ id, method, params }) {
339
- if (method === 'initialize') {
340
- sendResult(id, {
341
- protocolVersion: '2024-11-05',
342
- capabilities: { tools: {} },
343
- serverInfo: { name: '@aikdna/kdna-mcp-server', version: packageInfo.version },
344
- });
345
- return;
346
- }
347
- if (method === 'tools/list') {
348
- sendResult(id, { tools });
349
- return;
350
- }
351
- if (method === 'tools/call') {
352
- let call;
353
- try {
354
- call = validatedToolCall(params);
355
- } catch (error) {
356
- if (error instanceof JsonRpcError) {
357
- sendError(id, error.code, error.message);
358
- return;
359
- }
360
- throw error;
361
- }
362
- try {
363
- sendResult(id, await callTool(call.name, call.args));
364
- } catch (error) {
365
- sendResult(id, toolErrorResult(error));
366
- }
367
- return;
368
- }
369
- if (id !== undefined) sendError(id, -32601, 'Method not found');
370
- }
371
-
372
- const rl = readline.createInterface({ input: process.stdin });
373
- rl.on('line', async (line) => {
374
- if (!line.trim()) return;
375
- let message;
376
- try {
377
- message = JSON.parse(line);
378
- } catch {
379
- sendError(null, -32700, 'Parse error');
380
- return;
381
- }
382
-
383
- let request;
384
- try {
385
- request = validatedJsonRpcMessage(message);
386
- } catch (error) {
387
- if (error instanceof JsonRpcError) {
388
- sendError(null, error.code, error.message);
389
- return;
390
- }
391
- sendError(null, -32603, 'Internal error');
392
- return;
393
- }
394
-
395
- if (request.isNotification) return;
396
- if (!request.paramsValid) {
397
- sendError(request.id, -32602, 'Invalid params');
398
- return;
399
- }
400
- try {
401
- await handle(request);
402
- } catch {
403
- sendError(request.id, -32603, 'Internal error');
404
- }
405
- });
2
+ // This npm coordinate is retired. The only behavior this bin may ever have is
3
+ // to print the approved retirement notice and exit non-zero: it never reads
4
+ // inputs, files, stdin, or the network.
5
+ const RETIREMENT = "This npm coordinate is retired. The current KDNA MCP server is delivered from the Git channel aikdna/kdna-skills and is not published to npm. The supported stable npm surface is the five stable packages (Core, Read, CLI, Studio Core, Studio CLI). This coordinate is not an install path and is not a sixth stable package.";
6
+ process.stderr.write(RETIREMENT + "\n");
7
+ process.exitCode = 1;
package/package.json CHANGED
@@ -1,53 +1,25 @@
1
1
  {
2
2
  "name": "@aikdna/kdna-mcp-server",
3
- "version": "0.4.2",
4
- "description": "MCP server for loading, inspecting, verifying, and matching KDNA .kdna assets.",
3
+ "version": "0.5.1",
4
+ "description": "This npm coordinate is retired. The current KDNA MCP server is delivered from the Git channel aikdna/kdna-skills and is not published to npm.",
5
5
  "type": "module",
6
- "homepage": "https://aikdna.com",
7
6
  "repository": {
8
7
  "type": "git",
9
8
  "url": "git+https://github.com/aikdna/kdna-skills.git",
10
- "directory": "mcp-server"
9
+ "directory": "mcp-server-retired"
11
10
  },
12
- "bugs": {
13
- "url": "https://github.com/aikdna/kdna-skills/issues"
14
- },
15
- "keywords": [
16
- "kdna",
17
- "mcp",
18
- "ai-agent",
19
- "judgment",
20
- "loadplan"
21
- ],
22
11
  "bin": {
23
12
  "kdna-mcp": "bin/kdna-mcp.mjs"
24
13
  },
14
+ "scripts": {
15
+ "test": "node --test test/retired.test.mjs"
16
+ },
25
17
  "files": [
26
18
  "bin/",
27
19
  "README.md",
28
20
  "LICENSE",
29
21
  "NOTICE"
30
22
  ],
31
- "scripts": {
32
- "test": "node scripts/verify-core-candidate.mjs && node ../scripts/check-current-names.mjs && node --test test/*.test.mjs",
33
- "check:core-candidate": "node scripts/verify-core-candidate.mjs",
34
- "check:current-names": "node ../scripts/check-current-names.mjs",
35
- "naming:check": "node ../scripts/check-current-names.mjs",
36
- "release:check": "node ../scripts/release-check.js",
37
- "release:dependency-guard": "node ../scripts/release-dependency-guard.js",
38
- "release:preflight": "node ../scripts/release-preflight.js",
39
- "prepublishOnly": "npm test && npm run release:check && npm run release:dependency-guard"
40
- },
41
23
  "license": "Apache-2.0",
42
- "dependencies": {
43
- "@aikdna/kdna-core": "0.20.0",
44
- "ajv": "^8.20.0",
45
- "ajv-formats": "^3.0.1"
46
- },
47
- "devDependencies": {
48
- "cbor-x": "^1.6.4"
49
- },
50
- "engines": {
51
- "node": ">=18"
52
- }
24
+ "private": false
53
25
  }