icode-mcp-adapter 1.0.12 → 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",
|
|
@@ -154,6 +154,7 @@ export async function resolveSchemas(db, tableConfigs, opts = {}) {
|
|
|
154
154
|
ownerColumn,
|
|
155
155
|
columns,
|
|
156
156
|
...(config.customDescriptions && { customDescriptions: config.customDescriptions }),
|
|
157
|
+
...(config.customTools && { customTools: config.customTools }),
|
|
157
158
|
});
|
|
158
159
|
}
|
|
159
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
|