@enfyra/mcp-server 0.0.9 → 0.0.11
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 +1 -1
- package/src/index.mjs +103 -0
- package/src/lib/mcp-instructions.js +20 -4
package/package.json
CHANGED
package/src/index.mjs
CHANGED
|
@@ -351,6 +351,109 @@ server.tool('login', 'Force login to Enfyra and get new tokens', {
|
|
|
351
351
|
return { content: [{ type: 'text', text: `Logged in successfully!\nToken expires: ${new Date(getTokenExpiry()).toISOString()}` }] };
|
|
352
352
|
});
|
|
353
353
|
|
|
354
|
+
// ============================================================================
|
|
355
|
+
// PACKAGE TOOLS
|
|
356
|
+
// ============================================================================
|
|
357
|
+
|
|
358
|
+
server.tool(
|
|
359
|
+
'search_npm',
|
|
360
|
+
'Search NPM registry for packages. Returns name, version, description for installation.',
|
|
361
|
+
{
|
|
362
|
+
query: z.string().describe('Package name or search term (e.g., "axios", "node-ssh", "dayjs")'),
|
|
363
|
+
limit: z.number().optional().default(5).describe('Max results (default: 5)'),
|
|
364
|
+
},
|
|
365
|
+
async ({ query, limit }) => {
|
|
366
|
+
const url = `https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(query)}&size=${limit}`;
|
|
367
|
+
const response = await fetch(url);
|
|
368
|
+
if (!response.ok) throw new Error(`NPM search failed: ${response.statusText}`);
|
|
369
|
+
const data = await response.json();
|
|
370
|
+
|
|
371
|
+
const packages = data.objects.map((obj) => ({
|
|
372
|
+
name: obj.package.name,
|
|
373
|
+
version: obj.package.version,
|
|
374
|
+
description: obj.package.description || '',
|
|
375
|
+
}));
|
|
376
|
+
|
|
377
|
+
return {
|
|
378
|
+
content: [{
|
|
379
|
+
type: 'text',
|
|
380
|
+
text: JSON.stringify({ packages, total: data.total }, null, 2),
|
|
381
|
+
}],
|
|
382
|
+
};
|
|
383
|
+
},
|
|
384
|
+
);
|
|
385
|
+
|
|
386
|
+
server.tool(
|
|
387
|
+
'install_package',
|
|
388
|
+
[
|
|
389
|
+
'Install an NPM package on Enfyra. Searches NPM registry for exact version, then creates package_definition record.',
|
|
390
|
+
'Enfyra handles the actual yarn add internally based on type.',
|
|
391
|
+
'Type "Server" = available in handlers/hooks as $ctx.$pkgs.packageName.',
|
|
392
|
+
'Type "App" = available in extensions via getPackages().',
|
|
393
|
+
].join(' '),
|
|
394
|
+
{
|
|
395
|
+
name: z.string().describe('Exact NPM package name (e.g., "node-ssh", "axios")'),
|
|
396
|
+
type: z.enum(['Server', 'App']).default('Server').describe('Where to install: Server (handlers/hooks) or App (extensions)'),
|
|
397
|
+
version: z.string().optional().describe('Specific version. If omitted, fetches latest from NPM.'),
|
|
398
|
+
},
|
|
399
|
+
async ({ name, type, version }) => {
|
|
400
|
+
// Step 1: Get package info from NPM if version not specified
|
|
401
|
+
let pkgVersion = version;
|
|
402
|
+
let pkgDescription = '';
|
|
403
|
+
|
|
404
|
+
if (!pkgVersion) {
|
|
405
|
+
const npmUrl = `https://registry.npmjs.org/-/v1/search?text=${encodeURIComponent(name)}&size=5`;
|
|
406
|
+
const npmResponse = await fetch(npmUrl);
|
|
407
|
+
if (!npmResponse.ok) throw new Error(`NPM search failed: ${npmResponse.statusText}`);
|
|
408
|
+
const npmData = await npmResponse.json();
|
|
409
|
+
|
|
410
|
+
const exactMatch = npmData.objects.find((obj) => obj.package.name === name);
|
|
411
|
+
if (!exactMatch) throw new Error(`Package "${name}" not found on NPM`);
|
|
412
|
+
|
|
413
|
+
pkgVersion = exactMatch.package.version;
|
|
414
|
+
pkgDescription = exactMatch.package.description || '';
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
// Step 2: Check if already installed
|
|
418
|
+
const checkFilter = JSON.stringify({ name: { _eq: name } });
|
|
419
|
+
const existing = await fetchAPI(ENFYRA_API_URL, `/package_definition?filter=${encodeURIComponent(checkFilter)}&limit=1`);
|
|
420
|
+
if (existing.data && existing.data.length > 0) {
|
|
421
|
+
return {
|
|
422
|
+
content: [{
|
|
423
|
+
type: 'text',
|
|
424
|
+
text: `Package "${name}" is already installed (version: ${existing.data[0].version}, type: ${existing.data[0].type}).\n${JSON.stringify(existing.data[0], null, 2)}`,
|
|
425
|
+
}],
|
|
426
|
+
};
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Step 3: Get current user for installedBy
|
|
430
|
+
const me = await fetchAPI(ENFYRA_API_URL, '/me');
|
|
431
|
+
const userId = me.data?.[0]?.id || me.data?.[0]?._id;
|
|
432
|
+
if (!userId) throw new Error('Cannot get current user ID');
|
|
433
|
+
|
|
434
|
+
// Step 4: Install via package_definition
|
|
435
|
+
const body = {
|
|
436
|
+
name,
|
|
437
|
+
version: pkgVersion,
|
|
438
|
+
description: pkgDescription,
|
|
439
|
+
type,
|
|
440
|
+
installedBy: { id: userId },
|
|
441
|
+
};
|
|
442
|
+
|
|
443
|
+
const result = await fetchAPI(ENFYRA_API_URL, '/package_definition', {
|
|
444
|
+
method: 'POST',
|
|
445
|
+
body: JSON.stringify(body),
|
|
446
|
+
});
|
|
447
|
+
|
|
448
|
+
return {
|
|
449
|
+
content: [{
|
|
450
|
+
type: 'text',
|
|
451
|
+
text: `Package "${name}@${pkgVersion}" installed successfully (type: ${type}).\n${JSON.stringify(result, null, 2)}`,
|
|
452
|
+
}],
|
|
453
|
+
};
|
|
454
|
+
},
|
|
455
|
+
);
|
|
456
|
+
|
|
354
457
|
// ============================================================================
|
|
355
458
|
// MENU & EXTENSION TOOLS
|
|
356
459
|
// ============================================================================
|
|
@@ -69,7 +69,7 @@ export function buildMcpServerInstructions(apiBaseUrl) {
|
|
|
69
69
|
'- **Not all system tables have a REST route.** `query_table`, `find_one_record`, `create_record`, etc. all go through the dynamic REST API and will return **404** if the table has no registered route.',
|
|
70
70
|
'- **`column_definition` has NO route** — do NOT call `query_table("column_definition", …)`. It will always 404.',
|
|
71
71
|
'- To check which tables are accessible via MCP tools, call `get_all_routes` and look for the route whose `mainTable.id` matches the table you need, or `get_all_metadata` to see all table names.',
|
|
72
|
-
'- **Tables confirmed to have REST routes (system):** `table_definition`, `route_definition`, `user_definition`, `setting_definition`, `ai_config_definition`, `role_definition`, `menu_definition`, `extension_definition`, `folder_definition`, `file_definition`, `file_permission_definition`, `package_definition`, `bootstrap_script_definition`, `storage_config_definition`, `ai_conversation_definition`, `ai_message_definition`, `websocket_definition`, `websocket_event_definition`, `oauth_config_definition`, `oauth_account_definition`, `method_definition`, `pre_hook_definition`, `post_hook_definition`, `route_handler_definition`, `route_permission_definition`.',
|
|
72
|
+
'- **Tables confirmed to have REST routes (system):** `table_definition`, `route_definition`, `user_definition`, `setting_definition`, `ai_config_definition`, `role_definition`, `menu_definition`, `extension_definition`, `folder_definition`, `file_definition`, `file_permission_definition`, `package_definition`, `bootstrap_script_definition`, `storage_config_definition`, `ai_conversation_definition`, `ai_message_definition`, `websocket_definition`, `websocket_event_definition`, `oauth_config_definition`, `oauth_account_definition`, `method_definition`, `pre_hook_definition`, `post_hook_definition`, `route_handler_definition`, `route_permission_definition`, `flow_definition`, `flow_step_definition`, `flow_execution_definition`.',
|
|
73
73
|
'- **Tables without REST routes (internal/system only):** `column_definition`, `relation_definition` — these are managed indirectly via cascade on `table_definition` (PATCH /table_definition/{id} with columns/relations array). The `create_column` MCP tool handles this automatically.',
|
|
74
74
|
'',
|
|
75
75
|
'### Schema / table migration (sequential only)',
|
|
@@ -100,6 +100,17 @@ export function buildMcpServerInstructions(apiBaseUrl) {
|
|
|
100
100
|
'- **Client**: `io("ORIGIN/namespace", {auth: {token: JWT}})` — e.g. `io("http://localhost:3000/chat", {auth: {token: "…"}})`. WebSocket origin usually matches HTTP host (drop `/api` for WS path). `path` in gateway = namespace.',
|
|
101
101
|
'- **Workflow**: Create gateway → `create_record` on `websocket_definition`. Create event → `create_record` on `websocket_event_definition` with `gateway: {id}`. Changes auto-reload; test handlers before saving.',
|
|
102
102
|
'',
|
|
103
|
+
'### Flows (Automated Workflows)',
|
|
104
|
+
'- Enfyra supports automated workflows via **`flow_definition`**, **`flow_step_definition`**, and **`flow_execution_definition`** tables.',
|
|
105
|
+
'- **Flow** (`flow_definition`): `name`, `triggerType` (`schedule`, `event`, `webhook`, `manual`), `triggerConfig` (JSON), `timeout`, `isEnabled`.',
|
|
106
|
+
'- **Step** (`flow_step_definition`): `flow` → flow id, `key` (unique identifier for data chain), `stepOrder`, `type` (`script`, `condition`, `query`, `create`, `update`, `delete`, `http`, `trigger_flow`, `sleep`, `log`), `config` (JSON), `timeout`, `onError` (`stop`, `skip`, `retry`), `retryAttempts`.',
|
|
107
|
+
'- **Execution history** (`flow_execution_definition`): `flow` → flow id, `status`, `triggerPayload`, `context` (full data chain), `completedSteps`, `error`, `startedAt`, `completedAt`, `duration`.',
|
|
108
|
+
'- **triggerConfig examples**: schedule: `{"cron":"0 2 * * *","timezone":"UTC"}`, event: `{"table":"order_definition","action":"create"}`, webhook: `{"path":"/hooks/payment"}`, manual: `{}`.',
|
|
109
|
+
'- **Step config examples**: script: `{"code":"return $ctx.$repos.user_definition.find({limit:10})"}`, condition: `{"code":"return $ctx.$flow.$last?.data?.length > 0"}`, query: `{"table":"user_definition","filter":{"status":{"_eq":"active"}},"limit":10}`, http: `{"url":"https://api.example.com","method":"POST","body":{}}`, sleep: `{"ms":5000}`, trigger_flow: `{"flowId":2}`.',
|
|
110
|
+
'- **Data chain**: Steps access previous results via `$ctx.$flow.<stepKey>` and `$ctx.$flow.$last`. Trigger payload via `$ctx.$flow.$trigger`.',
|
|
111
|
+
'- **Workflow**: Create flow → `create_record` on `flow_definition`. Add steps → `create_record` on `flow_step_definition` with `flow: {id}`. Trigger manually or via schedule/event/webhook.',
|
|
112
|
+
'- **In handlers/hooks**: Trigger flows via `$ctx.$flows.trigger("flow-name", {payload})` or `$ctx.$flows.trigger(flowId, {payload})`.',
|
|
113
|
+
'',
|
|
103
114
|
'### Extension (Vue SFC only — NOT React)',
|
|
104
115
|
'- **CRITICAL:** MUST call `create_record` or `update_record` on `extension_definition` — outputting Vue code in chat does NOT save it. User will NOT see it.',
|
|
105
116
|
'- **Code format:** Vue SFC only. Structure: `<template>...</template>` + `<script setup>...</script>`. Server auto-compiles; if compile fails, fix and retry.',
|
|
@@ -156,9 +167,13 @@ export function buildMcpServerInstructions(apiBaseUrl) {
|
|
|
156
167
|
'- **type "page":** Full-page extension. Requires `menu: { id }` — create menu first (`create_menu` or `create_record` on `menu_definition`), find by path/label, then create extension with `menu: { id: menuId }`. `menu_definition` uses **label** not name — filter by `label` or `path`.',
|
|
157
168
|
'- **type "widget":** Widget extension. No menu required. Embed via `<Widget :id="extensionId" />` in other extensions or pages.',
|
|
158
169
|
'',
|
|
159
|
-
'#### NPM packages:',
|
|
160
|
-
'-
|
|
161
|
-
'-
|
|
170
|
+
'#### NPM packages (install via MCP):',
|
|
171
|
+
'- **Use `install_package` tool** — just pass the package name and type. The tool auto-fetches version from NPM, checks if already installed, and creates the record.',
|
|
172
|
+
'- Example: `install_package({ name: "node-ssh", type: "Server" })` — that is all. Tool handles everything.',
|
|
173
|
+
'- **Search first with `search_npm`** if unsure of exact package name.',
|
|
174
|
+
'- **Server** packages → available as `$ctx.$pkgs.packageName` in handlers/hooks.',
|
|
175
|
+
'- **App** packages → available via `getPackages([\'dayjs\'])` in extensions (call in `onMounted`).',
|
|
176
|
+
'- **Do NOT use `create_record` on `package_definition` directly** — use `install_package` instead.',
|
|
162
177
|
'',
|
|
163
178
|
'#### Important patterns:',
|
|
164
179
|
'- **useApi:** Must call `execute()` — does NOT auto-run. Supports batch operations with `ids` or `files` options.',
|
|
@@ -179,6 +194,7 @@ export function buildMcpServerInstructions(apiBaseUrl) {
|
|
|
179
194
|
`- \`update_record\` → PATCH \`${base}/<tableName>/<id>\``,
|
|
180
195
|
`- \`delete_record\` → DELETE \`${base}/<tableName>/<id>\``,
|
|
181
196
|
`- \`create_extension\` → POST \`${base}/extension_definition\` (Vue SFC only; for page pass menuId). \`update_record\` on extension_definition to change code.`,
|
|
197
|
+
`- Flow tables: \`${base}/flow_definition\`, \`${base}/flow_step_definition\`, \`${base}/flow_execution_definition\` — use standard CRUD tools.`,
|
|
182
198
|
`- Other: \`${base}/menu_definition\`, \`${base}/websocket_definition\`, \`${base}/admin/reload\`, etc.`,
|
|
183
199
|
'',
|
|
184
200
|
'When asked which endpoint the API calls, respond with **HTTP method + full URL** using this base. Call `get_enfyra_api_context` to confirm the resolved base if needed.',
|