@0xmaxma/claude-gateway 2.1.8 → 2.1.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.
Files changed (193) hide show
  1. package/dist/agent/runner.d.ts +25 -4
  2. package/dist/agent/runner.d.ts.map +1 -1
  3. package/dist/agent/runner.js +4 -0
  4. package/dist/agent/runner.js.map +1 -1
  5. package/dist/api/connectors-router.d.ts.map +1 -1
  6. package/dist/api/connectors-router.js +27 -3
  7. package/dist/api/connectors-router.js.map +1 -1
  8. package/dist/api/router.d.ts.map +1 -1
  9. package/dist/api/router.js +14 -0
  10. package/dist/api/router.js.map +1 -1
  11. package/dist/automation/browser-outcome.d.ts +3 -1
  12. package/dist/automation/browser-outcome.d.ts.map +1 -1
  13. package/dist/automation/browser-outcome.js +2 -2
  14. package/dist/automation/browser-outcome.js.map +1 -1
  15. package/dist/automation/browser-trace.d.ts +1 -1
  16. package/dist/automation/command-speech.d.ts +9 -1
  17. package/dist/automation/command-speech.d.ts.map +1 -1
  18. package/dist/automation/command-speech.js +18 -0
  19. package/dist/automation/command-speech.js.map +1 -1
  20. package/dist/automation/command-steps.d.ts +2 -0
  21. package/dist/automation/command-steps.d.ts.map +1 -1
  22. package/dist/automation/command-steps.js +34 -2
  23. package/dist/automation/command-steps.js.map +1 -1
  24. package/dist/automation/computer-command.d.ts +1 -0
  25. package/dist/automation/computer-command.d.ts.map +1 -1
  26. package/dist/automation/computer-command.js +31 -5
  27. package/dist/automation/computer-command.js.map +1 -1
  28. package/dist/automation/computer-outcome.d.ts +26 -3
  29. package/dist/automation/computer-outcome.d.ts.map +1 -1
  30. package/dist/automation/computer-outcome.js +183 -13
  31. package/dist/automation/computer-outcome.js.map +1 -1
  32. package/dist/automation/computer-policy.d.ts +10 -1
  33. package/dist/automation/computer-policy.d.ts.map +1 -1
  34. package/dist/automation/computer-policy.js +20 -6
  35. package/dist/automation/computer-policy.js.map +1 -1
  36. package/dist/automation/computer-use.d.ts +34 -0
  37. package/dist/automation/computer-use.d.ts.map +1 -1
  38. package/dist/automation/computer-use.js +211 -17
  39. package/dist/automation/computer-use.js.map +1 -1
  40. package/dist/automation/direct-command.d.ts +8 -0
  41. package/dist/automation/direct-command.d.ts.map +1 -1
  42. package/dist/automation/direct-command.js +12 -0
  43. package/dist/automation/direct-command.js.map +1 -1
  44. package/dist/automation/model-choice-evaluator.d.ts +3 -0
  45. package/dist/automation/model-choice-evaluator.d.ts.map +1 -1
  46. package/dist/automation/model-choice-evaluator.js +3 -1
  47. package/dist/automation/model-choice-evaluator.js.map +1 -1
  48. package/dist/automation/vision-decider.d.ts +4 -2
  49. package/dist/automation/vision-decider.d.ts.map +1 -1
  50. package/dist/automation/vision-decider.js +69 -15
  51. package/dist/automation/vision-decider.js.map +1 -1
  52. package/dist/build-provenance.json +4 -4
  53. package/dist/connectors/custom-connectors-store.d.ts.map +1 -1
  54. package/dist/connectors/custom-connectors-store.js +6 -1
  55. package/dist/connectors/custom-connectors-store.js.map +1 -1
  56. package/dist/connectors/custom.d.ts +14 -0
  57. package/dist/connectors/custom.d.ts.map +1 -1
  58. package/dist/connectors/custom.js +43 -2
  59. package/dist/connectors/custom.js.map +1 -1
  60. package/dist/connectors/proxy.d.ts +8 -0
  61. package/dist/connectors/proxy.d.ts.map +1 -1
  62. package/dist/connectors/proxy.js +53 -5
  63. package/dist/connectors/proxy.js.map +1 -1
  64. package/dist/connectors/resolve.d.ts.map +1 -1
  65. package/dist/connectors/resolve.js +16 -2
  66. package/dist/connectors/resolve.js.map +1 -1
  67. package/dist/connectors/sidecar.d.ts +131 -0
  68. package/dist/connectors/sidecar.d.ts.map +1 -0
  69. package/dist/connectors/sidecar.js +768 -0
  70. package/dist/connectors/sidecar.js.map +1 -0
  71. package/dist/connectors/token-env.d.ts +2 -0
  72. package/dist/connectors/token-env.d.ts.map +1 -1
  73. package/dist/connectors/token-env.js +16 -0
  74. package/dist/connectors/token-env.js.map +1 -1
  75. package/dist/connectors/types.d.ts +4 -0
  76. package/dist/connectors/types.d.ts.map +1 -1
  77. package/dist/connectors/uv-runtime.d.ts +37 -0
  78. package/dist/connectors/uv-runtime.d.ts.map +1 -0
  79. package/dist/connectors/uv-runtime.js +236 -0
  80. package/dist/connectors/uv-runtime.js.map +1 -0
  81. package/dist/index.js +10 -1
  82. package/dist/index.js.map +1 -1
  83. package/dist/jev/browser-contract.d.ts +3 -0
  84. package/dist/jev/browser-contract.d.ts.map +1 -1
  85. package/dist/jev/browser-contract.js +6 -0
  86. package/dist/jev/browser-contract.js.map +1 -1
  87. package/dist/jev/browser-evidence-summary.d.ts +1 -1
  88. package/dist/orchestration/agent-tool-schemas.d.ts +18 -0
  89. package/dist/orchestration/agent-tool-schemas.d.ts.map +1 -1
  90. package/dist/orchestration/agent-tool-schemas.js +11 -3
  91. package/dist/orchestration/agent-tool-schemas.js.map +1 -1
  92. package/dist/orchestration/bridge.d.ts.map +1 -1
  93. package/dist/orchestration/bridge.js +25 -5
  94. package/dist/orchestration/bridge.js.map +1 -1
  95. package/dist/orchestration/browser-routing.d.ts.map +1 -1
  96. package/dist/orchestration/browser-routing.js +2 -1
  97. package/dist/orchestration/browser-routing.js.map +1 -1
  98. package/dist/orchestration/computer-decisions.d.ts +1 -1
  99. package/dist/orchestration/computer-decisions.d.ts.map +1 -1
  100. package/dist/orchestration/computer-decisions.js +21 -7
  101. package/dist/orchestration/computer-decisions.js.map +1 -1
  102. package/dist/orchestration/computer-live.d.ts +62 -0
  103. package/dist/orchestration/computer-live.d.ts.map +1 -0
  104. package/dist/orchestration/computer-live.js +126 -0
  105. package/dist/orchestration/computer-live.js.map +1 -0
  106. package/dist/orchestration/connector-context.d.ts +17 -0
  107. package/dist/orchestration/connector-context.d.ts.map +1 -0
  108. package/dist/orchestration/connector-context.js +56 -0
  109. package/dist/orchestration/connector-context.js.map +1 -0
  110. package/dist/orchestration/container-tool-schemas.d.ts.map +1 -1
  111. package/dist/orchestration/container-tool-schemas.js +3 -0
  112. package/dist/orchestration/container-tool-schemas.js.map +1 -1
  113. package/dist/orchestration/decisions.d.ts +3 -1
  114. package/dist/orchestration/decisions.d.ts.map +1 -1
  115. package/dist/orchestration/decisions.js +4 -2
  116. package/dist/orchestration/decisions.js.map +1 -1
  117. package/dist/orchestration/gateway-tasks/browser.d.ts +1 -1
  118. package/dist/orchestration/gateway-tasks/browser.d.ts.map +1 -1
  119. package/dist/orchestration/gateway-tasks/browser.js +4 -3
  120. package/dist/orchestration/gateway-tasks/browser.js.map +1 -1
  121. package/dist/orchestration/gateway-tasks/computer-context.d.ts +4 -1
  122. package/dist/orchestration/gateway-tasks/computer-context.d.ts.map +1 -1
  123. package/dist/orchestration/gateway-tasks/computer-context.js +3 -1
  124. package/dist/orchestration/gateway-tasks/computer-context.js.map +1 -1
  125. package/dist/orchestration/gateway-tasks/computer.d.ts +78 -15
  126. package/dist/orchestration/gateway-tasks/computer.d.ts.map +1 -1
  127. package/dist/orchestration/gateway-tasks/computer.js +298 -31
  128. package/dist/orchestration/gateway-tasks/computer.js.map +1 -1
  129. package/dist/orchestration/gateway-tasks/controller.d.ts +14 -2
  130. package/dist/orchestration/gateway-tasks/controller.d.ts.map +1 -1
  131. package/dist/orchestration/gateway-tasks/controller.js +63 -2
  132. package/dist/orchestration/gateway-tasks/controller.js.map +1 -1
  133. package/dist/orchestration/notification-mailbox.js +3 -3
  134. package/dist/orchestration/notification-mailbox.js.map +1 -1
  135. package/dist/orchestration/process-turn.d.ts.map +1 -1
  136. package/dist/orchestration/process-turn.js +4 -1
  137. package/dist/orchestration/process-turn.js.map +1 -1
  138. package/dist/orchestration/runtime.d.ts +22 -1
  139. package/dist/orchestration/runtime.d.ts.map +1 -1
  140. package/dist/orchestration/runtime.js +87 -7
  141. package/dist/orchestration/runtime.js.map +1 -1
  142. package/dist/orchestration/task-controls.d.ts +8 -0
  143. package/dist/orchestration/task-controls.d.ts.map +1 -1
  144. package/dist/orchestration/task-controls.js +3 -2
  145. package/dist/orchestration/task-controls.js.map +1 -1
  146. package/dist/orchestration/tasks/automation-session.d.ts +42 -11
  147. package/dist/orchestration/tasks/automation-session.d.ts.map +1 -1
  148. package/dist/orchestration/tasks/automation-session.js +101 -21
  149. package/dist/orchestration/tasks/automation-session.js.map +1 -1
  150. package/dist/orchestration/tasks/driver.d.ts.map +1 -1
  151. package/dist/orchestration/tasks/driver.js +4 -0
  152. package/dist/orchestration/tasks/driver.js.map +1 -1
  153. package/dist/orchestration/tasks/service.d.ts +23 -0
  154. package/dist/orchestration/tasks/service.d.ts.map +1 -1
  155. package/dist/orchestration/tasks/service.js +120 -12
  156. package/dist/orchestration/tasks/service.js.map +1 -1
  157. package/dist/orchestration/telegram-tool-status.d.ts.map +1 -1
  158. package/dist/orchestration/telegram-tool-status.js +2 -0
  159. package/dist/orchestration/telegram-tool-status.js.map +1 -1
  160. package/dist/orchestration/types.d.ts +19 -0
  161. package/dist/orchestration/types.d.ts.map +1 -1
  162. package/dist/orchestration/types.js.map +1 -1
  163. package/dist/session/managed-connectors.d.ts +2 -0
  164. package/dist/session/managed-connectors.d.ts.map +1 -1
  165. package/dist/session/managed-connectors.js +9 -4
  166. package/dist/session/managed-connectors.js.map +1 -1
  167. package/dist/session/process.d.ts +3 -0
  168. package/dist/session/process.d.ts.map +1 -1
  169. package/dist/session/process.js +21 -3
  170. package/dist/session/process.js.map +1 -1
  171. package/dist/session/runtime-profile.d.ts +2 -0
  172. package/dist/session/runtime-profile.d.ts.map +1 -1
  173. package/dist/session/runtime-profile.js.map +1 -1
  174. package/dist/ui/voice-call-client.d.ts +3 -0
  175. package/dist/ui/voice-call-client.d.ts.map +1 -1
  176. package/dist/ui/voice-call-client.js +10 -1
  177. package/dist/ui/voice-call-client.js.map +1 -1
  178. package/dist/voice/errors.d.ts +1 -1
  179. package/dist/voice/errors.js +1 -1
  180. package/dist/voice/errors.js.map +1 -1
  181. package/dist/voice/providers/elevenlabs-tts.d.ts.map +1 -1
  182. package/dist/voice/providers/elevenlabs-tts.js +17 -1
  183. package/dist/voice/providers/elevenlabs-tts.js.map +1 -1
  184. package/dist/voice/providers/socket.js +25 -6
  185. package/dist/voice/providers/socket.js.map +1 -1
  186. package/dist/voice/session.js +3 -2
  187. package/dist/voice/session.js.map +1 -1
  188. package/mcp/fixtures/workspace-mcp-tools.json +260 -0
  189. package/mcp/lazy-tools.test.ts +137 -1
  190. package/mcp/lazy-tools.ts +40 -7
  191. package/mcp/server.ts +1 -1
  192. package/mcp/tools/tasks/module.ts +2 -1
  193. package/package.json +1 -1
@@ -3,7 +3,7 @@ import { createLazyToolCatalog } from './lazy-tools';
3
3
  import type { McpToolDefinition } from './types';
4
4
  import { Client } from '@modelcontextprotocol/sdk/client/index.js';
5
5
  import { StdioClientTransport } from '@modelcontextprotocol/sdk/client/stdio.js';
6
- import { mkdtempSync, writeFileSync, rmSync } from 'node:fs';
6
+ import { mkdtempSync, readFileSync, writeFileSync, rmSync } from 'node:fs';
7
7
  import { tmpdir } from 'node:os';
8
8
  import { join } from 'node:path';
9
9
 
@@ -22,13 +22,149 @@ describe('lazy gateway tools', () => {
22
22
  expect(parse(catalog.search({ query: 'ORIGINAL description 22' })).tools).toEqual([defs[22]]);
23
23
  expect(catalog.search({ limit: 21 }).isError).toBe(true);
24
24
  });
25
+ test('an empty or * query lists tools in name order, even names with an empty _ token', () => {
26
+ const catalog = createLazyToolCatalog(['zeta__x', 'omega_', 'beta', 'alpha'].map(name => ({ name, description: name, inputSchema: { type: 'object' } })));
27
+ const listed = (query: string) => parse(catalog.search({ query })).tools.map((tool: McpToolDefinition) => tool.name);
28
+ expect({ star: listed('*'), empty: listed('') }).toEqual({ star: ['alpha', 'beta', 'omega_', 'zeta__x'], empty: ['alpha', 'beta', 'omega_', 'zeta__x'] });
29
+ });
30
+ // Queries workers sent to tool_search against real workspace-mcp catalogs; each of these
31
+ // returned nothing under the every-word rule, costing the worker a whole model turn.
32
+ test('ranks tools by matching words when no tool matches every word, and treats * as an empty query', () => {
33
+ const catalogs = JSON.parse(readFileSync(join(import.meta.dir, 'fixtures/workspace-mcp-tools.json'), 'utf8')) as Record<string, McpToolDefinition[]>;
34
+ const search = (server: string, query: string) => parse(createLazyToolCatalog(catalogs[server]).search({ query }));
35
+ const top = (server: string, query: string) => search(server, query).tools.map((tool: McpToolDefinition) => tool.name);
36
+ expect({
37
+ 'list events': top('google-calendar', 'list events')[0],
38
+ 'list events calendar': top('google-calendar', 'list events calendar')[0],
39
+ 'search messages list': top('gmail', 'search messages list')[0],
40
+ // The description says "updating", so manage_event ties get_events on "event" and sorts second.
41
+ 'update event': top('google-calendar', 'update event').slice(0, 2),
42
+ }).toEqual({
43
+ 'list events': 'get_events',
44
+ 'list events calendar': 'get_events',
45
+ 'search messages list': 'search_gmail_messages',
46
+ 'update event': ['get_events', 'manage_event'],
47
+ });
48
+ for (const server of ['gmail', 'google-calendar']) {
49
+ const all = search(server, '*');
50
+ expect({ total: all.total, schemas: all.tools.some((tool: McpToolDefinition) => 'inputSchema' in tool) }).toEqual({ total: catalogs[server].length, schemas: false });
51
+ }
52
+ expect(top('gmail', 'search gmail messages')).toEqual(['search_gmail_messages']);
53
+ expect(search('gmail', 'zzz qqq').total).toBe(0);
54
+ });
55
+ describe('Drive, Docs and Sheets catalogs', () => {
56
+ const catalogs = JSON.parse(readFileSync(join(import.meta.dir, 'fixtures/workspace-mcp-tools.json'), 'utf8')) as Record<string, McpToolDefinition[]>;
57
+ const top = (server: string, query: string) => parse(createLazyToolCatalog(catalogs[server]).search({ query })).tools.map((tool: McpToolDefinition) => tool.name);
58
+ const disabled: Record<string, string[]> = {
59
+ gmail: ['modify_gmail_message_labels', 'batch_modify_gmail_message_labels', 'manage_gmail_label', 'list_gmail_filters', 'manage_gmail_filter'],
60
+ 'google-calendar': ['create_calendar'],
61
+ 'google-drive': ['manage_drive_access', 'set_drive_file_permissions'],
62
+ 'google-docs': ['manage_document_comment'],
63
+ 'google-sheets': ['manage_spreadsheet_comment'],
64
+ };
65
+ test('rank the tool a worker means first', () => {
66
+ expect({
67
+ 'find and replace in doc': top('google-docs', 'find and replace in doc')[0],
68
+ 'export doc to pdf': top('google-docs', 'export doc to pdf')[0],
69
+ 'append rows': top('google-sheets', 'append rows')[0],
70
+ 'search files': top('google-drive', 'search files')[0],
71
+ 'create folder': top('google-drive', 'create folder')[0],
72
+ 'copy file': top('google-drive', 'copy file')[0],
73
+ 'list my files': top('google-drive', 'list my files')[0],
74
+ // No Drive tool contains all three words.
75
+ 'show folder contents': top('google-drive', 'show folder contents')[0],
76
+ }).toEqual({
77
+ 'find and replace in doc': 'find_and_replace_doc',
78
+ 'export doc to pdf': 'export_doc_to_pdf',
79
+ 'append rows': 'append_table_rows',
80
+ 'search files': 'search_drive_files',
81
+ 'create folder': 'create_drive_folder',
82
+ 'copy file': 'copy_drive_file',
83
+ 'list my files': 'list_drive_items',
84
+ 'show folder contents': 'list_drive_items',
85
+ });
86
+ });
87
+ test('rank a name match above a description match when every query word matches', () => {
88
+ expect({
89
+ 'read sheet values': top('google-sheets', 'read sheet values')[0],
90
+ 'create spreadsheet': top('google-sheets', 'create spreadsheet')[0],
91
+ 'download file': top('google-drive', 'download file')[0],
92
+ }).toEqual({
93
+ 'read sheet values': 'read_sheet_values',
94
+ 'create spreadsheet': 'create_spreadsheet',
95
+ 'download file': 'get_drive_file_download_url',
96
+ });
97
+ });
98
+ // Known gap: modify_doc_text names "doc", not "document", so it ties batch_update_doc
99
+ // (whose name holds "update") and loses on name order. Only a doc/document prefix rule fixes it.
100
+ test.failing('known ranking gap: "update document text" should rank modify_doc_text first', () => {
101
+ expect(top('google-docs', 'update document text')[0]).toBe('modify_doc_text');
102
+ });
103
+ test('ranking only reorders: every query returns the same tools as the unranked filter', () => {
104
+ const unranked = (tools: McpToolDefinition[], rawQuery: string) => {
105
+ const query = rawQuery.trim().toLowerCase() === '*' ? '' : rawQuery.trim().toLowerCase();
106
+ const text = (tool: McpToolDefinition) => `${tool.name} ${tool.description}`.toLowerCase();
107
+ let matches = tools.filter(tool => query.split(/\s+/).every(word => text(tool).includes(word)));
108
+ if (!matches.length) {
109
+ const words = [...new Set(query.split(/[^a-z0-9]+/).filter(Boolean))];
110
+ matches = tools.filter(tool => words.some(word => text(tool).includes(word)));
111
+ }
112
+ return matches.map(tool => tool.name).sort();
113
+ };
114
+ const queries = ['*', '', 'list events', 'update event', 'list events calendar', 'search messages list', 'search gmail messages',
115
+ 'update document text', 'read sheet values', 'create spreadsheet', 'download file', 'find and replace in doc', 'export doc to pdf',
116
+ 'append rows', 'search files', 'create folder', 'copy file', 'list my files', 'show folder contents', 'doc', 'sheet', 'read',
117
+ 'send email', 'draft reply', 'attachment', 'free busy', 'out of office', 'comments', 'zzz qqq', 'get_doc_content', 'DRIVE file permissions'];
118
+ for (const [server, tools] of Object.entries(catalogs)) for (const query of queries) {
119
+ const catalog = createLazyToolCatalog(tools);
120
+ const first = parse(catalog.search({ query, limit: 20 }));
121
+ const names: string[] = [];
122
+ for (let offset = 0; offset < first.total; offset += 20) {
123
+ names.push(...parse(catalog.search({ query, offset, limit: 20 })).tools.map((tool: McpToolDefinition) => tool.name));
124
+ }
125
+ const listing = query === '' || query === '*';
126
+ expect({ server, query, total: first.total, names: listing ? names : [...names].sort() })
127
+ .toEqual({ server, query, total: unranked(tools, query).length, names: listing ? tools.map(tool => tool.name).sort((a, b) => a.localeCompare(b)) : unranked(tools, query) });
128
+ expect(new Set(names).size).toBe(names.length);
129
+ }
130
+ });
131
+ test('hide every disabled tool and list the full catalog for * without schemas', () => {
132
+ expect(Object.keys(catalogs).sort()).toEqual(Object.keys(disabled).sort());
133
+ for (const [server, names] of Object.entries(disabled)) {
134
+ expect(catalogs[server].map(tool => tool.name).filter(name => name === 'start_google_auth' || names.includes(name))).toEqual([]);
135
+ }
136
+ const listed = Object.fromEntries(Object.keys(disabled).map(server => {
137
+ const all = parse(createLazyToolCatalog(catalogs[server]).search({ query: '*', limit: 20 }));
138
+ return [server, { total: all.total, schemas: all.tools.some((tool: McpToolDefinition) => 'inputSchema' in tool) }];
139
+ }));
140
+ expect(listed).toEqual({
141
+ gmail: { total: 9, schemas: false }, 'google-calendar': { total: 6, schemas: false },
142
+ 'google-drive': { total: 14, schemas: false }, 'google-docs': { total: 18, schemas: false }, 'google-sheets': { total: 15, schemas: false },
143
+ });
144
+ });
145
+ });
25
146
  test('unauthorized, task and recursive tools never reach dispatcher', async () => {
26
147
  let calls = 0; const dispatch = async () => { calls++; return { content: [] }; };
27
148
  const catalog = createLazyToolCatalog(defs);
28
149
  for (const name of ['missing', 'task_spawn', 'tool_call', 'tool_search']) expect((await catalog.call({ name, arguments: {} }, dispatch)).isError).toBe(true);
29
150
  expect((await catalog.call({ name: 'tool_00', arguments: [] }, dispatch)).isError).toBe(true);
151
+ expect((await catalog.call({ name: 'tool_00', arguments: '{"target":' }, dispatch)).isError).toBe(true);
152
+ expect((await catalog.call({ tool_name: 'task_spawn', arguments: {} }, dispatch)).isError).toBe(true);
30
153
  expect(calls).toBe(0);
31
154
  });
155
+ test('tolerates tool_name and JSON-string arguments, and names a wrong call shape', async () => {
156
+ const seen: Array<[string, Record<string, unknown>]> = [];
157
+ const dispatch = async (name: string, input: Record<string, unknown>) => { seen.push([name, input]); return { content: [] }; };
158
+ const catalog = createLazyToolCatalog(defs);
159
+ expect((await catalog.call({ tool_name: 'tool_01', arguments: { target: 'a' } }, dispatch)).isError).toBeFalsy();
160
+ expect((await catalog.call({ tool_name: 'tool_02', arguments: '{"target":"b"}' }, dispatch)).isError).toBeFalsy();
161
+ expect(seen).toEqual([['tool_01', { target: 'a' }], ['tool_02', { target: 'b' }]]);
162
+ const missing = await catalog.call({ tool: 'tool_01', args: {} }, dispatch);
163
+ expect(missing.isError).toBe(true);
164
+ expect(missing.content[0].text).toContain('received keys: tool, args');
165
+ expect((await catalog.call({ name: 'nope', arguments: {} }, dispatch)).content[0].text).toContain('"nope"');
166
+ expect(seen).toHaveLength(2);
167
+ });
32
168
  test('excludeReserved filters an underlying tool literally named tool_search/tool_call; the connector opt-out does not', async () => {
33
169
  const collision: McpToolDefinition[] = [...defs,
34
170
  { name: 'tool_search', description: 'Underlying tool that collides with the reserved name', inputSchema: { type: 'object', properties: {}, additionalProperties: false } }];
package/mcp/lazy-tools.ts CHANGED
@@ -24,20 +24,53 @@ export function createLazyToolCatalog(tools: readonly McpToolDefinition[], exclu
24
24
  const offset = args.offset ?? 0; const limit = args.limit ?? 5;
25
25
  if (typeof offset !== 'number' || !Number.isSafeInteger(offset) || offset < 0 ||
26
26
  typeof limit !== 'number' || !Number.isInteger(limit) || limit < 1 || limit > 20) return fail('Invalid search pagination');
27
- const query = String(args.query ?? '').trim().toLowerCase();
27
+ const rawQuery = String(args.query ?? '').trim().toLowerCase();
28
+ const query = rawQuery === '*' ? '' : rawQuery;
28
29
  const name = String(args.name ?? '').trim().toLowerCase();
29
- const matches = catalog.filter(tool => name ? tool.name.toLowerCase() === name :
30
- query.split(/\s+/).every(word => `${tool.name} ${tool.description}`.toLowerCase().includes(word)));
30
+ const text = (tool: McpToolDefinition) => `${tool.name} ${tool.description}`.toLowerCase();
31
+ const words = query ? query.split(/\s+/) : [];
32
+ // Name hits outweigh description hits, and a whole name token outweighs a substring,
33
+ // so "read sheet values" puts read_sheet_values above move_sheet_rows ("spreadsheet").
34
+ const score = (tool: McpToolDefinition) => {
35
+ const toolName = tool.name.toLowerCase(), tokens = toolName.split('_');
36
+ return words.reduce((sum, word) => sum + (tokens.includes(word) ? 4 : toolName.includes(word) ? 2 : 1), 0);
37
+ };
38
+ let matches = name ? catalog.filter(tool => tool.name.toLowerCase() === name) :
39
+ catalog.filter(tool => words.every(word => text(tool).includes(word)))
40
+ .map(tool => ({ tool, score: score(tool) }))
41
+ .sort((a, b) => b.score - a.score || a.tool.name.localeCompare(b.tool.name))
42
+ .map(({ tool }) => tool);
43
+ // Natural multi-word queries ("update event") often have no tool containing every
44
+ // word, and an empty result costs the worker a turn: rank by how many words match.
45
+ // The name score stays out of this tier: it would put manage_event above get_events
46
+ // for "update event" but list_calendars above get_events for "list events calendar".
47
+ if (!name && !matches.length) {
48
+ const words = [...new Set(query.split(/[^a-z0-9]+/).filter(Boolean))];
49
+ matches = catalog.map(tool => ({ tool, hits: words.filter(word => text(tool).includes(word)).length }))
50
+ .filter(({ hits }) => hits > 0)
51
+ .sort((a, b) => b.hits - a.hits || a.tool.name.localeCompare(b.tool.name))
52
+ .map(({ tool }) => tool);
53
+ }
31
54
  const schemas = args.include_schema ?? Boolean(query || name);
32
55
  return result({ total: matches.length, offset, next_offset: offset + limit < matches.length ? offset + limit : null,
33
56
  tools: matches.slice(offset, offset + limit).map(tool => schemas ? tool : { name: tool.name, description: tool.description }) });
34
57
  },
35
58
  async call(args: Record<string, unknown>, dispatch: (name: string, input: Record<string, unknown>) => Promise<McpToolResult>): Promise<McpToolResult> {
36
59
  // A model knows these tools by their MCP names (`mcp__gateway__x`); the catalog holds the bare `x`.
37
- const name = typeof args.name === 'string' ? args.name.replace(/^mcp__gateway__/, '') : undefined;
38
- if (!name || !names.has(name)) return fail('Unknown or unauthorized gateway tool');
39
- if (!args.arguments || typeof args.arguments !== 'object' || Array.isArray(args.arguments)) return fail('Tool arguments must be an object');
40
- return dispatch(name, args.arguments as Record<string, unknown>);
60
+ // Models also reach for `tool_name` and JSON-encoded `arguments`; a bare rejection sent one
61
+ // retrying the same wrong shape until its turn ran out, so accept those and name what is wrong.
62
+ const rawName = typeof args.name === 'string' ? args.name : args.tool_name;
63
+ if (typeof rawName !== 'string' || !rawName.trim()) {
64
+ return fail(`tool_call needs "name" (the exact tool name from tool_search) and "arguments" (an object); received keys: ${Object.keys(args).join(', ') || 'none'}`);
65
+ }
66
+ const name = rawName.trim().replace(/^mcp__gateway__/, '');
67
+ if (!names.has(name)) return fail(`Unknown or unauthorized gateway tool "${name}"; call tool_search to list the available tools`);
68
+ let input = args.arguments;
69
+ if (typeof input === 'string') {
70
+ try { input = JSON.parse(input); } catch { return fail('Tool arguments must be an object (received a string that is not JSON)'); }
71
+ }
72
+ if (!input || typeof input !== 'object' || Array.isArray(input)) return fail('Tool arguments must be an object');
73
+ return dispatch(name, input as Record<string, unknown>);
41
74
  },
42
75
  };
43
76
  }
package/mcp/server.ts CHANGED
@@ -61,7 +61,7 @@ for (const mod of modules) {
61
61
  // mid-session and invalidated the whole cache — the same defect ee800a7 fixed for the response
62
62
  // schema. The turn's INTAKE_OVERLAY prompt text, below the cache breakpoint, is what asks for
63
63
  // the tool; the bridge refuses the call outright when the feature is not active.
64
- const taskTools = ORCHESTRATION_ROLE === 'agent' ? AGENT_TASK_TOOLS.filter(tool => (tool.name !== 'jev_evaluate' || process.env.GATEWAY_JEV_ENABLED === 'true')).filter(tool => tool.name !== 'capabilities_list' || process.env.GATEWAY_CAPABILITY_CATALOG === 'true') : ORCHESTRATION_ROLE === 'worker' ? WORKER_REPORT_TOOLS.filter(tool => (tool.name !== 'jev_evaluate' || process.env.GATEWAY_JEV_ENABLED === 'true')).filter(tool => tool.name !== 'task_memory_append' || process.env.GATEWAY_ORCHESTRATION_WRITE_MEMORY === 'true').concat(process.env.GATEWAY_SUBAGENTS === 'true' ? SUBAGENT_TOOLS : []) : [];
64
+ const taskTools = ORCHESTRATION_ROLE === 'agent' ? AGENT_TASK_TOOLS.filter(tool => (tool.name !== 'jev_evaluate' || process.env.GATEWAY_JEV_ENABLED === 'true')).filter(tool => tool.name !== 'capabilities_list' || process.env.GATEWAY_CAPABILITY_CATALOG === 'true').filter(tool => tool.name !== 'device_shell' || process.env.GATEWAY_COMPUTER_ENABLED === 'true') : ORCHESTRATION_ROLE === 'worker' ? WORKER_REPORT_TOOLS.filter(tool => (tool.name !== 'jev_evaluate' || process.env.GATEWAY_JEV_ENABLED === 'true')).filter(tool => tool.name !== 'task_memory_append' || process.env.GATEWAY_ORCHESTRATION_WRITE_MEMORY === 'true').concat(process.env.GATEWAY_SUBAGENTS === 'true' ? SUBAGENT_TOOLS : []) : [];
65
65
  if (ORCHESTRATION_ROLE && process.env.GATEWAY_ORCHESTRATION_TICKET_FILE) visibleTools.push(...taskTools);
66
66
  // A read-only subagent sees only tools that change nothing; the bridge refuses the rest.
67
67
  if (ORCHESTRATION_ROLE === 'worker' && process.env.GATEWAY_READONLY_TASK === 'true') {
@@ -17,7 +17,8 @@ export const WORKER_REPORT_TOOLS: McpToolDefinition[] = [
17
17
  ];
18
18
 
19
19
  // subagent_wait (and a foreground subagent_spawn) answers when the subagent finishes, as native `Agent` does.
20
- const LONG_RUNNING_TOOLS = new Set(['narrate', 'subagent_wait', 'subagent_spawn']);
20
+ // device_shell waits for the owner's approval and then for the command (up to 5 minutes).
21
+ const LONG_RUNNING_TOOLS = new Set(['narrate', 'subagent_wait', 'subagent_spawn', 'device_shell']);
21
22
  export const LONG_RUNNING_MAX_MS = 2 * 60 * 60 * 1000;
22
23
  export async function callTaskBridge(tool: string, args: Record<string, unknown>, requestId: string, signal: AbortSignal): Promise<McpToolResult> {
23
24
  // Rotated by the gateway at each decision/attempt boundary. A loaded token is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@0xmaxma/claude-gateway",
3
- "version": "2.1.8",
3
+ "version": "2.1.10",
4
4
  "description": "Multi-agent gateway for Claude",
5
5
  "repository": {
6
6
  "type": "git",