icode-mcp-adapter 1.0.0 → 1.0.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/README.md +131 -0
- package/package.json +1 -1
package/README.md
ADDED
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# icode-mcp-adapter
|
|
2
|
+
|
|
3
|
+
Dynamic MCP server adapter for icode-server. Auto-generates CRUD tools from your existing database tables — column metadata resolved from `INFORMATION_SCHEMA` at runtime.
|
|
4
|
+
|
|
5
|
+
## What it does
|
|
6
|
+
|
|
7
|
+
Given a lightweight config like this:
|
|
8
|
+
|
|
9
|
+
```js
|
|
10
|
+
{
|
|
11
|
+
name: 'myapp',
|
|
12
|
+
dbEnv: 'dev',
|
|
13
|
+
tables: {
|
|
14
|
+
users: { operations: ['list', 'get', 'add', 'update'] },
|
|
15
|
+
orders: { operations: ['list', 'get', 'add', 'update', 'delete'] },
|
|
16
|
+
},
|
|
17
|
+
}
|
|
18
|
+
```
|
|
19
|
+
|
|
20
|
+
It auto-generates MCP tools: `list_users`, `get_user`, `add_user`, `update_user`, `list_orders`, `get_order`, `add_order`, `update_order`, `delete_order` — with proper Zod input schemas, SQL queries, and error handling.
|
|
21
|
+
|
|
22
|
+
No manual column definitions. The adapter reads your DB schema and figures out types, PKs, required fields, enums, defaults, and soft delete.
|
|
23
|
+
|
|
24
|
+
## icode-server conventions
|
|
25
|
+
|
|
26
|
+
- **Primary key**: `guid` (string), fallback to `pk`
|
|
27
|
+
- **Soft delete**: `_deleted = 0` (active) / `_deleted = 1` (deleted)
|
|
28
|
+
- **Timestamps**: `_created`, `_time` (epoch ms, auto-managed)
|
|
29
|
+
- **Meta fields**: `_created`, `_createdBy`, `_time`, `_by`, `_deleted`, `pk` — all readOnly
|
|
30
|
+
|
|
31
|
+
## Install
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install icode-mcp-adapter @modelcontextprotocol/sdk zod
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Usage in icode-server
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// instacode.js
|
|
41
|
+
import mcpPlugin from 'icode-mcp-adapter/fastify';
|
|
42
|
+
import { getAppDbService } from './services/connectionService.mjs';
|
|
43
|
+
import paaalConfig from './plugins/mcp/configs/paaal.config.js';
|
|
44
|
+
|
|
45
|
+
await app.register(mcpPlugin, {
|
|
46
|
+
apps: { paaal: paaalConfig },
|
|
47
|
+
getDb: (appName, env) => getAppDbService(appName, env),
|
|
48
|
+
});
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
This registers:
|
|
52
|
+
- `POST /v1/mcp/:appName` — MCP protocol endpoint
|
|
53
|
+
- `DELETE /v1/mcp/:appName` — session termination
|
|
54
|
+
- `GET /v1/mcp/:appName/health` — health check
|
|
55
|
+
|
|
56
|
+
## App config format
|
|
57
|
+
|
|
58
|
+
```js
|
|
59
|
+
// plugins/mcp/configs/myapp.config.js
|
|
60
|
+
export default {
|
|
61
|
+
name: 'myapp',
|
|
62
|
+
displayName: 'My App',
|
|
63
|
+
version: '1.0.0',
|
|
64
|
+
dbEnv: 'dev',
|
|
65
|
+
tables: {
|
|
66
|
+
users: {
|
|
67
|
+
operations: ['list', 'get', 'add', 'update', 'delete'],
|
|
68
|
+
listOrderBy: '`_created` DESC',
|
|
69
|
+
columns: {
|
|
70
|
+
email: { description: 'User email address' },
|
|
71
|
+
},
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
};
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
### Table options
|
|
78
|
+
|
|
79
|
+
| Option | Default | Description |
|
|
80
|
+
|---|---|---|
|
|
81
|
+
| `operations` | `['list','get','add','update']` | Which CRUD tools to generate |
|
|
82
|
+
| `pkType` | auto-detected | `'string'` (guid) or `'auto'` (int) |
|
|
83
|
+
| `softDelete` | auto (true if `_deleted` exists) | Soft delete via `_deleted` flag |
|
|
84
|
+
| `singular` | auto-derived (`users`→`user`) | Tool name prefix: `add_user` |
|
|
85
|
+
| `listOrderBy` | `_created DESC` | SQL ORDER BY clause |
|
|
86
|
+
| `columns` | `{}` | Per-column overrides (description, type, filterable) |
|
|
87
|
+
|
|
88
|
+
### Auto-detection from INFORMATION_SCHEMA
|
|
89
|
+
|
|
90
|
+
| DB trait | Detected as |
|
|
91
|
+
|---|---|
|
|
92
|
+
| `guid` column | `primaryKey: 'guid'`, `pkType: 'string'` |
|
|
93
|
+
| `_deleted` column | soft delete: `WHERE _deleted = 0`, delete sets `_deleted = 1` |
|
|
94
|
+
| `_created` | autoSet (epoch ms), readOnly |
|
|
95
|
+
| `_time`, `_by`, `_createdBy`, `pk` | readOnly (meta fields) |
|
|
96
|
+
| `tinyint(1)` | boolean |
|
|
97
|
+
| `ENUM(...)` | enum with parsed values |
|
|
98
|
+
| `IS_NULLABLE = 'NO'` + no default | required |
|
|
99
|
+
| `COLUMN_KEY = 'MUL'` or `*_id` | filterable |
|
|
100
|
+
|
|
101
|
+
## Plugin options
|
|
102
|
+
|
|
103
|
+
```js
|
|
104
|
+
await app.register(mcpPlugin, {
|
|
105
|
+
apps: { ... }, // required — app configs keyed by name
|
|
106
|
+
getDb: (name, env) => {}, // required — returns db with .query()
|
|
107
|
+
prefix: '/v1/mcp', // optional — route prefix (default: /v1/mcp)
|
|
108
|
+
public: true, // optional — route visibility for AuthGate (default: true)
|
|
109
|
+
});
|
|
110
|
+
```
|
|
111
|
+
|
|
112
|
+
## Exports
|
|
113
|
+
|
|
114
|
+
```js
|
|
115
|
+
import { createMcpServer, createMcpServerAuto } from 'icode-mcp-adapter/engine';
|
|
116
|
+
import { resolveSchemas, clearSchemaCache } from 'icode-mcp-adapter/schema';
|
|
117
|
+
import { registerTableTools } from 'icode-mcp-adapter/tools';
|
|
118
|
+
import mcpPlugin from 'icode-mcp-adapter/fastify';
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
## Testing
|
|
122
|
+
|
|
123
|
+
```bash
|
|
124
|
+
npm test # smoke test (no DB required)
|
|
125
|
+
npm run sandbox # Express server on :3000 (needs .env with DB creds)
|
|
126
|
+
npm run inspector # MCP Inspector UI (needs .env with DB creds)
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Full integration guide
|
|
130
|
+
|
|
131
|
+
See [INTEGRATION.md](./INTEGRATION.md) for step-by-step setup, nginx config, Claude Desktop connection, and architecture details.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "icode-mcp-adapter",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.1",
|
|
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",
|