icode-mcp-adapter 1.0.11 → 1.0.13
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icode-mcp-adapter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13",
|
|
4
4
|
"description": "Dynamic MCP server adapter — auto-generates CRUD tools from schema configs. Plugs into icode-server via Fastify or runs standalone.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "src/engine/McpEngine.js",
|
|
@@ -45,6 +45,13 @@ const META_FIELDS = new Set([
|
|
|
45
45
|
'_by', // who last modified
|
|
46
46
|
'_deleted', // soft delete flag
|
|
47
47
|
'pk', // auto-increment secondary key
|
|
48
|
+
'_tenantId', // tenant marker (stamped by the host writer)
|
|
49
|
+
'_tzo', // timezone offset
|
|
50
|
+
'_vno', // version number
|
|
51
|
+
'_tag', // internal tagging
|
|
52
|
+
'org', // org partition
|
|
53
|
+
'settings', // per-row system settings json
|
|
54
|
+
'entitytype', // entity type marker (system-set)
|
|
48
55
|
]);
|
|
49
56
|
|
|
50
57
|
// ── Schema cache ─────────────────────────────────────────────────────────────
|
|
@@ -147,6 +154,7 @@ export async function resolveSchemas(db, tableConfigs, opts = {}) {
|
|
|
147
154
|
ownerColumn,
|
|
148
155
|
columns,
|
|
149
156
|
...(config.customDescriptions && { customDescriptions: config.customDescriptions }),
|
|
157
|
+
...(config.customTools && { customTools: config.customTools }),
|
|
150
158
|
});
|
|
151
159
|
}
|
|
152
160
|
|
|
@@ -97,6 +97,10 @@ export function registerTableTools(server, db, table, identity, newGuid, writer)
|
|
|
97
97
|
case 'delete': regDelete(server, db, table, display, owner, writer); break;
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
+
|
|
101
|
+
for (const [name, tool] of Object.entries(table.customTools || {})) {
|
|
102
|
+
regCustom(server, db, table, name, tool, owner, writer);
|
|
103
|
+
}
|
|
100
104
|
}
|
|
101
105
|
|
|
102
106
|
// ── LIST ──────────────────────────────────────────────────────────────────────
|
|
@@ -391,3 +395,40 @@ function regDelete(server, db, table, display, owner, writer) {
|
|
|
391
395
|
}
|
|
392
396
|
});
|
|
393
397
|
}
|
|
398
|
+
|
|
399
|
+
// ── CUSTOM TOOLS ──────────────────────────────────────────────────────────────
|
|
400
|
+
|
|
401
|
+
/**
|
|
402
|
+
* Register a hand-written tool from config: { title, description, inputs, handler }.
|
|
403
|
+
* `inputs` are ColumnDef-shaped descriptors ({ type, description, required, ... }).
|
|
404
|
+
* handler(args, ctx) gets { db, table, owner, writer, pkWhere, q } and may return
|
|
405
|
+
* a row object (JSON + structuredContent), a string (plain text), or a full MCP result.
|
|
406
|
+
*/
|
|
407
|
+
function regCustom(server, db, table, name, tool, owner, writer) {
|
|
408
|
+
const inputSchema = {};
|
|
409
|
+
for (const [arg, def] of Object.entries(tool.inputs || {})) {
|
|
410
|
+
inputSchema[arg] = zodFor({ name: arg, ...def });
|
|
411
|
+
}
|
|
412
|
+
|
|
413
|
+
server.registerTool(name, {
|
|
414
|
+
title: tool.title || name,
|
|
415
|
+
description: tool.description || '',
|
|
416
|
+
inputSchema,
|
|
417
|
+
}, async (args) => {
|
|
418
|
+
try {
|
|
419
|
+
const result = await tool.handler(args, {
|
|
420
|
+
db, table, owner, writer,
|
|
421
|
+
pkWhere: (pkVal) => pkWhere(table, pkVal, owner),
|
|
422
|
+
q,
|
|
423
|
+
});
|
|
424
|
+
if (typeof result === 'string') return { content: [{ type: 'text', text: result }] };
|
|
425
|
+
if (result?.content) return result;
|
|
426
|
+
return {
|
|
427
|
+
content: [{ type: 'text', text: JSON.stringify(result) }],
|
|
428
|
+
structuredContent: result,
|
|
429
|
+
};
|
|
430
|
+
} catch (error) {
|
|
431
|
+
return { content: [{ type: 'text', text: `Error: ${error.message}` }], isError: true };
|
|
432
|
+
}
|
|
433
|
+
});
|
|
434
|
+
}
|
package/src/engine/types.js
CHANGED
|
@@ -25,6 +25,14 @@
|
|
|
25
25
|
* @property {string} [listOrderBy] - Default ORDER BY clause (use backticks for reserved words)
|
|
26
26
|
* @property {string|null} [ownerColumn] - Row-level owner column; every query is scoped to the caller on it
|
|
27
27
|
* @property {Object} [customDescriptions] - Override tool descriptions per operation
|
|
28
|
+
* @property {Record<string, CustomTool>} [customTools] - Extra hand-written tools registered alongside the generated CRUD
|
|
29
|
+
*
|
|
30
|
+
* @typedef {Object} CustomTool
|
|
31
|
+
* @property {string} [title]
|
|
32
|
+
* @property {string} [description]
|
|
33
|
+
* @property {Record<string, ColumnDef>} [inputs] - Tool arguments as ColumnDef-shaped descriptors
|
|
34
|
+
* @property {(args: Object, ctx: { db, table, owner, writer, pkWhere: Function, q: Function }) => Promise<any>} handler
|
|
35
|
+
* - May return a row object (JSON + structuredContent), a string (plain text), or a full MCP result
|
|
28
36
|
*
|
|
29
37
|
* @typedef {Object} DbConfig
|
|
30
38
|
* @property {string} host
|