@defai.digital/ax-cli 4.2.0 → 4.3.0

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 CHANGED
@@ -223,6 +223,16 @@ ax-glm memory status # View token distribution
223
223
 
224
224
  ## Changelog
225
225
 
226
+ ### v4.3.0 - MCP Client V2 & Resource Support
227
+
228
+ **Enhanced MCP Integration**: Major upgrade to MCP client with improved resource handling and connection reliability.
229
+
230
+ - **MCP Client V2**: Rewritten MCP client with better error handling, connection pooling, and retry logic
231
+ - **Resource Support**: Full support for MCP resources with read/subscribe capabilities
232
+ - **Provider MCP Loader**: Improved provider-specific MCP configuration loading
233
+ - **Connection Stability**: Better handling of MCP server disconnections and reconnections
234
+ - **Bug Fixes**: Various stability improvements and edge case handling
235
+
226
236
  ### v4.2.0 - Provider-Specific MCP Configuration
227
237
 
228
238
  **Provider MCP Isolation**: ax-glm and ax-grok now have separate MCP configurations, allowing both CLIs to run simultaneously without conflicts.
@@ -0,0 +1,66 @@
1
+ /**
2
+ * AutomatosX MCP Auto-Discovery
3
+ *
4
+ * Automatically detects and enables AutomatosX MCP server when installed.
5
+ * This provides seamless integration between ax-glm/ax-grok and AutomatosX.
6
+ *
7
+ * Design:
8
+ * 1. Check if `automatosx` command exists in PATH
9
+ * 2. If installed, automatically inject AutomatosX MCP server config
10
+ * 3. User can override via .mcp.json or disable via settings
11
+ *
12
+ * This ensures that when users have both ax-glm/ax-grok and AutomatosX installed,
13
+ * they get automatic integration without manual configuration.
14
+ */
15
+ import type { MCPServerConfig } from '../schemas/settings-schemas.js';
16
+ /**
17
+ * Result of AutomatosX detection
18
+ */
19
+ export interface AutomatosXDetectionResult {
20
+ /** Whether AutomatosX is installed and available */
21
+ installed: boolean;
22
+ /** Path to the automatosx command (if found) */
23
+ commandPath?: string;
24
+ /** Version of AutomatosX (if detected) */
25
+ version?: string;
26
+ /** Whether MCP server capability is available */
27
+ hasMCPServer: boolean;
28
+ /** Error message if detection failed */
29
+ error?: string;
30
+ }
31
+ /**
32
+ * Options for auto-discovery
33
+ */
34
+ export interface AutoDiscoveryOptions {
35
+ /** Skip auto-discovery entirely */
36
+ disabled?: boolean;
37
+ /** Custom command path for automatosx */
38
+ customCommandPath?: string;
39
+ /** Custom environment variables for the MCP server */
40
+ env?: Record<string, string>;
41
+ }
42
+ /**
43
+ * Detect if AutomatosX is installed and available
44
+ */
45
+ export declare function detectAutomatosX(forceRefresh?: boolean): AutomatosXDetectionResult;
46
+ /**
47
+ * Generate AutomatosX MCP server config for auto-discovery
48
+ */
49
+ export declare function generateAutoDiscoveryConfig(options?: AutoDiscoveryOptions): MCPServerConfig | null;
50
+ /**
51
+ * Get auto-discovered MCP servers
52
+ *
53
+ * Returns AutomatosX MCP server config if:
54
+ * 1. AutomatosX is installed
55
+ * 2. It has MCP server capability
56
+ * 3. Auto-discovery is not disabled
57
+ */
58
+ export declare function getAutoDiscoveredServers(options?: AutoDiscoveryOptions): MCPServerConfig[];
59
+ /**
60
+ * Check if a server name is an auto-discovered AutomatosX server
61
+ */
62
+ export declare function isAutoDiscoveredServer(serverName: string): boolean;
63
+ /**
64
+ * Clear the detection cache
65
+ */
66
+ export declare function clearDetectionCache(): void;
@@ -0,0 +1,168 @@
1
+ /**
2
+ * AutomatosX MCP Auto-Discovery
3
+ *
4
+ * Automatically detects and enables AutomatosX MCP server when installed.
5
+ * This provides seamless integration between ax-glm/ax-grok and AutomatosX.
6
+ *
7
+ * Design:
8
+ * 1. Check if `automatosx` command exists in PATH
9
+ * 2. If installed, automatically inject AutomatosX MCP server config
10
+ * 3. User can override via .mcp.json or disable via settings
11
+ *
12
+ * This ensures that when users have both ax-glm/ax-grok and AutomatosX installed,
13
+ * they get automatic integration without manual configuration.
14
+ */
15
+ import { execSync } from 'child_process';
16
+ import { getActiveProvider } from '../provider/config.js';
17
+ // Cache the detection result to avoid repeated checks
18
+ let cachedDetection = null;
19
+ let cacheTime = 0;
20
+ const CACHE_TTL_MS = 60000; // 1 minute
21
+ /**
22
+ * Detect if AutomatosX is installed and available
23
+ */
24
+ export function detectAutomatosX(forceRefresh = false) {
25
+ // Return cached result if still valid
26
+ const now = Date.now();
27
+ if (!forceRefresh && cachedDetection && (now - cacheTime) < CACHE_TTL_MS) {
28
+ return cachedDetection;
29
+ }
30
+ try {
31
+ // Try to find automatosx in PATH
32
+ const commandPath = findCommand('automatosx');
33
+ if (!commandPath) {
34
+ cachedDetection = {
35
+ installed: false,
36
+ hasMCPServer: false,
37
+ };
38
+ cacheTime = now;
39
+ return cachedDetection;
40
+ }
41
+ // Check version
42
+ let version;
43
+ try {
44
+ const versionOutput = execSync('automatosx --version', {
45
+ encoding: 'utf-8',
46
+ timeout: 5000,
47
+ stdio: ['pipe', 'pipe', 'pipe'],
48
+ }).trim();
49
+ version = versionOutput;
50
+ }
51
+ catch {
52
+ // Version check failed, but command exists
53
+ }
54
+ // Check if MCP server capability exists
55
+ let hasMCPServer = false;
56
+ try {
57
+ const helpOutput = execSync('automatosx mcp --help', {
58
+ encoding: 'utf-8',
59
+ timeout: 5000,
60
+ stdio: ['pipe', 'pipe', 'pipe'],
61
+ });
62
+ hasMCPServer = helpOutput.includes('mcp server') || helpOutput.includes('Start AutomatosX as MCP server');
63
+ }
64
+ catch {
65
+ // MCP help failed, might be older version
66
+ }
67
+ cachedDetection = {
68
+ installed: true,
69
+ commandPath,
70
+ version,
71
+ hasMCPServer,
72
+ };
73
+ cacheTime = now;
74
+ return cachedDetection;
75
+ }
76
+ catch (error) {
77
+ cachedDetection = {
78
+ installed: false,
79
+ hasMCPServer: false,
80
+ error: error instanceof Error ? error.message : String(error),
81
+ };
82
+ cacheTime = now;
83
+ return cachedDetection;
84
+ }
85
+ }
86
+ /**
87
+ * Find a command in PATH
88
+ */
89
+ function findCommand(command) {
90
+ try {
91
+ // Use 'which' on Unix, 'where' on Windows
92
+ const whichCmd = process.platform === 'win32' ? 'where' : 'which';
93
+ const result = execSync(`${whichCmd} ${command}`, {
94
+ encoding: 'utf-8',
95
+ timeout: 5000,
96
+ stdio: ['pipe', 'pipe', 'pipe'],
97
+ }).trim();
98
+ // 'where' on Windows might return multiple lines
99
+ return result.split('\n')[0]?.trim();
100
+ }
101
+ catch {
102
+ return undefined;
103
+ }
104
+ }
105
+ /**
106
+ * Generate AutomatosX MCP server config for auto-discovery
107
+ */
108
+ export function generateAutoDiscoveryConfig(options) {
109
+ if (options?.disabled) {
110
+ return null;
111
+ }
112
+ const detection = detectAutomatosX();
113
+ if (!detection.installed || !detection.hasMCPServer) {
114
+ return null;
115
+ }
116
+ const provider = getActiveProvider();
117
+ const serverName = `automatosx-${provider.name}`;
118
+ const command = options?.customCommandPath || detection.commandPath || 'automatosx';
119
+ // Build environment variables
120
+ const env = {
121
+ // Set the project directory
122
+ AUTOMATOSX_PROJECT_DIR: process.cwd(),
123
+ // Indicate which provider is using AutomatosX
124
+ AUTOMATOSX_PROVIDER: provider.name,
125
+ // Pass through any custom env vars
126
+ ...(options?.env || {}),
127
+ };
128
+ const transport = {
129
+ type: 'stdio',
130
+ command,
131
+ args: ['mcp', 'server'],
132
+ env,
133
+ };
134
+ return {
135
+ name: serverName,
136
+ enabled: true,
137
+ transport,
138
+ initTimeout: 30000,
139
+ // Mark as auto-discovered
140
+ quiet: true,
141
+ };
142
+ }
143
+ /**
144
+ * Get auto-discovered MCP servers
145
+ *
146
+ * Returns AutomatosX MCP server config if:
147
+ * 1. AutomatosX is installed
148
+ * 2. It has MCP server capability
149
+ * 3. Auto-discovery is not disabled
150
+ */
151
+ export function getAutoDiscoveredServers(options) {
152
+ const config = generateAutoDiscoveryConfig(options);
153
+ return config ? [config] : [];
154
+ }
155
+ /**
156
+ * Check if a server name is an auto-discovered AutomatosX server
157
+ */
158
+ export function isAutoDiscoveredServer(serverName) {
159
+ return serverName.startsWith('automatosx-');
160
+ }
161
+ /**
162
+ * Clear the detection cache
163
+ */
164
+ export function clearDetectionCache() {
165
+ cachedDetection = null;
166
+ cacheTime = 0;
167
+ }
168
+ //# sourceMappingURL=automatosx-auto-discovery.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"automatosx-auto-discovery.js","sourceRoot":"","sources":["../../src/mcp/automatosx-auto-discovery.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAEzC,OAAO,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AA8B1D,sDAAsD;AACtD,IAAI,eAAe,GAAqC,IAAI,CAAC;AAC7D,IAAI,SAAS,GAAW,CAAC,CAAC;AAC1B,MAAM,YAAY,GAAG,KAAK,CAAC,CAAC,WAAW;AAEvC;;GAEG;AACH,MAAM,UAAU,gBAAgB,CAAC,YAAY,GAAG,KAAK;IACnD,sCAAsC;IACtC,MAAM,GAAG,GAAG,IAAI,CAAC,GAAG,EAAE,CAAC;IACvB,IAAI,CAAC,YAAY,IAAI,eAAe,IAAI,CAAC,GAAG,GAAG,SAAS,CAAC,GAAG,YAAY,EAAE,CAAC;QACzE,OAAO,eAAe,CAAC;IACzB,CAAC;IAED,IAAI,CAAC;QACH,iCAAiC;QACjC,MAAM,WAAW,GAAG,WAAW,CAAC,YAAY,CAAC,CAAC;QAE9C,IAAI,CAAC,WAAW,EAAE,CAAC;YACjB,eAAe,GAAG;gBAChB,SAAS,EAAE,KAAK;gBAChB,YAAY,EAAE,KAAK;aACpB,CAAC;YACF,SAAS,GAAG,GAAG,CAAC;YAChB,OAAO,eAAe,CAAC;QACzB,CAAC;QAED,gBAAgB;QAChB,IAAI,OAA2B,CAAC;QAChC,IAAI,CAAC;YACH,MAAM,aAAa,GAAG,QAAQ,CAAC,sBAAsB,EAAE;gBACrD,QAAQ,EAAE,OAAO;gBACjB,OAAO,EAAE,IAAI;gBACb,KAAK,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC;aAChC,CAAC,CAAC,IAAI,EAAE,CAAC;YACV,OAAO,GAAG,aAAa,CAA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B,KAAK,EAAE,IAAI;KACZ,CAAC;AACJ,CAAC;AAED;;;;;;;GAOG;AACH,MAAM,UAAU,wBAAwB,CAAC,OAA8B;IACrE,MAAM,MAAM,GAAG,2BAA2B,CAAC,OAAO,CAAC,CAAC;IACpD,OAAO,MAAM,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AAChC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,UAAkB;IACvD,OAAO,UAAU,CAAC,UAAU,CAAC,aAAa,CAAC,CAAC;AAC9C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,mBAAmB;IACjC,eAAe,GAAG,IAAI,CAAC;IACvB,SAAS,GAAG,CAAC,CAAC;AAChB,CAAC"}
@@ -138,6 +138,37 @@ export interface MCPPrompt {
138
138
  required?: boolean;
139
139
  }>;
140
140
  }
141
+ /**
142
+ * MCP Server Capabilities Summary
143
+ *
144
+ * Provides a structured view of what an MCP server supports.
145
+ * This enables agents to tailor their behavior based on server capabilities.
146
+ *
147
+ * For example, Figma MCP servers may support:
148
+ * - Resource subscriptions for real-time design updates
149
+ * - Progress notifications for long-running exports
150
+ * - Tools with output schemas for structured responses
151
+ */
152
+ export interface MCPServerCapabilities {
153
+ /** Whether the server supports resources/list and resources/read */
154
+ supportsResources: boolean;
155
+ /** Whether the server supports resources/subscribe for real-time updates */
156
+ supportsResourceSubscriptions: boolean;
157
+ /** Whether the server emits notifications/resources/list_changed */
158
+ supportsResourceListChanged: boolean;
159
+ /** Whether the server supports tools/list and tools/call */
160
+ supportsTools: boolean;
161
+ /** Whether the server emits notifications/tools/list_changed */
162
+ supportsToolListChanged: boolean;
163
+ /** Whether the server supports prompts/list and prompts/get */
164
+ supportsPrompts: boolean;
165
+ /** Whether the server emits notifications/prompts/list_changed */
166
+ supportsPromptListChanged: boolean;
167
+ /** Whether the server supports logging/setLevel */
168
+ supportsLogging: boolean;
169
+ experimental: Record<string, unknown>;
170
+ raw: Record<string, unknown>;
171
+ }
141
172
  /**
142
173
  * Type-safe MCP Manager with improved safety
143
174
  */
@@ -198,17 +229,28 @@ export declare class MCPManagerV2 extends EventEmitter {
198
229
  *
199
230
  * @param toolName - The tool to call
200
231
  * @param arguments_ - Tool arguments
201
- * @param options - Optional settings for validation
232
+ * @param options - Optional settings for validation and MCP _meta
202
233
  * @returns Result containing the tool result with optional schema validation
203
234
  */
204
235
  callTool(toolName: ToolName, arguments_: Record<string, unknown> | null | undefined, options?: {
205
236
  validateOutput?: boolean;
237
+ /** MCP _meta for progress tracking and cancellation */
238
+ _meta?: {
239
+ progressToken?: string | number;
240
+ /** Request ID for cancellation (custom extension) */
241
+ requestId?: string | number;
242
+ };
243
+ /** AbortSignal for cancellation */
244
+ signal?: AbortSignal;
206
245
  }): Promise<Result<ValidatedToolResult, Error>>;
207
246
  /**
208
247
  * Call MCP tool with progress tracking
209
248
  *
210
249
  * MCP Specification: Supports notifications/progress for long-running operations.
211
250
  *
251
+ * FIX: Now properly forwards _meta.progressToken to the MCP server so it can
252
+ * attach progress notifications to this specific request.
253
+ *
212
254
  * @param toolName - The tool to call
213
255
  * @param arguments_ - Tool arguments
214
256
  * @param options - Progress tracking options
@@ -222,6 +264,10 @@ export declare class MCPManagerV2 extends EventEmitter {
222
264
  *
223
265
  * MCP Specification: Supports notifications/cancelled for aborting operations.
224
266
  *
267
+ * FIX: Now properly propagates AbortSignal to the MCP SDK so cancellation
268
+ * actually stops the server work instead of just racing locally. Also sends
269
+ * notifications/cancelled to the server so it can clean up.
270
+ *
225
271
  * @param toolName - The tool to call
226
272
  * @param arguments_ - Tool arguments
227
273
  * @returns Result containing the tool result, cancellation status, or error
@@ -335,6 +381,68 @@ export declare class MCPManagerV2 extends EventEmitter {
335
381
  * Get transport type for a server
336
382
  */
337
383
  getTransportType(serverName: ServerName): Result<TransportType, Error>;
384
+ /**
385
+ * Get capabilities for a specific MCP server
386
+ *
387
+ * This allows agents to tailor their behavior based on server capabilities.
388
+ * For example, Figma MCP servers may support long-running exports with progress.
389
+ *
390
+ * @param serverName - The server to query capabilities for
391
+ * @returns Result containing capability summary or error
392
+ *
393
+ * @example
394
+ * ```typescript
395
+ * const caps = manager.getServerCapabilities(serverName);
396
+ * if (caps.success && caps.value.supportsProgress) {
397
+ * // Use callToolWithProgress for better UX
398
+ * await manager.callToolWithProgress(toolName, args, { onProgress });
399
+ * }
400
+ * ```
401
+ */
402
+ getServerCapabilities(serverName: ServerName): Result<MCPServerCapabilities, Error>;
403
+ /**
404
+ * Get capabilities for all connected servers
405
+ *
406
+ * @returns Map of server names to their capabilities
407
+ */
408
+ getAllServerCapabilities(): Map<ServerName, MCPServerCapabilities>;
409
+ /**
410
+ * Check if a server supports a specific capability
411
+ *
412
+ * @param serverName - Server to check
413
+ * @param capability - Capability to check for
414
+ * @returns true if the server supports the capability
415
+ */
416
+ serverSupports(serverName: ServerName, capability: keyof Omit<MCPServerCapabilities, 'experimental' | 'raw'>): boolean;
417
+ /**
418
+ * Get the MCP client for a specific server
419
+ *
420
+ * This is used by resources.ts to access listResources/readResource
421
+ *
422
+ * @param serverName - The server name
423
+ * @returns Result containing the client or error
424
+ */
425
+ getClient(serverName: ServerName): Result<Client, Error>;
426
+ /**
427
+ * List resources from a specific server
428
+ *
429
+ * @param serverName - The server name
430
+ * @returns Result containing resources or error
431
+ */
432
+ listResources(serverName: ServerName): Promise<Result<Array<{
433
+ uri: string;
434
+ name: string;
435
+ description?: string;
436
+ mimeType?: string;
437
+ }>, Error>>;
438
+ /**
439
+ * Read a resource from a specific server
440
+ *
441
+ * @param serverName - The server name
442
+ * @param uri - Resource URI
443
+ * @returns Result containing resource content or error
444
+ */
445
+ readResource(serverName: ServerName, uri: string): Promise<Result<string, Error>>;
338
446
  /**
339
447
  * Schedule reconnection for a failed server with exponential backoff
340
448
  *