agentinit 1.4.0 → 1.5.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/CHANGELOG.md +19 -0
- package/README.md +209 -0
- package/dist/agentinit-1.5.0.tgz +0 -0
- package/dist/agents/Agent.d.ts +110 -0
- package/dist/agents/Agent.d.ts.map +1 -0
- package/dist/agents/Agent.js +174 -0
- package/dist/agents/Agent.js.map +1 -0
- package/dist/agents/ClaudeAgent.d.ts +50 -0
- package/dist/agents/ClaudeAgent.d.ts.map +1 -0
- package/dist/agents/ClaudeAgent.js +249 -0
- package/dist/agents/ClaudeAgent.js.map +1 -0
- package/dist/agents/ClaudeDesktopAgent.d.ts +49 -0
- package/dist/agents/ClaudeDesktopAgent.d.ts.map +1 -0
- package/dist/agents/ClaudeDesktopAgent.js +143 -0
- package/dist/agents/ClaudeDesktopAgent.js.map +1 -0
- package/dist/agents/CodexCliAgent.d.ts +48 -0
- package/dist/agents/CodexCliAgent.d.ts.map +1 -0
- package/dist/agents/CodexCliAgent.js +262 -0
- package/dist/agents/CodexCliAgent.js.map +1 -0
- package/dist/agents/CursorAgent.d.ts +44 -0
- package/dist/agents/CursorAgent.d.ts.map +1 -0
- package/dist/agents/CursorAgent.js +231 -0
- package/dist/agents/CursorAgent.js.map +1 -0
- package/dist/agents/GeminiCliAgent.d.ts +40 -0
- package/dist/agents/GeminiCliAgent.d.ts.map +1 -0
- package/dist/agents/GeminiCliAgent.js +195 -0
- package/dist/agents/GeminiCliAgent.js.map +1 -0
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +33191 -0
- package/dist/cli.js.map +1 -0
- package/dist/commands/apply.d.ts +2 -0
- package/dist/commands/apply.d.ts.map +1 -0
- package/dist/commands/apply.js +468 -0
- package/dist/commands/apply.js.map +1 -0
- package/dist/commands/config.d.ts +8 -0
- package/dist/commands/config.d.ts.map +1 -0
- package/dist/commands/config.js +6 -0
- package/dist/commands/config.js.map +1 -0
- package/dist/commands/detect.d.ts +6 -0
- package/dist/commands/detect.d.ts.map +1 -0
- package/dist/commands/detect.js +55 -0
- package/dist/commands/detect.js.map +1 -0
- package/dist/commands/init.d.ts +7 -0
- package/dist/commands/init.d.ts.map +1 -0
- package/dist/commands/init.js +105 -0
- package/dist/commands/init.js.map +1 -0
- package/dist/commands/mcp.d.ts +8 -0
- package/dist/commands/mcp.d.ts.map +1 -0
- package/dist/commands/mcp.js +127 -0
- package/dist/commands/mcp.js.map +1 -0
- package/dist/commands/subagents.d.ts +9 -0
- package/dist/commands/subagents.d.ts.map +1 -0
- package/dist/commands/subagents.js +6 -0
- package/dist/commands/subagents.js.map +1 -0
- package/dist/commands/sync.d.ts +7 -0
- package/dist/commands/sync.d.ts.map +1 -0
- package/dist/commands/sync.js +49 -0
- package/dist/commands/sync.js.map +1 -0
- package/dist/commands/verifyMcp.d.ts +2 -0
- package/dist/commands/verifyMcp.d.ts.map +1 -0
- package/dist/commands/verifyMcp.js +215 -0
- package/dist/commands/verifyMcp.js.map +1 -0
- package/dist/constants/index.d.ts +3 -0
- package/dist/constants/index.d.ts.map +1 -0
- package/dist/constants/index.js +3 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/constants/mcp.d.ts +9 -0
- package/dist/constants/mcp.d.ts.map +1 -0
- package/dist/constants/mcp.js +28 -0
- package/dist/constants/mcp.js.map +1 -0
- package/dist/constants/tokens.d.ts +6 -0
- package/dist/constants/tokens.d.ts.map +1 -0
- package/dist/constants/tokens.js +5 -0
- package/dist/constants/tokens.js.map +1 -0
- package/dist/core/agentDetector.d.ts +9 -0
- package/dist/core/agentDetector.d.ts.map +1 -0
- package/dist/core/agentDetector.js +51 -0
- package/dist/core/agentDetector.js.map +1 -0
- package/dist/core/agentManager.d.ts +55 -0
- package/dist/core/agentManager.d.ts.map +1 -0
- package/dist/core/agentManager.js +111 -0
- package/dist/core/agentManager.js.map +1 -0
- package/dist/core/configMerger.d.ts +49 -0
- package/dist/core/configMerger.d.ts.map +1 -0
- package/dist/core/configMerger.js +180 -0
- package/dist/core/configMerger.js.map +1 -0
- package/dist/core/mcpClient.d.ts +38 -0
- package/dist/core/mcpClient.d.ts.map +1 -0
- package/dist/core/mcpClient.js +416 -0
- package/dist/core/mcpClient.js.map +1 -0
- package/dist/core/mcpFilter.d.ts +44 -0
- package/dist/core/mcpFilter.d.ts.map +1 -0
- package/dist/core/mcpFilter.js +126 -0
- package/dist/core/mcpFilter.js.map +1 -0
- package/dist/core/mcpParser.d.ts +25 -0
- package/dist/core/mcpParser.d.ts.map +1 -0
- package/dist/core/mcpParser.js +297 -0
- package/dist/core/mcpParser.js.map +1 -0
- package/dist/core/propagator.d.ts +25 -0
- package/dist/core/propagator.d.ts.map +1 -0
- package/dist/core/propagator.js +154 -0
- package/dist/core/propagator.js.map +1 -0
- package/dist/core/rulesApplicator.d.ts +29 -0
- package/dist/core/rulesApplicator.d.ts.map +1 -0
- package/dist/core/rulesApplicator.js +181 -0
- package/dist/core/rulesApplicator.js.map +1 -0
- package/dist/core/rulesParser.d.ts +41 -0
- package/dist/core/rulesParser.d.ts.map +1 -0
- package/dist/core/rulesParser.js +260 -0
- package/dist/core/rulesParser.js.map +1 -0
- package/dist/core/rulesTemplateLoader.d.ts +31 -0
- package/dist/core/rulesTemplateLoader.d.ts.map +1 -0
- package/dist/core/rulesTemplateLoader.js +75 -0
- package/dist/core/rulesTemplateLoader.js.map +1 -0
- package/dist/core/stackDetector.d.ts +16 -0
- package/dist/core/stackDetector.d.ts.map +1 -0
- package/dist/core/stackDetector.js +234 -0
- package/dist/core/stackDetector.js.map +1 -0
- package/dist/core/templateEngine.d.ts +15 -0
- package/dist/core/templateEngine.d.ts.map +1 -0
- package/dist/core/templateEngine.js +260 -0
- package/dist/core/templateEngine.js.map +1 -0
- package/dist/core/tomlGenerator.d.ts +24 -0
- package/dist/core/tomlGenerator.d.ts.map +1 -0
- package/dist/core/tomlGenerator.js +185 -0
- package/dist/core/tomlGenerator.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +21 -33195
- package/dist/index.js.map +1 -0
- package/dist/lib/index.d.ts +39 -0
- package/dist/lib/index.d.ts.map +1 -0
- package/dist/lib/index.js +40 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/types/index.d.ts +23 -0
- package/dist/lib/types/index.d.ts.map +1 -0
- package/dist/lib/types/index.js +23 -0
- package/dist/lib/types/index.js.map +1 -0
- package/dist/lib/utils/index.d.ts +18 -0
- package/dist/lib/utils/index.d.ts.map +1 -0
- package/dist/lib/utils/index.js +21 -0
- package/dist/lib/utils/index.js.map +1 -0
- package/dist/lib/verifier/index.d.ts +22 -0
- package/dist/lib/verifier/index.d.ts.map +1 -0
- package/dist/lib/verifier/index.js +22 -0
- package/dist/lib/verifier/index.js.map +1 -0
- package/dist/registry/mcpRegistry.d.ts +12 -0
- package/dist/registry/mcpRegistry.d.ts.map +1 -0
- package/dist/registry/mcpRegistry.js +114 -0
- package/dist/registry/mcpRegistry.js.map +1 -0
- package/dist/types/index.d.ts +180 -0
- package/dist/types/index.d.ts.map +1 -0
- package/dist/types/index.js +21 -0
- package/dist/types/index.js.map +1 -0
- package/dist/types/rules.d.ts +51 -0
- package/dist/types/rules.d.ts.map +1 -0
- package/dist/types/rules.js +2 -0
- package/dist/types/rules.js.map +1 -0
- package/dist/utils/fs.d.ts +12 -0
- package/dist/utils/fs.d.ts.map +1 -0
- package/dist/utils/fs.js +91 -0
- package/dist/utils/fs.js.map +1 -0
- package/dist/utils/logger.d.ts +14 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +36 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/paths.d.ts +77 -0
- package/dist/utils/paths.d.ts.map +1 -0
- package/dist/utils/paths.js +140 -0
- package/dist/utils/paths.js.map +1 -0
- package/package.json +30 -6
- package/dist/agentinit-1.4.0.tgz +0 -0
|
@@ -0,0 +1,416 @@
|
|
|
1
|
+
import { Client } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
|
+
import { StdioClientTransport } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
3
|
+
import { StreamableHTTPClientTransport } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
|
+
import { SSEClientTransport } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
5
|
+
import { countTokens } from 'contextcalc';
|
|
6
|
+
import { green, yellow, red } from 'kleur/colors';
|
|
7
|
+
import { MCPServerType } from '../types/index.js';
|
|
8
|
+
import { DEFAULT_CONNECTION_TIMEOUT_MS, MCP_VERIFIER_CONFIG, TimeoutError, TOKEN_COUNT_THRESHOLDS } from '../constants/index.js';
|
|
9
|
+
export class MCPVerificationError extends Error {
|
|
10
|
+
serverName;
|
|
11
|
+
constructor(message, serverName) {
|
|
12
|
+
super(message);
|
|
13
|
+
this.serverName = serverName;
|
|
14
|
+
this.name = 'MCPVerificationError';
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
export class MCPVerifier {
|
|
18
|
+
defaultTimeout;
|
|
19
|
+
constructor(defaultTimeout = DEFAULT_CONNECTION_TIMEOUT_MS) {
|
|
20
|
+
this.defaultTimeout = defaultTimeout;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Color utility function for token display
|
|
24
|
+
*/
|
|
25
|
+
colorizeTokenCount(tokenCount) {
|
|
26
|
+
if (tokenCount <= TOKEN_COUNT_THRESHOLDS.LOW)
|
|
27
|
+
return green(tokenCount.toString());
|
|
28
|
+
if (tokenCount <= TOKEN_COUNT_THRESHOLDS.MEDIUM)
|
|
29
|
+
return yellow(tokenCount.toString());
|
|
30
|
+
return red(tokenCount.toString());
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Calculate token counts for MCP tools based on how they appear in Claude's context
|
|
34
|
+
*/
|
|
35
|
+
calculateToolTokens(tools, serverName) {
|
|
36
|
+
const toolTokenCounts = new Map();
|
|
37
|
+
let totalToolTokens = 0;
|
|
38
|
+
for (const tool of tools) {
|
|
39
|
+
try {
|
|
40
|
+
// Create a complete tool representation as it would appear in Claude's context
|
|
41
|
+
// This matches the JSON schema format that Claude receives for function calling
|
|
42
|
+
const rawSchema = tool.inputSchema && typeof tool.inputSchema === "object"
|
|
43
|
+
? tool.inputSchema
|
|
44
|
+
: undefined;
|
|
45
|
+
const schemaType = rawSchema?.type;
|
|
46
|
+
const parameters = {
|
|
47
|
+
$schema: "http://json-schema.org/draft-07/schema#",
|
|
48
|
+
...(rawSchema ?? {}),
|
|
49
|
+
};
|
|
50
|
+
const hasObjectHints = rawSchema !== undefined &&
|
|
51
|
+
["properties", "required", "additionalProperties", "patternProperties"].some((key) => key in rawSchema);
|
|
52
|
+
const isObjectSchema = rawSchema === undefined ||
|
|
53
|
+
schemaType === "object" ||
|
|
54
|
+
(Array.isArray(schemaType) && schemaType.includes("object")) ||
|
|
55
|
+
hasObjectHints;
|
|
56
|
+
// Only apply object-specific defaults when the schema is actually an object type
|
|
57
|
+
if (isObjectSchema) {
|
|
58
|
+
if (!("type" in parameters))
|
|
59
|
+
parameters.type = "object";
|
|
60
|
+
if (!("properties" in parameters))
|
|
61
|
+
parameters.properties = {};
|
|
62
|
+
if (!("required" in parameters))
|
|
63
|
+
parameters.required = [];
|
|
64
|
+
if (!("additionalProperties" in parameters))
|
|
65
|
+
parameters.additionalProperties = false;
|
|
66
|
+
}
|
|
67
|
+
// Create the prefixed tool name as it appears in Claude's context
|
|
68
|
+
const prefixedToolName = `mcp__${serverName}__${tool.name}`;
|
|
69
|
+
const toolForCounting = {
|
|
70
|
+
name: prefixedToolName,
|
|
71
|
+
...(tool.description !== undefined ? { description: tool.description } : {}),
|
|
72
|
+
parameters,
|
|
73
|
+
};
|
|
74
|
+
// Create the function wrapper format that Claude actually receives
|
|
75
|
+
// This includes the full function definition with formatted JSON schema
|
|
76
|
+
const functionDefinition = JSON.stringify(toolForCounting);
|
|
77
|
+
const claudeToolRepresentation = `<function>${functionDefinition}</function>`;
|
|
78
|
+
// Count tokens for the complete tool representation including wrapper
|
|
79
|
+
// TODO: This 5x multiplier is a temporary fix to better match Claude Code's context calculation
|
|
80
|
+
// Needs further investigation for accurate token counting
|
|
81
|
+
const tokenCount = countTokens(claudeToolRepresentation) * 5;
|
|
82
|
+
toolTokenCounts.set(tool.name, tokenCount);
|
|
83
|
+
totalToolTokens += tokenCount;
|
|
84
|
+
}
|
|
85
|
+
catch (error) {
|
|
86
|
+
// If token counting fails for a specific tool, default to 0
|
|
87
|
+
console.warn(`Failed to count tokens for tool ${tool.name}:`, error);
|
|
88
|
+
toolTokenCounts.set(tool.name, 0);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
return { toolTokenCounts, totalToolTokens };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Verify a single MCP server
|
|
95
|
+
*/
|
|
96
|
+
async verifyServer(server, timeout) {
|
|
97
|
+
const startTime = Date.now();
|
|
98
|
+
const timeoutMs = timeout || this.defaultTimeout;
|
|
99
|
+
const abortController = new AbortController();
|
|
100
|
+
let client = null;
|
|
101
|
+
let transport = null;
|
|
102
|
+
try {
|
|
103
|
+
// Create the appropriate transport based on server type
|
|
104
|
+
transport = await this.createTransport(server);
|
|
105
|
+
// Create the MCP client
|
|
106
|
+
client = new Client({
|
|
107
|
+
name: MCP_VERIFIER_CONFIG.name,
|
|
108
|
+
version: MCP_VERIFIER_CONFIG.version
|
|
109
|
+
});
|
|
110
|
+
// Set up timeout promise that properly cancels resources
|
|
111
|
+
const timeoutPromise = new Promise((_, reject) => {
|
|
112
|
+
const timeoutId = setTimeout(async () => {
|
|
113
|
+
abortController.abort();
|
|
114
|
+
// Cleanup resources on timeout
|
|
115
|
+
try {
|
|
116
|
+
if (client) {
|
|
117
|
+
await client.close();
|
|
118
|
+
}
|
|
119
|
+
if (transport && typeof transport.close === 'function') {
|
|
120
|
+
await transport.close();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
catch (cleanupError) {
|
|
124
|
+
// Ignore cleanup errors
|
|
125
|
+
}
|
|
126
|
+
reject(new TimeoutError(`Connection timeout after ${timeoutMs}ms`));
|
|
127
|
+
}, timeoutMs);
|
|
128
|
+
// Clear timeout if operation completes before timeout
|
|
129
|
+
abortController.signal.addEventListener('abort', () => {
|
|
130
|
+
clearTimeout(timeoutId);
|
|
131
|
+
});
|
|
132
|
+
});
|
|
133
|
+
// Connect to the server with timeout
|
|
134
|
+
const connectPromise = this.connectAndVerify(client, transport, server, abortController.signal);
|
|
135
|
+
const capabilities = await Promise.race([connectPromise, timeoutPromise]);
|
|
136
|
+
const connectionTime = Date.now() - startTime;
|
|
137
|
+
return {
|
|
138
|
+
server,
|
|
139
|
+
status: 'success',
|
|
140
|
+
capabilities,
|
|
141
|
+
connectionTime
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
catch (error) {
|
|
145
|
+
const connectionTime = Date.now() - startTime;
|
|
146
|
+
const errorMessage = error instanceof Error ? error.message : 'Unknown error';
|
|
147
|
+
const isTimeout = error instanceof TimeoutError || connectionTime >= timeoutMs;
|
|
148
|
+
return {
|
|
149
|
+
server,
|
|
150
|
+
status: isTimeout ? 'timeout' : 'error',
|
|
151
|
+
error: errorMessage,
|
|
152
|
+
connectionTime
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
finally {
|
|
156
|
+
// Ensure cleanup happens in all cases
|
|
157
|
+
abortController.abort();
|
|
158
|
+
try {
|
|
159
|
+
if (client) {
|
|
160
|
+
await client.close();
|
|
161
|
+
}
|
|
162
|
+
if (transport && typeof transport.close === 'function') {
|
|
163
|
+
await transport.close();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
catch (cleanupError) {
|
|
167
|
+
// Ignore cleanup errors
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Verify multiple MCP servers
|
|
173
|
+
*/
|
|
174
|
+
async verifyServers(servers, timeout) {
|
|
175
|
+
const results = await Promise.allSettled(servers.map(server => this.verifyServer(server, timeout)));
|
|
176
|
+
return results.map((result, index) => {
|
|
177
|
+
if (result.status === 'fulfilled') {
|
|
178
|
+
return result.value;
|
|
179
|
+
}
|
|
180
|
+
else {
|
|
181
|
+
const server = servers[index];
|
|
182
|
+
if (!server) {
|
|
183
|
+
throw new Error(`Server at index ${index} is undefined`);
|
|
184
|
+
}
|
|
185
|
+
return {
|
|
186
|
+
server,
|
|
187
|
+
status: 'error',
|
|
188
|
+
error: result.reason instanceof Error ? result.reason.message : 'Unknown error'
|
|
189
|
+
};
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Create the appropriate transport for the server type
|
|
195
|
+
*/
|
|
196
|
+
async createTransport(server) {
|
|
197
|
+
switch (server.type) {
|
|
198
|
+
case MCPServerType.STDIO: {
|
|
199
|
+
if (!server.command) {
|
|
200
|
+
throw new MCPVerificationError('STDIO server missing command', server.name);
|
|
201
|
+
}
|
|
202
|
+
const isDebugMode = process.env.DEBUG === '1';
|
|
203
|
+
// Filter out undefined values from process.env
|
|
204
|
+
const cleanEnv = {};
|
|
205
|
+
for (const [key, value] of Object.entries(process.env)) {
|
|
206
|
+
if (value !== undefined) {
|
|
207
|
+
cleanEnv[key] = value;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
return new StdioClientTransport({
|
|
211
|
+
command: server.command,
|
|
212
|
+
args: server.args || [],
|
|
213
|
+
env: server.env ? { ...cleanEnv, ...server.env } : cleanEnv,
|
|
214
|
+
stderr: isDebugMode ? 'inherit' : 'ignore'
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
case MCPServerType.HTTP:
|
|
218
|
+
if (!server.url) {
|
|
219
|
+
throw new MCPVerificationError('HTTP server missing URL', server.name);
|
|
220
|
+
}
|
|
221
|
+
return new StreamableHTTPClientTransport(new URL(server.url));
|
|
222
|
+
case MCPServerType.SSE:
|
|
223
|
+
if (!server.url) {
|
|
224
|
+
throw new MCPVerificationError('SSE server missing URL', server.name);
|
|
225
|
+
}
|
|
226
|
+
return new SSEClientTransport(new URL(server.url));
|
|
227
|
+
default:
|
|
228
|
+
throw new MCPVerificationError(`Unsupported server type: ${server.type}`, server.name);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
/**
|
|
232
|
+
* Connect to the server and retrieve capabilities
|
|
233
|
+
*/
|
|
234
|
+
async connectAndVerify(client, transport, server, abortSignal) {
|
|
235
|
+
try {
|
|
236
|
+
// Check if operation was aborted before starting
|
|
237
|
+
if (abortSignal?.aborted) {
|
|
238
|
+
throw new Error('Operation aborted');
|
|
239
|
+
}
|
|
240
|
+
// Connect to the server
|
|
241
|
+
await client.connect(transport);
|
|
242
|
+
// Get server info
|
|
243
|
+
const serverInfo = {
|
|
244
|
+
name: server.name,
|
|
245
|
+
version: "unknown",
|
|
246
|
+
protocolVersion: "unknown"
|
|
247
|
+
};
|
|
248
|
+
// Check for abort before continuing
|
|
249
|
+
if (abortSignal?.aborted) {
|
|
250
|
+
throw new Error('Operation aborted');
|
|
251
|
+
}
|
|
252
|
+
// List tools
|
|
253
|
+
const tools = [];
|
|
254
|
+
try {
|
|
255
|
+
const toolsResponse = await client.listTools();
|
|
256
|
+
tools.push(...toolsResponse.tools.map(tool => {
|
|
257
|
+
const mcpTool = { name: tool.name };
|
|
258
|
+
if (tool.description !== undefined)
|
|
259
|
+
mcpTool.description = tool.description;
|
|
260
|
+
if (tool.inputSchema !== undefined)
|
|
261
|
+
mcpTool.inputSchema = tool.inputSchema;
|
|
262
|
+
return mcpTool;
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
catch (error) {
|
|
266
|
+
// Tools might not be supported, continue
|
|
267
|
+
}
|
|
268
|
+
// Check for abort before continuing
|
|
269
|
+
if (abortSignal?.aborted) {
|
|
270
|
+
throw new Error('Operation aborted');
|
|
271
|
+
}
|
|
272
|
+
// List resources
|
|
273
|
+
const resources = [];
|
|
274
|
+
try {
|
|
275
|
+
const resourcesResponse = await client.listResources();
|
|
276
|
+
resources.push(...resourcesResponse.resources.map(resource => {
|
|
277
|
+
const mcpResource = { uri: resource.uri };
|
|
278
|
+
if (resource.name !== undefined)
|
|
279
|
+
mcpResource.name = resource.name;
|
|
280
|
+
if (resource.description !== undefined)
|
|
281
|
+
mcpResource.description = resource.description;
|
|
282
|
+
if (resource.mimeType !== undefined)
|
|
283
|
+
mcpResource.mimeType = resource.mimeType;
|
|
284
|
+
return mcpResource;
|
|
285
|
+
}));
|
|
286
|
+
}
|
|
287
|
+
catch (error) {
|
|
288
|
+
// Resources might not be supported, continue
|
|
289
|
+
}
|
|
290
|
+
// Check for abort before continuing
|
|
291
|
+
if (abortSignal?.aborted) {
|
|
292
|
+
throw new Error('Operation aborted');
|
|
293
|
+
}
|
|
294
|
+
// List prompts
|
|
295
|
+
const prompts = [];
|
|
296
|
+
try {
|
|
297
|
+
const promptsResponse = await client.listPrompts();
|
|
298
|
+
prompts.push(...promptsResponse.prompts.map(prompt => {
|
|
299
|
+
const mcpPrompt = { name: prompt.name };
|
|
300
|
+
if (prompt.description !== undefined)
|
|
301
|
+
mcpPrompt.description = prompt.description;
|
|
302
|
+
if (prompt.arguments !== undefined) {
|
|
303
|
+
// Filter and transform arguments to match our type
|
|
304
|
+
mcpPrompt.arguments = prompt.arguments.map(arg => {
|
|
305
|
+
const mcpArg = { name: arg.name };
|
|
306
|
+
if (arg.description !== undefined)
|
|
307
|
+
mcpArg.description = arg.description;
|
|
308
|
+
if (arg.required !== undefined)
|
|
309
|
+
mcpArg.required = arg.required;
|
|
310
|
+
return mcpArg;
|
|
311
|
+
});
|
|
312
|
+
}
|
|
313
|
+
return mcpPrompt;
|
|
314
|
+
}));
|
|
315
|
+
}
|
|
316
|
+
catch (error) {
|
|
317
|
+
// Prompts might not be supported, continue
|
|
318
|
+
}
|
|
319
|
+
// Calculate token counts for tools
|
|
320
|
+
const { toolTokenCounts, totalToolTokens } = this.calculateToolTokens(tools, server.name);
|
|
321
|
+
return {
|
|
322
|
+
tools,
|
|
323
|
+
resources,
|
|
324
|
+
prompts,
|
|
325
|
+
serverInfo,
|
|
326
|
+
toolTokenCounts,
|
|
327
|
+
totalToolTokens
|
|
328
|
+
};
|
|
329
|
+
}
|
|
330
|
+
finally {
|
|
331
|
+
// Clean up the connection
|
|
332
|
+
try {
|
|
333
|
+
await client.close();
|
|
334
|
+
}
|
|
335
|
+
catch (error) {
|
|
336
|
+
// Ignore cleanup errors
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Format verification results for display
|
|
342
|
+
*/
|
|
343
|
+
formatResults(results) {
|
|
344
|
+
const isDebugMode = process.env.DEBUG === '1';
|
|
345
|
+
const output = [];
|
|
346
|
+
for (const result of results) {
|
|
347
|
+
const { server, status, capabilities, error, connectionTime } = result;
|
|
348
|
+
if (status === 'success' && capabilities) {
|
|
349
|
+
output.push(`✅ MCP Server: ${server.name} (${server.type.toUpperCase()})`);
|
|
350
|
+
output.push(` Status: Connected successfully (${connectionTime}ms)`);
|
|
351
|
+
if (capabilities.serverInfo) {
|
|
352
|
+
output.push(` Version: ${capabilities.serverInfo.version}`);
|
|
353
|
+
}
|
|
354
|
+
if (capabilities.tools.length > 0) {
|
|
355
|
+
const totalTokensDisplay = capabilities.totalToolTokens
|
|
356
|
+
? ` - ${this.colorizeTokenCount(capabilities.totalToolTokens)} tokens`
|
|
357
|
+
: '';
|
|
358
|
+
output.push(` \n Tools (${capabilities.tools.length})${totalTokensDisplay}:`);
|
|
359
|
+
capabilities.tools.forEach(tool => {
|
|
360
|
+
const tokenCount = capabilities.toolTokenCounts?.get(tool.name) || 0;
|
|
361
|
+
const tokenDisplay = tokenCount > 0 ? ` (${tokenCount} tokens)` : '';
|
|
362
|
+
output.push(` • ${tool.name}${tokenDisplay}${tool.description ? ` - ${tool.description}` : ''}`);
|
|
363
|
+
});
|
|
364
|
+
}
|
|
365
|
+
// Only show resources and prompts in debug mode
|
|
366
|
+
if (isDebugMode && capabilities.resources.length > 0) {
|
|
367
|
+
output.push(` \n Resources (${capabilities.resources.length}):`);
|
|
368
|
+
capabilities.resources.forEach(resource => {
|
|
369
|
+
const resourceName = resource.name || resource.uri.split('/').pop() || resource.uri;
|
|
370
|
+
output.push(` • ${resourceName}${resource.description ? ` - ${resource.description}` : ''}`);
|
|
371
|
+
});
|
|
372
|
+
}
|
|
373
|
+
if (isDebugMode && capabilities.prompts.length > 0) {
|
|
374
|
+
output.push(` \n Prompts (${capabilities.prompts.length}):`);
|
|
375
|
+
capabilities.prompts.forEach(prompt => {
|
|
376
|
+
output.push(` • ${prompt.name}${prompt.description ? ` - ${prompt.description}` : ''}`);
|
|
377
|
+
});
|
|
378
|
+
}
|
|
379
|
+
if (capabilities.tools.length === 0 && capabilities.resources.length === 0 && capabilities.prompts.length === 0) {
|
|
380
|
+
output.push(` ⚠️ No tools, resources, or prompts available`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
else {
|
|
384
|
+
const statusIcon = status === 'timeout' ? '⏱️' : '❌';
|
|
385
|
+
output.push(`${statusIcon} MCP Server: ${server.name} (${server.type.toUpperCase()})`);
|
|
386
|
+
output.push(` Status: ${status === 'timeout' ? 'Connection timeout' : 'Failed'} (${connectionTime || 0}ms)`);
|
|
387
|
+
if (error) {
|
|
388
|
+
output.push(` Error: ${error}`);
|
|
389
|
+
}
|
|
390
|
+
// Show connection details for debugging
|
|
391
|
+
if (server.type === 'stdio' && server.command) {
|
|
392
|
+
output.push(` Command: ${server.command} ${server.args?.join(' ') || ''}`);
|
|
393
|
+
}
|
|
394
|
+
else if (server.url) {
|
|
395
|
+
// Sanitize URL to remove credentials and sensitive query parameters
|
|
396
|
+
let sanitizedUrl;
|
|
397
|
+
try {
|
|
398
|
+
const parsedUrl = new URL(server.url);
|
|
399
|
+
parsedUrl.username = '';
|
|
400
|
+
parsedUrl.password = '';
|
|
401
|
+
parsedUrl.search = ''; // Remove query parameters
|
|
402
|
+
sanitizedUrl = parsedUrl.toString();
|
|
403
|
+
}
|
|
404
|
+
catch (error) {
|
|
405
|
+
// Fallback to just host+pathname if URL parsing fails
|
|
406
|
+
sanitizedUrl = server.url.split('?')[0] || 'invalid-url';
|
|
407
|
+
}
|
|
408
|
+
output.push(` URL: ${sanitizedUrl}`);
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
output.push(''); // Empty line between servers
|
|
412
|
+
}
|
|
413
|
+
return output.join('\n');
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
//# sourceMappingURL=mcpClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpClient.js","sourceRoot":"","sources":["../../src/core/mcpClient.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,kBAAkB,EAAE,MAAM,yCAAyC,CAAC;AAC7E,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,OAAO,EAAE,6BAA6B,EAAE,mBAAmB,EAAE,YAAY,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAC;AAUjI,MAAM,OAAO,oBAAqB,SAAQ,KAAK;IACA;IAA7C,YAAY,OAAe,EAAkB,UAAkB;QAC7D,KAAK,CAAC,OAAO,CAAC,CAAC;QAD4B,eAAU,GAAV,UAAU,CAAQ;QAE7D,IAAI,CAAC,IAAI,GAAG,sBAAsB,CAAC;IACrC,CAAC;CACF;AAGD,MAAM,OAAO,WAAW;IACd,cAAc,CAAS;IAE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Ae,MAAM,CAAC,OAAO,IAAI,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,EAAE,CAAC,CAAC;gBAC/E,CAAC;qBAAM,IAAI,MAAM,CAAC,GAAG,EAAE,CAAC;oBACtB,oEAAoE;oBACpE,IAAI,YAAoB,CAAC;oBACzB,IAAI,CAAC;wBACH,MAAM,SAAS,GAAG,IAAI,GAAG,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;wBACtC,SAAS,CAAC,QAAQ,GAAG,EAAE,CAAC;wBACxB,SAAS,CAAC,QAAQ,GAAG,EAAE,CAAC;wBACxB,SAAS,CAAC,MAAM,GAAG,EAAE,CAAC,CAAC,0BAA0B;wBACjD,YAAY,GAAG,SAAS,CAAC,QAAQ,EAAE,CAAC;oBACtC,CAAC;oBAAC,OAAO,KAAK,EAAE,CAAC;wBACf,sDAAsD;wBACtD,YAAY,GAAG,MAAM,CAAC,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa,CAAC;oBAC3D,CAAC;oBACD,MAAM,CAAC,IAAI,CAAC,WAAW,YAAY,EAAE,CAAC,CAAC;gBACzC,CAAC;YACH,CAAC;YAED,MAAM,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC,CAAC,6BAA6B;QAChD,CAAC;QAED,OAAO,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC3B,CAAC;CACF"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { Agent } from '../agents/Agent.js';
|
|
2
|
+
import type { MCPServerConfig, FilteredMCPConfig } from '../types/index.js';
|
|
3
|
+
/**
|
|
4
|
+
* MCP filtering and transformation utility
|
|
5
|
+
* Handles capability-based filtering and agent-specific transformations
|
|
6
|
+
*/
|
|
7
|
+
export declare class MCPFilter {
|
|
8
|
+
/**
|
|
9
|
+
* Filter and transform MCP servers for a specific agent
|
|
10
|
+
*/
|
|
11
|
+
static filterForAgent(agent: Agent, servers: MCPServerConfig[]): FilteredMCPConfig;
|
|
12
|
+
/**
|
|
13
|
+
* Filter MCP servers based on generic capabilities
|
|
14
|
+
*/
|
|
15
|
+
static filterByCapabilities(servers: MCPServerConfig[], capabilities: {
|
|
16
|
+
stdio: boolean;
|
|
17
|
+
http: boolean;
|
|
18
|
+
sse: boolean;
|
|
19
|
+
}): MCPServerConfig[];
|
|
20
|
+
/**
|
|
21
|
+
* Get servers that would be filtered out by an agent
|
|
22
|
+
*/
|
|
23
|
+
static getFilteredOutServers(agent: Agent, servers: MCPServerConfig[]): MCPServerConfig[];
|
|
24
|
+
/**
|
|
25
|
+
* Check if a server has been modified during transformation
|
|
26
|
+
*/
|
|
27
|
+
private static hasServerChanged;
|
|
28
|
+
/**
|
|
29
|
+
* Generate a human-readable reason for the transformation
|
|
30
|
+
*/
|
|
31
|
+
private static getTransformationReason;
|
|
32
|
+
/**
|
|
33
|
+
* Validate that servers are compatible with agent capabilities
|
|
34
|
+
*/
|
|
35
|
+
static validateCompatibility(agent: Agent, servers: MCPServerConfig[]): {
|
|
36
|
+
compatible: MCPServerConfig[];
|
|
37
|
+
incompatible: MCPServerConfig[];
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* Get a summary of filtering and transformation results
|
|
41
|
+
*/
|
|
42
|
+
static getSummary(agent: Agent, servers: MCPServerConfig[]): string;
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=mcpFilter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpFilter.d.ts","sourceRoot":"","sources":["../../src/core/mcpFilter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,KAAK,EACV,eAAe,EACf,iBAAiB,EAElB,MAAM,mBAAmB,CAAC;AAE3B;;;GAGG;AACH,qBAAa,SAAS;IACpB;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,iBAAiB;IA6BlF;;OAEG;IACH,MAAM,CAAC,oBAAoB,CACzB,OAAO,EAAE,eAAe,EAAE,EAC1B,YAAY,EAAE;QAAE,KAAK,EAAE,OAAO,CAAC;QAAC,IAAI,EAAE,OAAO,CAAC;QAAC,GAAG,EAAE,OAAO,CAAA;KAAE,GAC5D,eAAe,EAAE;IAepB;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,eAAe,EAAE;IAOzF;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAW/B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,uBAAuB;IA6BtC;;OAEG;IACH,MAAM,CAAC,qBAAqB,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG;QACtE,UAAU,EAAE,eAAe,EAAE,CAAC;QAC9B,YAAY,EAAE,eAAe,EAAE,CAAC;KACjC;IAgBD;;OAEG;IACH,MAAM,CAAC,UAAU,CAAC,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,eAAe,EAAE,GAAG,MAAM;CAkBpE"}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* MCP filtering and transformation utility
|
|
3
|
+
* Handles capability-based filtering and agent-specific transformations
|
|
4
|
+
*/
|
|
5
|
+
export class MCPFilter {
|
|
6
|
+
/**
|
|
7
|
+
* Filter and transform MCP servers for a specific agent
|
|
8
|
+
*/
|
|
9
|
+
static filterForAgent(agent, servers) {
|
|
10
|
+
const transformations = [];
|
|
11
|
+
// First, let the agent transform servers (e.g., remote to stdio)
|
|
12
|
+
const transformedServers = agent.transformMCPServers(servers);
|
|
13
|
+
// Track transformations
|
|
14
|
+
for (let i = 0; i < servers.length; i++) {
|
|
15
|
+
const original = servers[i];
|
|
16
|
+
const transformed = transformedServers[i];
|
|
17
|
+
if (original && transformed && this.hasServerChanged(original, transformed)) {
|
|
18
|
+
transformations.push({
|
|
19
|
+
original,
|
|
20
|
+
transformed,
|
|
21
|
+
reason: this.getTransformationReason(agent, original, transformed)
|
|
22
|
+
});
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
// Then filter based on capabilities
|
|
26
|
+
const filteredServers = agent.filterMCPServers(transformedServers);
|
|
27
|
+
return {
|
|
28
|
+
servers: filteredServers,
|
|
29
|
+
transformations
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* Filter MCP servers based on generic capabilities
|
|
34
|
+
*/
|
|
35
|
+
static filterByCapabilities(servers, capabilities) {
|
|
36
|
+
return servers.filter(server => {
|
|
37
|
+
switch (server.type) {
|
|
38
|
+
case 'stdio':
|
|
39
|
+
return capabilities.stdio;
|
|
40
|
+
case 'http':
|
|
41
|
+
return capabilities.http;
|
|
42
|
+
case 'sse':
|
|
43
|
+
return capabilities.sse;
|
|
44
|
+
default:
|
|
45
|
+
return false;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Get servers that would be filtered out by an agent
|
|
51
|
+
*/
|
|
52
|
+
static getFilteredOutServers(agent, servers) {
|
|
53
|
+
const filtered = this.filterForAgent(agent, servers);
|
|
54
|
+
const filteredServerNames = new Set(filtered.servers.map(s => s.name));
|
|
55
|
+
return servers.filter(server => !filteredServerNames.has(server.name));
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Check if a server has been modified during transformation
|
|
59
|
+
*/
|
|
60
|
+
static hasServerChanged(original, transformed) {
|
|
61
|
+
return (original.type !== transformed.type ||
|
|
62
|
+
original.command !== transformed.command ||
|
|
63
|
+
original.url !== transformed.url ||
|
|
64
|
+
JSON.stringify(original.args) !== JSON.stringify(transformed.args) ||
|
|
65
|
+
JSON.stringify(original.env) !== JSON.stringify(transformed.env) ||
|
|
66
|
+
JSON.stringify(original.headers) !== JSON.stringify(transformed.headers));
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Generate a human-readable reason for the transformation
|
|
70
|
+
*/
|
|
71
|
+
static getTransformationReason(agent, original, transformed) {
|
|
72
|
+
if (original.type !== transformed.type) {
|
|
73
|
+
if (original.type === 'http' && transformed.type === 'stdio') {
|
|
74
|
+
return `${agent.name} only supports stdio MCPs - converted HTTP server to use mcp-remote proxy`;
|
|
75
|
+
}
|
|
76
|
+
if (original.type === 'sse' && transformed.type === 'stdio') {
|
|
77
|
+
return `${agent.name} only supports stdio MCPs - converted SSE server to use mcp-remote proxy`;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
if (original.command !== transformed.command) {
|
|
81
|
+
return `Command modified for ${agent.name} compatibility`;
|
|
82
|
+
}
|
|
83
|
+
if (JSON.stringify(original.args) !== JSON.stringify(transformed.args)) {
|
|
84
|
+
return `Arguments modified for ${agent.name} compatibility`;
|
|
85
|
+
}
|
|
86
|
+
if (JSON.stringify(original.env) !== JSON.stringify(transformed.env)) {
|
|
87
|
+
return `Environment variables modified for ${agent.name} compatibility`;
|
|
88
|
+
}
|
|
89
|
+
return `Server configuration modified for ${agent.name} compatibility`;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* Validate that servers are compatible with agent capabilities
|
|
93
|
+
*/
|
|
94
|
+
static validateCompatibility(agent, servers) {
|
|
95
|
+
const compatible = [];
|
|
96
|
+
const incompatible = [];
|
|
97
|
+
for (const server of servers) {
|
|
98
|
+
const supportsType = agent.capabilities.mcp[server.type];
|
|
99
|
+
if (supportsType) {
|
|
100
|
+
compatible.push(server);
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
incompatible.push(server);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return { compatible, incompatible };
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Get a summary of filtering and transformation results
|
|
110
|
+
*/
|
|
111
|
+
static getSummary(agent, servers) {
|
|
112
|
+
const filtered = this.filterForAgent(agent, servers);
|
|
113
|
+
const summary = [];
|
|
114
|
+
summary.push(`${agent.name} processed ${servers.length} MCP server(s):`);
|
|
115
|
+
summary.push(`• ${filtered.servers.length} servers will be applied`);
|
|
116
|
+
if (filtered.transformations.length > 0) {
|
|
117
|
+
summary.push(`• ${filtered.transformations.length} servers were transformed for compatibility`);
|
|
118
|
+
}
|
|
119
|
+
const filteredOut = servers.length - filtered.servers.length;
|
|
120
|
+
if (filteredOut > 0) {
|
|
121
|
+
summary.push(`• ${filteredOut} servers were filtered out (unsupported)`);
|
|
122
|
+
}
|
|
123
|
+
return summary.join('\n');
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
//# sourceMappingURL=mcpFilter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpFilter.js","sourceRoot":"","sources":["../../src/core/mcpFilter.ts"],"names":[],"mappings":"AAOA;;;GAGG;AACH,MAAM,OAAO,SAAS;IACpB;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,KAAY,EAAE,OAA0B;QAC5D,MAAM,eAAe,GAAwB,EAAE,CAAC;QAEhD,iEAAiE;QACjE,MAAM,kBAAkB,GAAG,KAAK,CAAC,mBAAmB,CAAC,OAAO,CAAC,CAAC;QAE9D,wBAAwB;QACxB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC,EAAE,EAAE,CAAC;YACxC,MAAM,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;YAC5B,MAAM,WAAW,GAAG,kBAAkB,CAAC,CAAC,CAAC,CAAC;YAE1C,IAAI,QAAQ,IAAI,WAAW,IAAI,IAAI,CAAC,gBAAgB,CAAC,QAAQ,EAAE,WAAW,CAAC,EAAE,CAAC;gBAC5E,eAAe,CAAC,IAAI,CAAC;oBACnB,QAAQ;oBACR,WAAW;oBACX,MAAM,EAAE,IAAI,CAAC,uBAAuB,CAAC,KAAK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C,MAAM,6CAA6C,CAAC,CAAC;QAClG,CAAC;QAED,MAAM,WAAW,GAAG,OAAO,CAAC,MAAM,GAAG,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC;QAC7D,IAAI,WAAW,GAAG,CAAC,EAAE,CAAC;YACpB,OAAO,CAAC,IAAI,CAAC,KAAK,WAAW,0CAA0C,CAAC,CAAC;QAC3E,CAAC;QAED,OAAO,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAC5B,CAAC;CACF"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { MCPCommandParsed } from '../types/index.js';
|
|
2
|
+
export declare class MCPParseError extends Error {
|
|
3
|
+
constructor(message: string);
|
|
4
|
+
}
|
|
5
|
+
export declare class MCPParser {
|
|
6
|
+
/**
|
|
7
|
+
* Parse command line arguments to extract MCP server configurations
|
|
8
|
+
*/
|
|
9
|
+
static parseArguments(args: string[]): MCPCommandParsed;
|
|
10
|
+
private static parseStdioMCP;
|
|
11
|
+
private static parseHttpMCP;
|
|
12
|
+
private static parseSSEMCP;
|
|
13
|
+
private static parseCommand;
|
|
14
|
+
private static parseArgsString;
|
|
15
|
+
private static parseEnvString;
|
|
16
|
+
/**
|
|
17
|
+
* Check if a string looks like a command (indicates old syntax usage)
|
|
18
|
+
*/
|
|
19
|
+
private static looksLikeCommand;
|
|
20
|
+
/**
|
|
21
|
+
* Check if a string looks like a URL (indicates old syntax usage)
|
|
22
|
+
*/
|
|
23
|
+
private static looksLikeUrl;
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=mcpParser.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpParser.d.ts","sourceRoot":"","sources":["../../src/core/mcpParser.ts"],"names":[],"mappings":"AAAA,OAAO,EAAkC,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAErF,qBAAa,aAAc,SAAQ,KAAK;gBAC1B,OAAO,EAAE,MAAM;CAI5B;AAED,qBAAa,SAAS;IACpB;;OAEG;IACH,MAAM,CAAC,cAAc,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,gBAAgB;IAiCvD,OAAO,CAAC,MAAM,CAAC,aAAa;IAoF5B,OAAO,CAAC,MAAM,CAAC,YAAY;IAsF3B,OAAO,CAAC,MAAM,CAAC,WAAW;IAmD1B,OAAO,CAAC,MAAM,CAAC,YAAY;IAiC3B,OAAO,CAAC,MAAM,CAAC,eAAe;IAI9B,OAAO,CAAC,MAAM,CAAC,cAAc;IAiB7B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,gBAAgB;IAU/B;;OAEG;IACH,OAAO,CAAC,MAAM,CAAC,YAAY;CAU5B"}
|