@defai.digital/ax-cli 4.1.18 → 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 +33 -0
- package/dist/mcp/automatosx-auto-discovery.d.ts +66 -0
- package/dist/mcp/automatosx-auto-discovery.js +168 -0
- package/dist/mcp/automatosx-auto-discovery.js.map +1 -0
- package/dist/mcp/client-v2.d.ts +109 -1
- package/dist/mcp/client-v2.js +230 -38
- package/dist/mcp/client-v2.js.map +1 -1
- package/dist/mcp/config.js +49 -4
- package/dist/mcp/config.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -2
- package/dist/mcp/index.js +4 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/provider-mcp-loader.d.ts +130 -0
- package/dist/mcp/provider-mcp-loader.js +292 -0
- package/dist/mcp/provider-mcp-loader.js.map +1 -0
- package/dist/mcp/resources.d.ts +8 -4
- package/dist/mcp/resources.js +42 -41
- package/dist/mcp/resources.js.map +1 -1
- package/package.json +1 -1
package/dist/mcp/index.d.ts
CHANGED
|
@@ -30,10 +30,14 @@
|
|
|
30
30
|
*/
|
|
31
31
|
export { MCPManager } from "./client.js";
|
|
32
32
|
export type { MCPTool, MCPServerConfig, MCPTransportConfig } from "./client.js";
|
|
33
|
-
export { MCPManagerV2, createServerName, createToolName, type ConnectionState, type ReconnectionConfig, type MCPPrompt, } from "./client-v2.js";
|
|
33
|
+
export { MCPManagerV2, createServerName, createToolName, type ConnectionState, type ReconnectionConfig, type MCPPrompt, type MCPServerCapabilities, } from "./client-v2.js";
|
|
34
34
|
export type { ServerName, ToolName } from "./client-v2.js";
|
|
35
35
|
export { loadMCPConfig, addMCPServer, removeMCPServer, PREDEFINED_SERVERS, getTemplate, generateConfigFromTemplate, } from "./config.js";
|
|
36
36
|
export type { MCPConfig } from "./config.js";
|
|
37
|
+
export { loadProviderMCPConfig, getProviderMCPServers, providerMCPConfigExists, getProviderMCPConfigPath, getClaudeCodeMCPConfigPath, getUserMCPConfigPath, getLegacyMCPConfigPath, } from "./provider-mcp-loader.js";
|
|
38
|
+
export type { ProviderMCPLoadResult, ClaudeCodeMCPConfig, LegacyProviderMCPConfig, } from "./provider-mcp-loader.js";
|
|
39
|
+
export { detectAutomatosX, getAutoDiscoveredServers, generateAutoDiscoveryConfig, isAutoDiscoveredServer, clearDetectionCache, } from "./automatosx-auto-discovery.js";
|
|
40
|
+
export type { AutomatosXDetectionResult, AutoDiscoveryOptions, } from "./automatosx-auto-discovery.js";
|
|
37
41
|
export { detectConfigFormat, detectMultipleConfigs, getDetectionSummary } from "./config-detector.js";
|
|
38
42
|
export { migrateConfig, batchMigrateConfigs, formatBatchMigrationResult } from "./config-migrator.js";
|
|
39
43
|
export { createTransport, type MCPTransport, type TransportType, type TransportConfig, type StdioFraming, } from "./transports.js";
|
|
@@ -42,7 +46,8 @@ export { CancellationManager, getCancellationManager, resetCancellationManager,
|
|
|
42
46
|
export { SubscriptionManager, getSubscriptionManager, resetSubscriptionManager, type ResourceSubscription, } from "./subscriptions.js";
|
|
43
47
|
export { ToolOutputValidator, getToolOutputValidator, resetToolOutputValidator, type SchemaValidationResult, type SchemaValidationStatus, } from "./schema-validator.js";
|
|
44
48
|
export { MCP_TIMEOUTS, MCP_LIMITS, MCP_ERROR_CODES, MCP_RECONNECTION, MCP_TRANSPORT_DEFAULTS, MCP_PATTERNS, } from "./constants.js";
|
|
45
|
-
export {
|
|
49
|
+
export { Ok, Err, toError } from "./type-safety.js";
|
|
50
|
+
export type { Result } from "./type-safety.js";
|
|
46
51
|
export { matchErrorPattern, getTransportHints, getEnvVarHints, ERROR_REMEDIATION, type Remediation } from "./error-remediation.js";
|
|
47
52
|
export { resolveMCPReferences, extractMCPReferences } from "./resources.js";
|
|
48
53
|
export { parseMCPIdentifier, promptToSlashCommand, parsePromptCommand, formatPromptResult, getPromptDescription, } from "./prompts.js";
|
package/dist/mcp/index.js
CHANGED
|
@@ -40,6 +40,10 @@ export { MCPManagerV2, createServerName, createToolName, } from "./client-v2.js"
|
|
|
40
40
|
// ============================================================================
|
|
41
41
|
// Config loading and management
|
|
42
42
|
export { loadMCPConfig, addMCPServer, removeMCPServer, PREDEFINED_SERVERS, getTemplate, generateConfigFromTemplate, } from "./config.js";
|
|
43
|
+
// Provider-specific MCP config loading (Claude Code format support)
|
|
44
|
+
export { loadProviderMCPConfig, getProviderMCPServers, providerMCPConfigExists, getProviderMCPConfigPath, getClaudeCodeMCPConfigPath, getUserMCPConfigPath, getLegacyMCPConfigPath, } from "./provider-mcp-loader.js";
|
|
45
|
+
// AutomatosX auto-discovery (seamless integration when AutomatosX is installed)
|
|
46
|
+
export { detectAutomatosX, getAutoDiscoveredServers, generateAutoDiscoveryConfig, isAutoDiscoveredServer, clearDetectionCache, } from "./automatosx-auto-discovery.js";
|
|
43
47
|
// Config detection and migration
|
|
44
48
|
export { detectConfigFormat, detectMultipleConfigs, getDetectionSummary } from "./config-detector.js";
|
|
45
49
|
export { migrateConfig, batchMigrateConfigs, formatBatchMigrationResult } from "./config-migrator.js";
|
package/dist/mcp/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,+EAA+E;AAC/E,WAAW;AACX,+EAA+E;AAE/E,kEAAkE;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,+DAA+D;AAC/D,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,cAAc,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/mcp/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6BG;AAEH,+EAA+E;AAC/E,WAAW;AACX,+EAA+E;AAE/E,kEAAkE;AAClE,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAGzC,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 +1,130 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-Specific MCP Configuration Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads MCP configurations from multiple locations following Claude Code best practices.
|
|
5
|
+
*
|
|
6
|
+
* Priority (highest to lowest):
|
|
7
|
+
* 1. .ax-glm/.mcp.json or .ax-grok/.mcp.json (provider-specific directory)
|
|
8
|
+
* 2. Project root .mcp.json (Claude Code standard location)
|
|
9
|
+
* 3. ~/.ax-glm/.mcp.json or ~/.ax-grok/.mcp.json (user-level config)
|
|
10
|
+
* 4. .ax-glm/mcp-config.json or .ax-grok/mcp-config.json (legacy format)
|
|
11
|
+
*
|
|
12
|
+
* Claude Code Format (.mcp.json):
|
|
13
|
+
* ```json
|
|
14
|
+
* {
|
|
15
|
+
* "mcpServers": {
|
|
16
|
+
* "serverName": {
|
|
17
|
+
* "command": "...",
|
|
18
|
+
* "args": [...],
|
|
19
|
+
* "env": {...}
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* This ensures that when both ax-glm and ax-grok are installed,
|
|
26
|
+
* they maintain separate MCP configurations without conflicts.
|
|
27
|
+
*/
|
|
28
|
+
import type { MCPServerConfig } from '../schemas/settings-schemas.js';
|
|
29
|
+
/**
|
|
30
|
+
* Claude Code MCP format (.mcp.json)
|
|
31
|
+
* This is the recommended format, same as Claude Code
|
|
32
|
+
*/
|
|
33
|
+
export interface ClaudeCodeMCPConfig {
|
|
34
|
+
mcpServers?: Record<string, {
|
|
35
|
+
command: string;
|
|
36
|
+
args?: string[];
|
|
37
|
+
env?: Record<string, string>;
|
|
38
|
+
disabled?: boolean;
|
|
39
|
+
}>;
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Legacy provider-specific MCP configuration format
|
|
43
|
+
* This is the format used in .ax-glm/mcp-config.json and .ax-grok/mcp-config.json
|
|
44
|
+
*/
|
|
45
|
+
export interface LegacyProviderMCPConfig {
|
|
46
|
+
mcp?: {
|
|
47
|
+
/** Whether MCP is enabled for this provider */
|
|
48
|
+
enabled?: boolean;
|
|
49
|
+
/** Command to start the MCP server */
|
|
50
|
+
serverCommand?: string;
|
|
51
|
+
/** Arguments for the MCP server command */
|
|
52
|
+
serverArgs?: string[];
|
|
53
|
+
/** Whether to auto-connect on startup */
|
|
54
|
+
autoConnect?: boolean;
|
|
55
|
+
/** Connection timeout in milliseconds */
|
|
56
|
+
timeout?: number;
|
|
57
|
+
/** Environment variables for the MCP server */
|
|
58
|
+
env?: Record<string, string>;
|
|
59
|
+
};
|
|
60
|
+
provider?: {
|
|
61
|
+
/** Provider name (e.g., 'glm', 'grok') */
|
|
62
|
+
name?: string;
|
|
63
|
+
/** Environment variable for API key */
|
|
64
|
+
apiKeyEnv?: string;
|
|
65
|
+
/** Default model */
|
|
66
|
+
defaultModel?: string;
|
|
67
|
+
};
|
|
68
|
+
integration?: {
|
|
69
|
+
/** Use AutomatosX memory system */
|
|
70
|
+
useMemory?: boolean;
|
|
71
|
+
/** Use agent context for enhanced prompts */
|
|
72
|
+
useAgentContext?: boolean;
|
|
73
|
+
/** Save responses to memory */
|
|
74
|
+
saveResponsesToMemory?: boolean;
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Result of loading provider-specific MCP config
|
|
79
|
+
*/
|
|
80
|
+
export interface ProviderMCPLoadResult {
|
|
81
|
+
/** Whether config was found */
|
|
82
|
+
found: boolean;
|
|
83
|
+
/** Path to config file */
|
|
84
|
+
configPath?: string;
|
|
85
|
+
/** Format of the config file */
|
|
86
|
+
format?: 'claude-code' | 'legacy';
|
|
87
|
+
/** Converted MCPServerConfigs (if found and valid) */
|
|
88
|
+
serverConfigs: MCPServerConfig[];
|
|
89
|
+
/** Error message if loading failed */
|
|
90
|
+
error?: string;
|
|
91
|
+
/** Warnings during loading */
|
|
92
|
+
warnings: string[];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the path to the provider-specific MCP config file (.ax-glm/.mcp.json or .ax-grok/.mcp.json)
|
|
96
|
+
*/
|
|
97
|
+
export declare function getProviderMCPConfigPath(projectRoot?: string): string;
|
|
98
|
+
/**
|
|
99
|
+
* Get the path to the Claude Code format MCP config file (.mcp.json in project root)
|
|
100
|
+
* This is the standard Claude Code location that users may already have configured
|
|
101
|
+
*/
|
|
102
|
+
export declare function getClaudeCodeMCPConfigPath(projectRoot?: string): string;
|
|
103
|
+
/**
|
|
104
|
+
* Get the path to the user-level MCP config file (~/.ax-glm/.mcp.json or ~/.ax-grok/.mcp.json)
|
|
105
|
+
*/
|
|
106
|
+
export declare function getUserMCPConfigPath(): string;
|
|
107
|
+
/**
|
|
108
|
+
* Get the path to the legacy MCP config file (mcp-config.json)
|
|
109
|
+
*/
|
|
110
|
+
export declare function getLegacyMCPConfigPath(projectRoot?: string): string;
|
|
111
|
+
/**
|
|
112
|
+
* Check if provider-specific MCP config exists (any format/location)
|
|
113
|
+
*/
|
|
114
|
+
export declare function providerMCPConfigExists(projectRoot?: string): boolean;
|
|
115
|
+
/**
|
|
116
|
+
* Load provider-specific MCP configuration
|
|
117
|
+
*
|
|
118
|
+
* This function checks multiple locations in priority order:
|
|
119
|
+
* 1. Provider-specific directory (.ax-glm/.mcp.json or .ax-grok/.mcp.json)
|
|
120
|
+
* 2. Project root .mcp.json (Claude Code standard location)
|
|
121
|
+
* 3. User-level config (~/.ax-glm/.mcp.json or ~/.ax-grok/.mcp.json)
|
|
122
|
+
* 4. Legacy format (.ax-glm/mcp-config.json or .ax-grok/mcp-config.json)
|
|
123
|
+
*
|
|
124
|
+
* The first config found is used. Converts to MCPServerConfig[] format.
|
|
125
|
+
*/
|
|
126
|
+
export declare function loadProviderMCPConfig(projectRoot?: string): ProviderMCPLoadResult;
|
|
127
|
+
/**
|
|
128
|
+
* Get provider MCP servers ready to be merged with other sources
|
|
129
|
+
*/
|
|
130
|
+
export declare function getProviderMCPServers(projectRoot?: string): MCPServerConfig[];
|
|
@@ -0,0 +1,292 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Provider-Specific MCP Configuration Loader
|
|
3
|
+
*
|
|
4
|
+
* Loads MCP configurations from multiple locations following Claude Code best practices.
|
|
5
|
+
*
|
|
6
|
+
* Priority (highest to lowest):
|
|
7
|
+
* 1. .ax-glm/.mcp.json or .ax-grok/.mcp.json (provider-specific directory)
|
|
8
|
+
* 2. Project root .mcp.json (Claude Code standard location)
|
|
9
|
+
* 3. ~/.ax-glm/.mcp.json or ~/.ax-grok/.mcp.json (user-level config)
|
|
10
|
+
* 4. .ax-glm/mcp-config.json or .ax-grok/mcp-config.json (legacy format)
|
|
11
|
+
*
|
|
12
|
+
* Claude Code Format (.mcp.json):
|
|
13
|
+
* ```json
|
|
14
|
+
* {
|
|
15
|
+
* "mcpServers": {
|
|
16
|
+
* "serverName": {
|
|
17
|
+
* "command": "...",
|
|
18
|
+
* "args": [...],
|
|
19
|
+
* "env": {...}
|
|
20
|
+
* }
|
|
21
|
+
* }
|
|
22
|
+
* }
|
|
23
|
+
* ```
|
|
24
|
+
*
|
|
25
|
+
* This ensures that when both ax-glm and ax-grok are installed,
|
|
26
|
+
* they maintain separate MCP configurations without conflicts.
|
|
27
|
+
*/
|
|
28
|
+
import fs from 'fs';
|
|
29
|
+
import path from 'path';
|
|
30
|
+
import { homedir } from 'os';
|
|
31
|
+
import { getActiveConfigPaths, getActiveProvider } from '../provider/config.js';
|
|
32
|
+
import { extractErrorMessage } from '../utils/error-handler.js';
|
|
33
|
+
/**
|
|
34
|
+
* Get the path to the provider-specific MCP config file (.ax-glm/.mcp.json or .ax-grok/.mcp.json)
|
|
35
|
+
*/
|
|
36
|
+
export function getProviderMCPConfigPath(projectRoot) {
|
|
37
|
+
const configPaths = getActiveConfigPaths();
|
|
38
|
+
const root = projectRoot || process.cwd();
|
|
39
|
+
return path.join(root, configPaths.DIR_NAME, '.mcp.json');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Get the path to the Claude Code format MCP config file (.mcp.json in project root)
|
|
43
|
+
* This is the standard Claude Code location that users may already have configured
|
|
44
|
+
*/
|
|
45
|
+
export function getClaudeCodeMCPConfigPath(projectRoot) {
|
|
46
|
+
const root = projectRoot || process.cwd();
|
|
47
|
+
return path.join(root, '.mcp.json');
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get the path to the user-level MCP config file (~/.ax-glm/.mcp.json or ~/.ax-grok/.mcp.json)
|
|
51
|
+
*/
|
|
52
|
+
export function getUserMCPConfigPath() {
|
|
53
|
+
const configPaths = getActiveConfigPaths();
|
|
54
|
+
return path.join(homedir(), configPaths.DIR_NAME, '.mcp.json');
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Get the path to the legacy MCP config file (mcp-config.json)
|
|
58
|
+
*/
|
|
59
|
+
export function getLegacyMCPConfigPath(projectRoot) {
|
|
60
|
+
const configPaths = getActiveConfigPaths();
|
|
61
|
+
const root = projectRoot || process.cwd();
|
|
62
|
+
return path.join(root, configPaths.DIR_NAME, 'mcp-config.json');
|
|
63
|
+
}
|
|
64
|
+
/**
|
|
65
|
+
* Check if provider-specific MCP config exists (any format/location)
|
|
66
|
+
*/
|
|
67
|
+
export function providerMCPConfigExists(projectRoot) {
|
|
68
|
+
return fs.existsSync(getProviderMCPConfigPath(projectRoot)) ||
|
|
69
|
+
fs.existsSync(getClaudeCodeMCPConfigPath(projectRoot)) ||
|
|
70
|
+
fs.existsSync(getUserMCPConfigPath()) ||
|
|
71
|
+
fs.existsSync(getLegacyMCPConfigPath(projectRoot));
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Load provider-specific MCP configuration
|
|
75
|
+
*
|
|
76
|
+
* This function checks multiple locations in priority order:
|
|
77
|
+
* 1. Provider-specific directory (.ax-glm/.mcp.json or .ax-grok/.mcp.json)
|
|
78
|
+
* 2. Project root .mcp.json (Claude Code standard location)
|
|
79
|
+
* 3. User-level config (~/.ax-glm/.mcp.json or ~/.ax-grok/.mcp.json)
|
|
80
|
+
* 4. Legacy format (.ax-glm/mcp-config.json or .ax-grok/mcp-config.json)
|
|
81
|
+
*
|
|
82
|
+
* The first config found is used. Converts to MCPServerConfig[] format.
|
|
83
|
+
*/
|
|
84
|
+
export function loadProviderMCPConfig(projectRoot) {
|
|
85
|
+
const warnings = [];
|
|
86
|
+
// Priority 1: Provider-specific directory (.ax-glm/.mcp.json or .ax-grok/.mcp.json)
|
|
87
|
+
const providerPath = getProviderMCPConfigPath(projectRoot);
|
|
88
|
+
if (fs.existsSync(providerPath)) {
|
|
89
|
+
try {
|
|
90
|
+
const raw = fs.readFileSync(providerPath, 'utf-8');
|
|
91
|
+
const config = JSON.parse(raw);
|
|
92
|
+
const serverConfigs = convertClaudeCodeFormat(config);
|
|
93
|
+
return {
|
|
94
|
+
found: true,
|
|
95
|
+
configPath: providerPath,
|
|
96
|
+
format: 'claude-code',
|
|
97
|
+
serverConfigs,
|
|
98
|
+
warnings,
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return {
|
|
103
|
+
found: true,
|
|
104
|
+
configPath: providerPath,
|
|
105
|
+
format: 'claude-code',
|
|
106
|
+
serverConfigs: [],
|
|
107
|
+
error: `Failed to parse ${providerPath}: ${extractErrorMessage(error)}`,
|
|
108
|
+
warnings,
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
// Priority 2: Project root .mcp.json (Claude Code standard location)
|
|
113
|
+
const claudeCodePath = getClaudeCodeMCPConfigPath(projectRoot);
|
|
114
|
+
if (fs.existsSync(claudeCodePath)) {
|
|
115
|
+
try {
|
|
116
|
+
const raw = fs.readFileSync(claudeCodePath, 'utf-8');
|
|
117
|
+
const config = JSON.parse(raw);
|
|
118
|
+
const serverConfigs = convertClaudeCodeFormat(config);
|
|
119
|
+
return {
|
|
120
|
+
found: true,
|
|
121
|
+
configPath: claudeCodePath,
|
|
122
|
+
format: 'claude-code',
|
|
123
|
+
serverConfigs,
|
|
124
|
+
warnings,
|
|
125
|
+
};
|
|
126
|
+
}
|
|
127
|
+
catch (error) {
|
|
128
|
+
return {
|
|
129
|
+
found: true,
|
|
130
|
+
configPath: claudeCodePath,
|
|
131
|
+
format: 'claude-code',
|
|
132
|
+
serverConfigs: [],
|
|
133
|
+
error: `Failed to parse .mcp.json: ${extractErrorMessage(error)}`,
|
|
134
|
+
warnings,
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
// Priority 3: User-level config (~/.ax-glm/.mcp.json or ~/.ax-grok/.mcp.json)
|
|
139
|
+
const userPath = getUserMCPConfigPath();
|
|
140
|
+
if (fs.existsSync(userPath)) {
|
|
141
|
+
try {
|
|
142
|
+
const raw = fs.readFileSync(userPath, 'utf-8');
|
|
143
|
+
const config = JSON.parse(raw);
|
|
144
|
+
const serverConfigs = convertClaudeCodeFormat(config);
|
|
145
|
+
return {
|
|
146
|
+
found: true,
|
|
147
|
+
configPath: userPath,
|
|
148
|
+
format: 'claude-code',
|
|
149
|
+
serverConfigs,
|
|
150
|
+
warnings,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
catch (error) {
|
|
154
|
+
return {
|
|
155
|
+
found: true,
|
|
156
|
+
configPath: userPath,
|
|
157
|
+
format: 'claude-code',
|
|
158
|
+
serverConfigs: [],
|
|
159
|
+
error: `Failed to parse ${userPath}: ${extractErrorMessage(error)}`,
|
|
160
|
+
warnings,
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
// Priority 4: Legacy format (.ax-glm/mcp-config.json or .ax-grok/mcp-config.json)
|
|
165
|
+
const legacyPath = getLegacyMCPConfigPath(projectRoot);
|
|
166
|
+
if (fs.existsSync(legacyPath)) {
|
|
167
|
+
warnings.push(`Using legacy mcp-config.json format. Consider migrating to .mcp.json (Claude Code format)`);
|
|
168
|
+
try {
|
|
169
|
+
const raw = fs.readFileSync(legacyPath, 'utf-8');
|
|
170
|
+
const config = JSON.parse(raw);
|
|
171
|
+
const serverConfigs = convertLegacyFormat(config);
|
|
172
|
+
return {
|
|
173
|
+
found: true,
|
|
174
|
+
configPath: legacyPath,
|
|
175
|
+
format: 'legacy',
|
|
176
|
+
serverConfigs,
|
|
177
|
+
warnings,
|
|
178
|
+
};
|
|
179
|
+
}
|
|
180
|
+
catch (error) {
|
|
181
|
+
return {
|
|
182
|
+
found: true,
|
|
183
|
+
configPath: legacyPath,
|
|
184
|
+
format: 'legacy',
|
|
185
|
+
serverConfigs: [],
|
|
186
|
+
error: `Failed to parse mcp-config.json: ${extractErrorMessage(error)}`,
|
|
187
|
+
warnings,
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
// No config found
|
|
192
|
+
return {
|
|
193
|
+
found: false,
|
|
194
|
+
serverConfigs: [],
|
|
195
|
+
warnings,
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
/**
|
|
199
|
+
* Convert Claude Code format (.mcp.json) to MCPServerConfig[]
|
|
200
|
+
*/
|
|
201
|
+
function convertClaudeCodeFormat(config) {
|
|
202
|
+
if (!config.mcpServers || typeof config.mcpServers !== 'object') {
|
|
203
|
+
return [];
|
|
204
|
+
}
|
|
205
|
+
const servers = [];
|
|
206
|
+
for (const [name, serverDef] of Object.entries(config.mcpServers)) {
|
|
207
|
+
if (serverDef.disabled) {
|
|
208
|
+
continue;
|
|
209
|
+
}
|
|
210
|
+
// Build environment variables
|
|
211
|
+
const env = {
|
|
212
|
+
AUTOMATOSX_PROJECT_DIR: process.cwd(),
|
|
213
|
+
...(serverDef.env || {}),
|
|
214
|
+
};
|
|
215
|
+
const transport = {
|
|
216
|
+
type: 'stdio',
|
|
217
|
+
command: serverDef.command,
|
|
218
|
+
args: serverDef.args || [],
|
|
219
|
+
env,
|
|
220
|
+
};
|
|
221
|
+
servers.push({
|
|
222
|
+
name,
|
|
223
|
+
enabled: true,
|
|
224
|
+
transport,
|
|
225
|
+
// Default timeout for provider MCP servers
|
|
226
|
+
initTimeout: 30000,
|
|
227
|
+
// Suppress verbose output by default
|
|
228
|
+
quiet: true,
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
return servers;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* Convert legacy format (mcp-config.json) to MCPServerConfig[]
|
|
235
|
+
*/
|
|
236
|
+
function convertLegacyFormat(config) {
|
|
237
|
+
const mcp = config.mcp;
|
|
238
|
+
if (!mcp?.serverCommand) {
|
|
239
|
+
return [];
|
|
240
|
+
}
|
|
241
|
+
// Check if MCP is disabled
|
|
242
|
+
if (mcp.enabled === false) {
|
|
243
|
+
return [];
|
|
244
|
+
}
|
|
245
|
+
const provider = getActiveProvider();
|
|
246
|
+
// Build the server name based on provider
|
|
247
|
+
// e.g., "automatosx-glm" or "automatosx-grok"
|
|
248
|
+
const serverName = `automatosx-${provider.name}`;
|
|
249
|
+
// Build environment variables
|
|
250
|
+
const env = {
|
|
251
|
+
AUTOMATOSX_PROJECT_DIR: process.cwd(),
|
|
252
|
+
...(mcp.env || {}),
|
|
253
|
+
};
|
|
254
|
+
// Add provider-specific env vars from the config
|
|
255
|
+
if (config.provider?.apiKeyEnv) {
|
|
256
|
+
env.AUTOMATOSX_API_KEY_ENV = config.provider.apiKeyEnv;
|
|
257
|
+
}
|
|
258
|
+
// Add integration settings as env vars
|
|
259
|
+
if (config.integration) {
|
|
260
|
+
if (config.integration.useMemory !== undefined) {
|
|
261
|
+
env.AUTOMATOSX_USE_MEMORY = String(config.integration.useMemory);
|
|
262
|
+
}
|
|
263
|
+
if (config.integration.useAgentContext !== undefined) {
|
|
264
|
+
env.AUTOMATOSX_USE_AGENT_CONTEXT = String(config.integration.useAgentContext);
|
|
265
|
+
}
|
|
266
|
+
if (config.integration.saveResponsesToMemory !== undefined) {
|
|
267
|
+
env.AUTOMATOSX_SAVE_RESPONSES = String(config.integration.saveResponsesToMemory);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
const transport = {
|
|
271
|
+
type: 'stdio',
|
|
272
|
+
command: mcp.serverCommand,
|
|
273
|
+
args: mcp.serverArgs || [],
|
|
274
|
+
env,
|
|
275
|
+
};
|
|
276
|
+
return [{
|
|
277
|
+
name: serverName,
|
|
278
|
+
enabled: true,
|
|
279
|
+
transport,
|
|
280
|
+
initTimeout: mcp.timeout || 30000,
|
|
281
|
+
// Suppress verbose output by default
|
|
282
|
+
quiet: true,
|
|
283
|
+
}];
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Get provider MCP servers ready to be merged with other sources
|
|
287
|
+
*/
|
|
288
|
+
export function getProviderMCPServers(projectRoot) {
|
|
289
|
+
const result = loadProviderMCPConfig(projectRoot);
|
|
290
|
+
return result.serverConfigs;
|
|
291
|
+
}
|
|
292
|
+
//# sourceMappingURL=provider-mcp-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"provider-mcp-loader.js","sourceRoot":"","sources":["../../src/mcp/provider-mcp-loader.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAEH,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,OAAO,EAAE,MAAM,IAAI,CAAC;AAC7B,OAAO,EAAE,oBAAoB,EAAE,iBAAiB,EAAE,MAAM,uBAAuB,CAAC;AAEhF,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAsEhE;;GAEG;AACH,MAAM,UAAU,wBAAwB,CAAC,WAAoB;IAC3D,MAAM,WAAW,GAAG,oBAAoB,EAAE,CAAC;IAC3C,MAAM,IAAI,GAAG,WAAW,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;IAC1C,OAAO,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,WAAW,CAAC,QAAQ,EAAE,WAAW,CAAC,CAAC;AAC5D,CAAC;AAED;;;GA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AC,MAAM,CAAC,WAAW,CAAC,eAAe,CAAC,CAAC;QAChF,CAAC;QACD,IAAI,MAAM,CAAC,WAAW,CAAC,qBAAqB,KAAK,SAAS,EAAE,CAAC;YAC3D,GAAG,CAAC,yBAAyB,GAAG,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,qBAAqB,CAAC,CAAC;QACnF,CAAC;IACH,CAAC;IAED,MAAM,SAAS,GAAuB;QACpC,IAAI,EAAE,OAAO;QACb,OAAO,EAAE,GAAG,CAAC,aAAa;QAC1B,IAAI,EAAE,GAAG,CAAC,UAAU,IAAI,EAAE;QAC1B,GAAG;KACJ,CAAC;IAEF,OAAO,CAAC;YACN,IAAI,EAAE,UAAU;YAChB,OAAO,EAAE,IAAI;YACb,SAAS;YACT,WAAW,EAAE,GAAG,CAAC,OAAO,IAAI,KAAK;YACjC,qCAAqC;YACrC,KAAK,EAAE,IAAI;SACZ,CAAC,CAAC;AACL,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,qBAAqB,CAAC,WAAoB;IACxD,MAAM,MAAM,GAAG,qBAAqB,CAAC,WAAW,CAAC,CAAC;IAClD,OAAO,MAAM,CAAC,aAAa,CAAC;AAC9B,CAAC"}
|
package/dist/mcp/resources.d.ts
CHANGED
|
@@ -3,8 +3,12 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Enables users to reference MCP-exposed resources using @mcp: syntax
|
|
5
5
|
* Similar to file references, but for database tables, API endpoints, etc.
|
|
6
|
+
*
|
|
7
|
+
* BUG FIX: Updated to use v2 manager's connection state instead of legacy clients Map.
|
|
8
|
+
* The v1 MCPManager now wraps v2 internally, so we access the v2 instance.
|
|
6
9
|
*/
|
|
7
10
|
import type { MCPManager } from './client.js';
|
|
11
|
+
import { MCPManagerV2 } from './client-v2.js';
|
|
8
12
|
export interface MCPResource {
|
|
9
13
|
/** Resource URI (e.g., database://users, api://endpoints/get-user) */
|
|
10
14
|
uri: string;
|
|
@@ -22,15 +26,15 @@ export interface MCPResource {
|
|
|
22
26
|
/**
|
|
23
27
|
* List all resources from MCP servers
|
|
24
28
|
*/
|
|
25
|
-
export declare function listAllResources(mcpManager: MCPManager): Promise<MCPResource[]>;
|
|
29
|
+
export declare function listAllResources(mcpManager: MCPManager | MCPManagerV2): Promise<MCPResource[]>;
|
|
26
30
|
/**
|
|
27
31
|
* List resources from a specific MCP server
|
|
28
32
|
*/
|
|
29
|
-
export declare function listServerResources(mcpManager: MCPManager, serverName: string): Promise<MCPResource[]>;
|
|
33
|
+
export declare function listServerResources(mcpManager: MCPManager | MCPManagerV2, serverName: string): Promise<MCPResource[]>;
|
|
30
34
|
/**
|
|
31
35
|
* Get resource content from MCP server
|
|
32
36
|
*/
|
|
33
|
-
export declare function getResourceContent(mcpManager: MCPManager, serverName: string, uri: string): Promise<string>;
|
|
37
|
+
export declare function getResourceContent(mcpManager: MCPManager | MCPManagerV2, serverName: string, uri: string): Promise<string>;
|
|
34
38
|
/**
|
|
35
39
|
* Parse @mcp: reference
|
|
36
40
|
* Format: @mcp:server/uri
|
|
@@ -47,7 +51,7 @@ export declare function extractMCPReferences(text: string): string[];
|
|
|
47
51
|
/**
|
|
48
52
|
* Replace MCP references in text with actual content
|
|
49
53
|
*/
|
|
50
|
-
export declare function resolveMCPReferences(text: string, mcpManager: MCPManager): Promise<string>;
|
|
54
|
+
export declare function resolveMCPReferences(text: string, mcpManager: MCPManager | MCPManagerV2): Promise<string>;
|
|
51
55
|
/**
|
|
52
56
|
* Search resources by name or URI
|
|
53
57
|
*/
|
package/dist/mcp/resources.js
CHANGED
|
@@ -3,17 +3,33 @@
|
|
|
3
3
|
*
|
|
4
4
|
* Enables users to reference MCP-exposed resources using @mcp: syntax
|
|
5
5
|
* Similar to file references, but for database tables, API endpoints, etc.
|
|
6
|
+
*
|
|
7
|
+
* BUG FIX: Updated to use v2 manager's connection state instead of legacy clients Map.
|
|
8
|
+
* The v1 MCPManager now wraps v2 internally, so we access the v2 instance.
|
|
6
9
|
*/
|
|
10
|
+
import { MCPManagerV2, createServerName } from './client-v2.js';
|
|
7
11
|
import { extractErrorMessage } from '../utils/error-handler.js';
|
|
12
|
+
/**
|
|
13
|
+
* Get the v2 manager from either v1 or v2 instance
|
|
14
|
+
*/
|
|
15
|
+
function getV2Manager(mcpManager) {
|
|
16
|
+
// If it's already v2, return it directly
|
|
17
|
+
if (mcpManager instanceof MCPManagerV2) {
|
|
18
|
+
return mcpManager;
|
|
19
|
+
}
|
|
20
|
+
// Otherwise, it's v1 wrapper - access the internal v2 instance
|
|
21
|
+
return mcpManager.v2;
|
|
22
|
+
}
|
|
8
23
|
/**
|
|
9
24
|
* List all resources from MCP servers
|
|
10
25
|
*/
|
|
11
26
|
export async function listAllResources(mcpManager) {
|
|
12
27
|
const resources = [];
|
|
13
|
-
const
|
|
28
|
+
const v2 = getV2Manager(mcpManager);
|
|
29
|
+
const servers = v2.getServers();
|
|
14
30
|
for (const serverName of servers) {
|
|
15
31
|
try {
|
|
16
|
-
const serverResources = await listServerResources(mcpManager, serverName);
|
|
32
|
+
const serverResources = await listServerResources(mcpManager, String(serverName));
|
|
17
33
|
resources.push(...serverResources);
|
|
18
34
|
}
|
|
19
35
|
catch {
|
|
@@ -27,55 +43,40 @@ export async function listAllResources(mcpManager) {
|
|
|
27
43
|
* List resources from a specific MCP server
|
|
28
44
|
*/
|
|
29
45
|
export async function listServerResources(mcpManager, serverName) {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
return [];
|
|
35
|
-
}
|
|
36
|
-
// Try to list resources
|
|
37
|
-
const result = await client.listResources();
|
|
38
|
-
// Convert to our resource format
|
|
39
|
-
return result.resources.map((resource) => ({
|
|
40
|
-
uri: resource.uri,
|
|
41
|
-
name: resource.name || resource.uri,
|
|
42
|
-
description: resource.description,
|
|
43
|
-
mimeType: resource.mimeType,
|
|
44
|
-
serverName,
|
|
45
|
-
reference: `@mcp:${serverName}/${resource.uri}`
|
|
46
|
-
}));
|
|
46
|
+
const v2 = getV2Manager(mcpManager);
|
|
47
|
+
const brandedServerName = createServerName(serverName);
|
|
48
|
+
if (!brandedServerName) {
|
|
49
|
+
return [];
|
|
47
50
|
}
|
|
48
|
-
|
|
49
|
-
|
|
51
|
+
// Use the v2 manager's listResources method
|
|
52
|
+
const result = await v2.listResources(brandedServerName);
|
|
53
|
+
if (!result.success) {
|
|
50
54
|
return [];
|
|
51
55
|
}
|
|
56
|
+
// Convert to our resource format
|
|
57
|
+
return result.value.map(resource => ({
|
|
58
|
+
uri: resource.uri,
|
|
59
|
+
name: resource.name || resource.uri,
|
|
60
|
+
description: resource.description,
|
|
61
|
+
mimeType: resource.mimeType,
|
|
62
|
+
serverName,
|
|
63
|
+
reference: `@mcp:${serverName}/${resource.uri}`
|
|
64
|
+
}));
|
|
52
65
|
}
|
|
53
66
|
/**
|
|
54
67
|
* Get resource content from MCP server
|
|
55
68
|
*/
|
|
56
69
|
export async function getResourceContent(mcpManager, serverName, uri) {
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
}
|
|
62
|
-
const result = await client.readResource({ uri });
|
|
63
|
-
// Extract text content
|
|
64
|
-
if (result.contents && result.contents.length > 0) {
|
|
65
|
-
const content = result.contents[0];
|
|
66
|
-
if (content.text) {
|
|
67
|
-
return content.text;
|
|
68
|
-
}
|
|
69
|
-
if (content.blob) {
|
|
70
|
-
// Handle base64 encoded content
|
|
71
|
-
return Buffer.from(content.blob, 'base64').toString('utf-8');
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return '';
|
|
70
|
+
const v2 = getV2Manager(mcpManager);
|
|
71
|
+
const brandedServerName = createServerName(serverName);
|
|
72
|
+
if (!brandedServerName) {
|
|
73
|
+
throw new Error(`Invalid server name: "${serverName}"`);
|
|
75
74
|
}
|
|
76
|
-
|
|
77
|
-
|
|
75
|
+
const result = await v2.readResource(brandedServerName, uri);
|
|
76
|
+
if (!result.success) {
|
|
77
|
+
throw new Error(`Failed to read resource ${uri}: ${extractErrorMessage(result.error)}`);
|
|
78
78
|
}
|
|
79
|
+
return result.value;
|
|
79
80
|
}
|
|
80
81
|
/**
|
|
81
82
|
* Parse @mcp: reference
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/mcp/resources.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"resources.js","sourceRoot":"","sources":["../../src/mcp/resources.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAGH,OAAO,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAChE,OAAO,EAAE,mBAAmB,EAAE,MAAM,2BAA2B,CAAC;AAiBhE;;GAEG;AACH,SAAS,YAAY,CAAC,UAAqC;IACzD,yCAAyC;IACzC,IAAI,UAAU,YAAY,YAAY,EAAE,CAAC;QACvC,OAAO,UAAU,CAAC;IACpB,CAAC;IACD,+DAA+D;IAC/D,OAAQ,UAAkB,CAAC,EAAkB,CAAC;AAChD,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,UAAqC;IAC1E,MAAM,SAAS,GAAkB,EAAE,CAAC;IACpC,MAAM,EAAE,GAAG,YAAY,CAAC,UAAU,CAAC,CAAC;IACpC,MAAM,OAAO,GAAG,EAAE,CAAC,UAAU,EAAE,CAAC;IAEhC,KAAK,MAAM,UAAU,IAAI,OAAO,EAAE,CAAC;QACjC,IAAI,CAAC;YACH,MAAM,eAAe,GAAG,MAAM,mBAAmB,CAAC,UAAU,EAAE,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC;YAClF,SAAS,CAAC,IAAI,CAAC,GAAG,eAAe,CAAC,CAAC;QACrC,CAAC;QAAC,MAAM,CAAC;YACP,qDAAqD;YACrD,OAAO,CAAC,IAAI,CAAC,WAAW,UAAU,qDAAqD,CAAC,CAAC;QAC3F,CAAC;IACH,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED;;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