integram-mcp 0.7.169 → 0.7.173

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.
Files changed (3) hide show
  1. package/README.md +4 -4
  2. package/index.js +75 -11
  3. package/package.json +1 -1
package/README.md CHANGED
@@ -15,7 +15,7 @@ claude mcp add integram \
15
15
  -e INTEGRAM_URL=https://ai2o.online \
16
16
  -e INTEGRAM_EMAIL=you@example.com \
17
17
  -e INTEGRAM_PASSWORD=secret \
18
- -- npx -y integram-mcp@0.7.169
18
+ -- npx -y integram-mcp@0.7.173
19
19
  ```
20
20
 
21
21
  Ставить ничего не нужно: `npx` скачает пакет сам.
@@ -49,7 +49,7 @@ claude mcp add integram \
49
49
  -e INTEGRAM_URL=http://localhost:8081 \
50
50
  -e INTEGRAM_EMAIL=you@example.com \
51
51
  -e INTEGRAM_PASSWORD=secret \
52
- -- npx -y integram-mcp@0.7.169
52
+ -- npx -y integram-mcp@0.7.173
53
53
  ```
54
54
 
55
55
  Удалить: `claude mcp remove integram`
@@ -63,7 +63,7 @@ claude mcp add integram \
63
63
  "mcpServers": {
64
64
  "integram": {
65
65
  "command": "npx",
66
- "args": ["-y", "integram-mcp@0.7.169"],
66
+ "args": ["-y", "integram-mcp@0.7.173"],
67
67
  "env": {
68
68
  "INTEGRAM_URL": "https://ai2o.online",
69
69
  "INTEGRAM_EMAIL": "you@example.com",
@@ -83,7 +83,7 @@ claude mcp add integram \
83
83
  "mcpServers": {
84
84
  "integram": {
85
85
  "command": "npx",
86
- "args": ["-y", "integram-mcp@0.7.169"],
86
+ "args": ["-y", "integram-mcp@0.7.173"],
87
87
  "env": {
88
88
  "INTEGRAM_URL": "https://ai2o.online",
89
89
  "INTEGRAM_EMAIL": "you@example.com",
package/index.js CHANGED
@@ -419,7 +419,8 @@ async function loadWorkspaceTools(slug) {
419
419
  }
420
420
 
421
421
  // Built-in MCP tools handled locally — never load from backend to avoid duplicates
422
- const BUILT_IN_NAMES = new Set([
422
+ // PM-948: экспорт — built-ins участвуют в каталоге did-you-mean подсказок.
423
+ export const BUILT_IN_NAMES = new Set([
423
424
  'list_workspaces', 'switch_workspace', 'create_workspace',
424
425
  'delete_workspace', 'clone_workspace', 'search_tools', 'confirm_action',
425
426
  ]);
@@ -811,7 +812,7 @@ export const EN_DESCRIPTIONS = {
811
812
  create_portal_ticket: 'Open a support ticket on behalf of a portal customer (admin): a ticket in the support module linked to the customer with an initial status. Returns: { id, subject }.',
812
813
  create_portal_order: 'Place a portal order on behalf of a customer (admin): creates a REAL order with money — an order record with items at server catalog prices. WITHOUT idempotencyKey a repeated call creates a DUPLICATE order — pass the key on retries. Requires confirmation.',
813
814
  // Portal
814
- invoke_server_function: 'Execute a codespace server function (api/<name>.js in the workspace git repo). Arbitrary code in a sandbox — requires confirmation. Optional idempotencyMinutes suppresses retries with identical args within an N-minute window — enable for functions with external side effects.',
815
+ invoke_server_function: 'Execute a codespace server function (api/<name>.js in the workspace git repo). Arbitrary code in a sandbox — requires confirmation. Optional idempotencyMinutes suppresses retries with identical args within an N-minute window — enable for functions with external side effects. A function may declare its capabilities in a header comment "// capabilities: query, write" — BEFORE invoking, read the header via search_code/read_file: a writing function creates records, PM tasks and sends notifications. The tool response always carries capabilities and writes (true for writing functions) with a warning in note. dryRun: true — safe diagnostics: write-bridges are replaced with stubs and the response carries a dryRun.intercepted journal of what would have been called; no confirmation required; side effects OUTSIDE bridges (external fetch, ai calls) are NOT suppressed.',
815
816
  list_portal_config_history: 'List portal config snapshot history (admin): recent saves with dates and authors. Call BEFORE restore_portal_config.',
816
817
  restore_portal_config: 'Roll the portal config back to a history snapshot (admin). Overwrites the ENTIRE current config — call list_portal_config_history first and tell the user what will be lost. The portal cache is invalidated automatically. Requires confirmation.',
817
818
  get_portal_analytics: 'Portal visit and order stats (admin): page/product views and orders created over 1d|7d|30d (default 7d).',
@@ -1615,8 +1616,10 @@ async function dispatchTool(request) {
1615
1616
  // Regular tool call → proxy to backend
1616
1617
  if (!activeTools.has(name)) {
1617
1618
  // PM-164: называем похожие инструменты, чтобы модель не подменяла имя.
1618
- const catalog = (allTools || []).map((t) => ({ name: t.name, group: t.group, description: t.description }));
1619
- const text = buildNotActiveText(name, catalog, [...activeTools]);
1619
+ // PM-948: built-ins тоже в каталоге; для ветки unknown они считаются
1620
+ // активными (всегда перехватываются раньше и до сюда не доходят точными именами).
1621
+ const catalog = buildSuggestionCatalog(allTools);
1622
+ const text = buildNotActiveText(name, catalog, [...activeTools, ...BUILT_IN_NAMES]);
1620
1623
  return { content: [{ type: 'text', text }], isError: true };
1621
1624
  }
1622
1625
 
@@ -2235,12 +2238,44 @@ export function buildSearchToolsText(p) {
2235
2238
 
2236
2239
  // ─── PM-164: similar-name guard ──────────────────────────────────────────────
2237
2240
 
2241
+ // PM-948: каталог для did-you-mean — built-ins прокси + backend-тулы.
2242
+ // Опечатка «create_workspce» должна подсказывать create_workspace, а не пустоту.
2243
+ export function buildSuggestionCatalog(allTools) {
2244
+ return [
2245
+ ...[...BUILT_IN_NAMES].map((n) => ({ name: n, group: 'builtin', description: '' })),
2246
+ ...(allTools || []).map((t) => ({ name: t.name, group: t.group, description: t.description })),
2247
+ ];
2248
+ }
2249
+
2238
2250
  /**
2239
- * Детерминированный поиск похожих имён: общие токены (по '_') или подстрока.
2240
- * Сам запрошенный тул не предлагается. Сортировка: больше общих токенов — выше.
2251
+ * PM-948: нормированная похожесть Левенштейна, формула difflib
2252
+ * (m + n − dist) / (m + n). На подстановках чуть щедрее difflib
2253
+ * (замена стоит 1, а не 2) — порог 0.6 компенсирует консервативно.
2254
+ */
2255
+ function editSimilarity(a, b) {
2256
+ const m = a.length;
2257
+ const n = b.length;
2258
+ if (!m || !n) return 0;
2259
+ let prev = Array.from({ length: n + 1 }, (_, j) => j);
2260
+ for (let i = 1; i <= m; i++) {
2261
+ const cur = [i];
2262
+ for (let j = 1; j <= n; j++) {
2263
+ cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
2264
+ }
2265
+ prev = cur;
2266
+ }
2267
+ return (m + n - prev[n]) / (m + n);
2268
+ }
2269
+
2270
+ const EDIT_SIMILARITY_THRESHOLD = 0.6;
2271
+
2272
+ /**
2273
+ * Детерминированный поиск похожих имён: общие токены (по '_'), подстрока
2274
+ * или edit-похожесть ≥ 0.6 (PM-948). Сам запрошенный тул не предлагается.
2275
+ * Сортировка: токен-совпадения (score ≥ 100) выше чисто edit-совпадений.
2241
2276
  */
2242
2277
  export function findSimilarTools(name, catalog, limit = 3) {
2243
- const tokens = (n) => n.split('_').filter(Boolean);
2278
+ const tokens = (n) => String(n ?? '').split('_').filter(Boolean);
2244
2279
  const nameToks = new Set(tokens(name));
2245
2280
  const scored = [];
2246
2281
  for (const t of catalog) {
@@ -2250,8 +2285,10 @@ export function findSimilarTools(name, catalog, limit = 3) {
2250
2285
  if (nameToks.has(tok)) shared += 1;
2251
2286
  else if (t.name.includes(name) || name.includes(t.name)) shared += 1;
2252
2287
  }
2253
- if (shared === 0) continue;
2254
- scored.push({ tool: t, score: shared });
2288
+ const edit = editSimilarity(String(name ?? ''), String(t.name ?? ''));
2289
+ if (shared === 0 && edit < EDIT_SIMILARITY_THRESHOLD) continue;
2290
+ const score = shared > 0 ? shared * 100 + Math.round(edit * 10) : Math.round(edit * 10);
2291
+ scored.push({ tool: t, score });
2255
2292
  }
2256
2293
  scored.sort((a, b) => b.score - a.score || a.tool.name.localeCompare(b.tool.name));
2257
2294
  return scored.slice(0, limit).map((s) => s.tool);
@@ -2264,10 +2301,37 @@ export function findSimilarTools(name, catalog, limit = 3) {
2264
2301
  export function buildNotActiveText(name, catalog, activeNames) {
2265
2302
  // PM-103: имени нет в каталоге — это не «не активен», а «такого тула нет».
2266
2303
  // Общий текст «is not active» модель читает как «имя неверное, попробую соседнее».
2304
+ // PM-948: неизвестное имя не отменяет близости — добавляем did-you-mean,
2305
+ // чтобы эмиссия самоисправлялась вместо перебора соседних тулов.
2267
2306
  const known = catalog.some((t) => t.name === name);
2268
2307
  if (!known) {
2269
- return `Error: Unknown tool "${name}" — no such tool in the integram catalog. ` +
2270
- `Do NOT call a different tool instead. Check the name, or use search_tools to discover the right one.`;
2308
+ const base = `Error: Unknown tool "${name}" — no such tool in the integram catalog. ` +
2309
+ `Do NOT call a different tool instead.`;
2310
+ const similar = name ? findSimilarTools(String(name), catalog) : [];
2311
+ if (!similar.length) {
2312
+ return base + ` Check the name, or use search_tools to discover the right one.`;
2313
+ }
2314
+ const label = (t) => (t.group ? `"${t.name}" (group "${t.group}")` : `"${t.name}"`);
2315
+ const activeSet = new Set(activeNames);
2316
+ const lines = [base];
2317
+ const activeHits = similar.filter((t) => activeSet.has(t.name));
2318
+ const inactiveHits = similar.filter((t) => !activeSet.has(t.name));
2319
+ if (activeHits.length) {
2320
+ lines.push(
2321
+ `Did you mean: ${activeHits.map(label).join(', ')}? ` +
2322
+ `It IS ACTIVE — if that is what you meant, call it by its exact name. Do NOT guess other tools.`,
2323
+ );
2324
+ }
2325
+ if (inactiveHits.length) {
2326
+ const groups = [...new Set(inactiveHits.map((t) => t.group).filter(Boolean))];
2327
+ lines.push(
2328
+ `Did you mean: ${inactiveHits.map(label).join(', ')}? ` +
2329
+ `If one of these is what you meant, activate its group first: ` +
2330
+ groups.map((g) => `search_tools("${g}")`).join(' or ') +
2331
+ ` — then call the tool by its exact name.`,
2332
+ );
2333
+ }
2334
+ return lines.join('\n');
2271
2335
  }
2272
2336
  const similar = findSimilarTools(name, catalog);
2273
2337
  if (!similar.length) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "integram-mcp",
3
- "version": "0.7.169",
3
+ "version": "0.7.173",
4
4
  "type": "module",
5
5
  "description": "MCP server for Integram — connect AI assistants to your workspace via Model Context Protocol",
6
6
  "mcpName": "io.github.judas-priest/integram",