@enfyra/mcp-server 0.0.9 → 0.0.10

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": "@enfyra/mcp-server",
3
- "version": "0.0.9",
3
+ "version": "0.0.10",
4
4
  "description": "MCP server for Enfyra - manage your Enfyra instance via Claude Code",
5
5
  "type": "module",
6
6
  "license": "MIT",
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
  // ============================================================================
@@ -156,9 +156,13 @@ export function buildMcpServerInstructions(apiBaseUrl) {
156
156
  '- **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
157
  '- **type "widget":** Widget extension. No menu required. Embed via `<Widget :id="extensionId" />` in other extensions or pages.',
158
158
  '',
159
- '#### NPM packages:',
160
- '- Before using (e.g. dayjs, chart.js) check `package_definition` (filter `type: App`, `name`, `isEnabled`). If not found, tell user to install via Settings Packages.',
161
- '- Use `getPackages([\'dayjs\'])` in code; call in `onMounted` or async handler.',
159
+ '#### NPM packages (install via MCP):',
160
+ '- **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.',
161
+ '- Example: `install_package({ name: "node-ssh", type: "Server" })` that is all. Tool handles everything.',
162
+ '- **Search first with `search_npm`** if unsure of exact package name.',
163
+ '- **Server** packages → available as `$ctx.$pkgs.packageName` in handlers/hooks.',
164
+ '- **App** packages → available via `getPackages([\'dayjs\'])` in extensions (call in `onMounted`).',
165
+ '- **Do NOT use `create_record` on `package_definition` directly** — use `install_package` instead.',
162
166
  '',
163
167
  '#### Important patterns:',
164
168
  '- **useApi:** Must call `execute()` — does NOT auto-run. Supports batch operations with `ids` or `files` options.',