@dexto/core 1.13.5 → 1.14.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/dist/agent/DextoAgent.cjs +32 -0
- package/dist/agent/DextoAgent.d.ts +5 -1
- package/dist/agent/DextoAgent.d.ts.map +1 -1
- package/dist/agent/DextoAgent.js +32 -0
- package/dist/approval/index.d.ts +1 -1
- package/dist/approval/index.d.ts.map +1 -1
- package/dist/approval/manager.cjs +7 -0
- package/dist/approval/manager.d.ts +1 -0
- package/dist/approval/manager.d.ts.map +1 -1
- package/dist/approval/manager.js +7 -0
- package/dist/approval/types.d.ts +4 -0
- package/dist/approval/types.d.ts.map +1 -1
- package/dist/mcp/index.d.ts +1 -1
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/manager.cjs +224 -73
- package/dist/mcp/manager.d.ts +27 -3
- package/dist/mcp/manager.d.ts.map +1 -1
- package/dist/mcp/manager.js +224 -73
- package/dist/mcp/mcp-client.cjs +61 -65
- package/dist/mcp/mcp-client.d.ts +1 -1
- package/dist/mcp/mcp-client.d.ts.map +1 -1
- package/dist/mcp/mcp-client.js +61 -65
- package/dist/mcp/types.d.ts +19 -2
- package/dist/mcp/types.d.ts.map +1 -1
- package/dist/tools/approval/session-tool-policy.cjs +11 -0
- package/dist/tools/approval/session-tool-policy.d.ts +1 -0
- package/dist/tools/approval/session-tool-policy.d.ts.map +1 -1
- package/dist/tools/approval/session-tool-policy.js +11 -0
- package/dist/tools/tool-manager.cjs +14 -0
- package/dist/tools/tool-manager.d.ts +2 -0
- package/dist/tools/tool-manager.d.ts.map +1 -1
- package/dist/tools/tool-manager.js +14 -0
- package/package.json +3 -3
package/dist/mcp/manager.cjs
CHANGED
|
@@ -23,7 +23,9 @@ __export(manager_exports, {
|
|
|
23
23
|
module.exports = __toCommonJS(manager_exports);
|
|
24
24
|
var import_mcp_client = require("./mcp-client.js");
|
|
25
25
|
var import_types = require("../logger/v2/types.js");
|
|
26
|
+
var import_types2 = require("@modelcontextprotocol/sdk/types.js");
|
|
26
27
|
var import_errors = require("./errors.js");
|
|
28
|
+
var import_error_codes = require("./error-codes.js");
|
|
27
29
|
var import_events = require("../events/index.js");
|
|
28
30
|
var import_schema_fingerprint = require("../tools/schema-fingerprint.js");
|
|
29
31
|
var import_cfworker = require("@modelcontextprotocol/sdk/validation/cfworker");
|
|
@@ -32,6 +34,10 @@ function isJsonSchemaObject(value) {
|
|
|
32
34
|
}
|
|
33
35
|
class MCPManager {
|
|
34
36
|
clients = /* @__PURE__ */ new Map();
|
|
37
|
+
retiredClients = /* @__PURE__ */ new Map();
|
|
38
|
+
desiredConfigurations = /* @__PURE__ */ new Map();
|
|
39
|
+
connectingOperations = /* @__PURE__ */ new Map();
|
|
40
|
+
pendingConnectionOperations = /* @__PURE__ */ new Set();
|
|
35
41
|
connectionErrors = {};
|
|
36
42
|
configCache = /* @__PURE__ */ new Map();
|
|
37
43
|
// Store original configs for restart
|
|
@@ -126,6 +132,9 @@ class MCPManager {
|
|
|
126
132
|
if (existingServerWithSameSanitizedName && existingServerWithSameSanitizedName !== name) {
|
|
127
133
|
throw import_errors.MCPError.duplicateName(name, existingServerWithSameSanitizedName);
|
|
128
134
|
}
|
|
135
|
+
const previousClient = this.clients.get(name);
|
|
136
|
+
if (previousClient && previousClient !== client)
|
|
137
|
+
this.retiredClients.set(previousClient, name);
|
|
129
138
|
this.clients.set(name, client);
|
|
130
139
|
this.sanitizedNameToServerMap.set(sanitizedName, name);
|
|
131
140
|
this.setupClientNotifications(name, client);
|
|
@@ -281,10 +290,10 @@ class MCPManager {
|
|
|
281
290
|
this.logger.debug(
|
|
282
291
|
`\u2705 Successfully cached ${Object.keys(tools).length} tools for client: ${clientName}`
|
|
283
292
|
);
|
|
284
|
-
} catch
|
|
285
|
-
this.logger.error(
|
|
286
|
-
|
|
287
|
-
);
|
|
293
|
+
} catch {
|
|
294
|
+
this.logger.error(`\u274C Error retrieving tools for client ${clientName}`, {
|
|
295
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
296
|
+
});
|
|
288
297
|
return;
|
|
289
298
|
}
|
|
290
299
|
try {
|
|
@@ -303,8 +312,10 @@ class MCPManager {
|
|
|
303
312
|
});
|
|
304
313
|
}
|
|
305
314
|
this.logger.debug(`Cached ${prompts.length} prompts for client: ${clientName}`);
|
|
306
|
-
} catch
|
|
307
|
-
this.logger.debug(`Skipping prompts for client ${clientName}
|
|
315
|
+
} catch {
|
|
316
|
+
this.logger.debug(`Skipping prompts for client ${clientName}`, {
|
|
317
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
318
|
+
});
|
|
308
319
|
}
|
|
309
320
|
try {
|
|
310
321
|
this.removeServerResources(clientName);
|
|
@@ -318,8 +329,10 @@ class MCPManager {
|
|
|
318
329
|
});
|
|
319
330
|
});
|
|
320
331
|
this.logger.debug(`Cached resources for client: ${clientName}`);
|
|
321
|
-
} catch
|
|
322
|
-
this.logger.debug(`Skipping resources for client ${clientName}
|
|
332
|
+
} catch {
|
|
333
|
+
this.logger.debug(`Skipping resources for client ${clientName}`, {
|
|
334
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
335
|
+
});
|
|
323
336
|
}
|
|
324
337
|
}
|
|
325
338
|
/**
|
|
@@ -353,7 +366,6 @@ class MCPManager {
|
|
|
353
366
|
this.logger.debug(` - ${toolName}`);
|
|
354
367
|
}
|
|
355
368
|
});
|
|
356
|
-
this.logger.silly(`MCP tools: ${JSON.stringify(allTools, null, 2)}`);
|
|
357
369
|
return allTools;
|
|
358
370
|
}
|
|
359
371
|
/**
|
|
@@ -456,6 +468,26 @@ class MCPManager {
|
|
|
456
468
|
getToolClient(toolName) {
|
|
457
469
|
return this.toolCache.get(toolName)?.client;
|
|
458
470
|
}
|
|
471
|
+
/** Call a literal upstream identity and retain its complete MCP protocol result. */
|
|
472
|
+
async callToolDirect(request) {
|
|
473
|
+
const { connectionId, toolName } = request.identity;
|
|
474
|
+
if (this.connectingOperations.has(connectionId)) {
|
|
475
|
+
throw import_errors.MCPError.clientNotConnected("connection operation in progress");
|
|
476
|
+
}
|
|
477
|
+
const client = this.clients.get(connectionId);
|
|
478
|
+
if (!client) throw import_errors.MCPError.serverNotFound(connectionId);
|
|
479
|
+
const timeout = this.configCache.get(connectionId)?.timeout;
|
|
480
|
+
const connected = await client.getConnectedClient();
|
|
481
|
+
const result = await connected.callTool(
|
|
482
|
+
{ name: toolName, arguments: request.arguments },
|
|
483
|
+
import_types2.CallToolResultSchema,
|
|
484
|
+
{
|
|
485
|
+
...timeout !== void 0 ? { timeout } : {},
|
|
486
|
+
...request.signal !== void 0 ? { signal: request.signal } : {}
|
|
487
|
+
}
|
|
488
|
+
);
|
|
489
|
+
return import_types2.CallToolResultSchema.parse(result);
|
|
490
|
+
}
|
|
459
491
|
/**
|
|
460
492
|
* Execute a specific MCP tool with the given arguments.
|
|
461
493
|
* @param toolName Name of the MCP tool to execute (may include server prefix)
|
|
@@ -580,6 +612,63 @@ class MCPManager {
|
|
|
580
612
|
}
|
|
581
613
|
return await entry.client.readResource(entry.summary.uri);
|
|
582
614
|
}
|
|
615
|
+
/** Register desired configuration without connecting or changing legacy restart configuration. */
|
|
616
|
+
configureServer(name, config) {
|
|
617
|
+
if (name === "__proto__")
|
|
618
|
+
throw import_errors.MCPError.connectionFailed(
|
|
619
|
+
name,
|
|
620
|
+
"Server name is reserved by legacy error storage"
|
|
621
|
+
);
|
|
622
|
+
this.assertConfigurationMutable(name);
|
|
623
|
+
this.desiredConfigurations.set(name, structuredClone(config));
|
|
624
|
+
}
|
|
625
|
+
/** Forget an explicit desired registration; disconnecting alone retains it. */
|
|
626
|
+
forgetServerConfiguration(name) {
|
|
627
|
+
this.assertConfigurationMutable(name);
|
|
628
|
+
this.desiredConfigurations.delete(name);
|
|
629
|
+
}
|
|
630
|
+
/** Connect an explicitly registered, enabled configuration using the existing engine. */
|
|
631
|
+
async connectConfiguredServer(name) {
|
|
632
|
+
const config = this.desiredConfigurations.get(name);
|
|
633
|
+
if (config === void 0)
|
|
634
|
+
throw import_errors.MCPError.serverNotFound(name, "Desired configuration not found");
|
|
635
|
+
if (!config.enabled) throw import_errors.MCPError.connectionFailed(name, "Configured server is disabled");
|
|
636
|
+
this.assertConfigurationMutable(name);
|
|
637
|
+
await this.connectServer(name, structuredClone(config));
|
|
638
|
+
}
|
|
639
|
+
/** List only explicitly registered desired configurations, never raw configs or diagnostics. */
|
|
640
|
+
getConfiguredServerStatuses() {
|
|
641
|
+
return Array.from(
|
|
642
|
+
this.desiredConfigurations,
|
|
643
|
+
([name, config]) => {
|
|
644
|
+
const metadata = { name, configuredTransport: config.type };
|
|
645
|
+
if (this.connectingOperations.has(name))
|
|
646
|
+
return { ...metadata, status: "connecting" };
|
|
647
|
+
if (this.clients.has(name)) return { ...metadata, status: "connected" };
|
|
648
|
+
if (!config.enabled) return { ...metadata, status: "disabled" };
|
|
649
|
+
const error = Object.hasOwn(this.connectionErrors, name) ? this.connectionErrors[name] : void 0;
|
|
650
|
+
if (error !== void 0) {
|
|
651
|
+
const errorCode = Object.values(import_error_codes.MCPErrorCode).find((code) => code === error.code) ?? import_error_codes.MCPErrorCode.CONNECTION_FAILED;
|
|
652
|
+
return { ...metadata, status: "failed", errorCode };
|
|
653
|
+
}
|
|
654
|
+
return { ...metadata, status: "configured" };
|
|
655
|
+
}
|
|
656
|
+
);
|
|
657
|
+
}
|
|
658
|
+
assertConfigurationMutable(name) {
|
|
659
|
+
if (this.clients.has(name) || this.connectingOperations.has(name)) {
|
|
660
|
+
throw import_errors.MCPError.connectionFailed(
|
|
661
|
+
name,
|
|
662
|
+
"Server has an active connection operation or registered client"
|
|
663
|
+
);
|
|
664
|
+
}
|
|
665
|
+
}
|
|
666
|
+
finishConnectionAttempt(name) {
|
|
667
|
+
const count = this.connectingOperations.get(name);
|
|
668
|
+
if (count === void 0) throw import_errors.MCPError.protocolError("Missing MCP connection operation");
|
|
669
|
+
if (count === 1) this.connectingOperations.delete(name);
|
|
670
|
+
else this.connectingOperations.set(name, count - 1);
|
|
671
|
+
}
|
|
583
672
|
/**
|
|
584
673
|
* Initialize clients from server configurations
|
|
585
674
|
* @param serverConfigs Server configurations with individual connection modes
|
|
@@ -617,7 +706,8 @@ class MCPManager {
|
|
|
617
706
|
};
|
|
618
707
|
}
|
|
619
708
|
this.logger.debug(
|
|
620
|
-
`Handled connection error for '${name}' during initialization
|
|
709
|
+
`Handled connection error for '${name}' during initialization`,
|
|
710
|
+
{ code: import_error_codes.MCPErrorCode.CONNECTION_FAILED }
|
|
621
711
|
);
|
|
622
712
|
});
|
|
623
713
|
connectionPromises.push(connectPromise);
|
|
@@ -640,13 +730,25 @@ class MCPManager {
|
|
|
640
730
|
* @returns Promise resolving when the connection attempt is complete.
|
|
641
731
|
* @throws Error if the connection fails.
|
|
642
732
|
*/
|
|
643
|
-
|
|
733
|
+
connectServer(name, config) {
|
|
734
|
+
return this.trackConnectionOperation(this.connectServerAndCache(name, config));
|
|
735
|
+
}
|
|
736
|
+
async trackConnectionOperation(operation) {
|
|
737
|
+
this.pendingConnectionOperations.add(operation);
|
|
738
|
+
try {
|
|
739
|
+
await operation;
|
|
740
|
+
} finally {
|
|
741
|
+
this.pendingConnectionOperations.delete(operation);
|
|
742
|
+
}
|
|
743
|
+
}
|
|
744
|
+
async connectServerAndCache(name, config) {
|
|
644
745
|
if (this.clients.has(name)) {
|
|
645
746
|
this.logger.warn(`Client '${name}' is already connected or registered.`);
|
|
646
747
|
return;
|
|
647
748
|
}
|
|
648
749
|
const client = new import_mcp_client.DextoMcpClient(this.logger);
|
|
649
750
|
client.setAuthProviderFactory(this.authProviderFactory);
|
|
751
|
+
this.connectingOperations.set(name, (this.connectingOperations.get(name) ?? 0) + 1);
|
|
650
752
|
try {
|
|
651
753
|
this.logger.info(`Attempting to connect to new server '${name}'...`);
|
|
652
754
|
await client.connect(config, name);
|
|
@@ -664,9 +766,24 @@ class MCPManager {
|
|
|
664
766
|
message: errorMsg,
|
|
665
767
|
...errorCode ? { code: errorCode } : {}
|
|
666
768
|
};
|
|
667
|
-
this.logger.error(`Failed to connect to new server '${name}'
|
|
668
|
-
|
|
769
|
+
this.logger.error(`Failed to connect to new server '${name}'`, {
|
|
770
|
+
code: import_error_codes.MCPErrorCode.CONNECTION_FAILED
|
|
771
|
+
});
|
|
772
|
+
await this.discardFailedClient(name, client);
|
|
669
773
|
throw import_errors.MCPError.connectionFailed(name, errorMsg);
|
|
774
|
+
} finally {
|
|
775
|
+
this.finishConnectionAttempt(name);
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
async discardFailedClient(name, client) {
|
|
779
|
+
if (this.clients.get(name) === client) {
|
|
780
|
+
this.clearClientCache(name);
|
|
781
|
+
this.clients.delete(name);
|
|
782
|
+
}
|
|
783
|
+
try {
|
|
784
|
+
await client.disconnect();
|
|
785
|
+
} catch {
|
|
786
|
+
this.logger.warn(`Failed to disconnect rejected MCP client '${name}'`);
|
|
670
787
|
}
|
|
671
788
|
}
|
|
672
789
|
/**
|
|
@@ -725,10 +842,10 @@ class MCPManager {
|
|
|
725
842
|
try {
|
|
726
843
|
await client.disconnect();
|
|
727
844
|
this.logger.info(`Successfully disconnected client: ${name}`);
|
|
728
|
-
} catch
|
|
729
|
-
this.logger.error(
|
|
730
|
-
|
|
731
|
-
);
|
|
845
|
+
} catch {
|
|
846
|
+
this.logger.error(`Error disconnecting client '${name}'`, {
|
|
847
|
+
code: import_error_codes.MCPErrorCode.DISCONNECTION_FAILED
|
|
848
|
+
});
|
|
732
849
|
}
|
|
733
850
|
this.clearClientCache(name);
|
|
734
851
|
this.clients.delete(name);
|
|
@@ -745,7 +862,10 @@ class MCPManager {
|
|
|
745
862
|
* @param name The name of the server to restart.
|
|
746
863
|
* @throws Error if server doesn't exist or config is not cached.
|
|
747
864
|
*/
|
|
748
|
-
|
|
865
|
+
restartServer(name) {
|
|
866
|
+
return this.trackConnectionOperation(this.restartServerAndCache(name));
|
|
867
|
+
}
|
|
868
|
+
async restartServerAndCache(name) {
|
|
749
869
|
const config = this.configCache.get(name);
|
|
750
870
|
if (!config) {
|
|
751
871
|
throw import_errors.MCPError.serverNotFound(
|
|
@@ -753,61 +873,80 @@ class MCPManager {
|
|
|
753
873
|
"Server config not found - cannot restart dynamically added servers without stored config"
|
|
754
874
|
);
|
|
755
875
|
}
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
876
|
+
this.connectingOperations.set(name, (this.connectingOperations.get(name) ?? 0) + 1);
|
|
877
|
+
try {
|
|
878
|
+
const client = this.clients.get(name);
|
|
879
|
+
this.logger.info(`Restarting MCP server '${name}'...`);
|
|
880
|
+
if (client) {
|
|
881
|
+
try {
|
|
882
|
+
await client.disconnect();
|
|
883
|
+
this.logger.info(`Disconnected server '${name}' for restart`);
|
|
884
|
+
} catch {
|
|
885
|
+
this.logger.warn(
|
|
886
|
+
`Error disconnecting server '${name}' during restart (continuing)`,
|
|
887
|
+
{ code: import_error_codes.MCPErrorCode.DISCONNECTION_FAILED }
|
|
888
|
+
);
|
|
889
|
+
}
|
|
890
|
+
} else {
|
|
891
|
+
this.logger.info(
|
|
892
|
+
`No active client found for '${name}' during restart; attempting fresh connection`
|
|
765
893
|
);
|
|
766
894
|
}
|
|
767
|
-
|
|
768
|
-
this.
|
|
769
|
-
|
|
770
|
-
);
|
|
771
|
-
}
|
|
772
|
-
this.clearClientCache(name);
|
|
773
|
-
this.clients.delete(name);
|
|
774
|
-
delete this.connectionErrors[name];
|
|
775
|
-
try {
|
|
895
|
+
this.clearClientCache(name);
|
|
896
|
+
this.clients.delete(name);
|
|
897
|
+
delete this.connectionErrors[name];
|
|
776
898
|
const newClient = new import_mcp_client.DextoMcpClient(this.logger);
|
|
777
899
|
newClient.setAuthProviderFactory(this.authProviderFactory);
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
900
|
+
try {
|
|
901
|
+
await newClient.connect(config, name);
|
|
902
|
+
if (this.approvalManager) {
|
|
903
|
+
newClient.setApprovalManager(this.approvalManager);
|
|
904
|
+
}
|
|
905
|
+
this.registerClient(name, newClient);
|
|
906
|
+
await this.updateClientCache(name, newClient);
|
|
907
|
+
this.logger.info(`Successfully restarted server '${name}'`);
|
|
908
|
+
this.eventBus.emit("mcp:server-restarted", { serverName: name });
|
|
909
|
+
} catch (error) {
|
|
910
|
+
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
911
|
+
const errorCode = error && typeof error === "object" && "code" in error ? String(error.code) : void 0;
|
|
912
|
+
this.connectionErrors[name] = {
|
|
913
|
+
message: errorMsg,
|
|
914
|
+
...errorCode ? { code: errorCode } : {}
|
|
915
|
+
};
|
|
916
|
+
this.logger.error(`Failed to restart server '${name}'`, {
|
|
917
|
+
code: import_error_codes.MCPErrorCode.CONNECTION_FAILED
|
|
918
|
+
});
|
|
919
|
+
await this.discardFailedClient(name, newClient);
|
|
920
|
+
throw import_errors.MCPError.connectionFailed(name, errorMsg);
|
|
781
921
|
}
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
this.logger.info(`Successfully restarted server '${name}'`);
|
|
785
|
-
this.eventBus.emit("mcp:server-restarted", { serverName: name });
|
|
786
|
-
} catch (error) {
|
|
787
|
-
const errorMsg = error instanceof Error ? error.message : String(error);
|
|
788
|
-
const errorCode = error && typeof error === "object" && "code" in error ? String(error.code) : void 0;
|
|
789
|
-
this.connectionErrors[name] = {
|
|
790
|
-
message: errorMsg,
|
|
791
|
-
...errorCode ? { code: errorCode } : {}
|
|
792
|
-
};
|
|
793
|
-
this.logger.error(`Failed to restart server '${name}': ${errorMsg}`);
|
|
794
|
-
throw import_errors.MCPError.connectionFailed(name, errorMsg);
|
|
922
|
+
} finally {
|
|
923
|
+
this.finishConnectionAttempt(name);
|
|
795
924
|
}
|
|
796
925
|
}
|
|
797
926
|
/**
|
|
798
|
-
*
|
|
927
|
+
* Drain already-started connection/restart operations, including discovery, then
|
|
928
|
+
* disconnect registered clients and clear caches. Desired registrations remain reusable.
|
|
929
|
+
* Callers must stop starting new connection/restart operations before teardown.
|
|
930
|
+
* Draining waits for existing protocol/authentication completion; it does not cancel
|
|
931
|
+
* startup or introduce an additional deadline.
|
|
799
932
|
*/
|
|
800
933
|
async disconnectAll() {
|
|
934
|
+
await Promise.allSettled([...this.pendingConnectionOperations]);
|
|
801
935
|
const disconnectPromises = [];
|
|
802
|
-
|
|
936
|
+
const ownedClients = new Map(this.retiredClients);
|
|
937
|
+
for (const [name, client] of this.clients) ownedClients.set(client, name);
|
|
938
|
+
for (const [client, name] of ownedClients) {
|
|
803
939
|
disconnectPromises.push(
|
|
804
940
|
client.disconnect().then(() => this.logger.info(`Disconnected client: ${name}`)).catch(
|
|
805
|
-
(
|
|
941
|
+
() => this.logger.error(`Failed to disconnect client '${name}'`, {
|
|
942
|
+
code: import_error_codes.MCPErrorCode.DISCONNECTION_FAILED
|
|
943
|
+
})
|
|
806
944
|
)
|
|
807
945
|
);
|
|
808
946
|
}
|
|
809
947
|
await Promise.all(disconnectPromises);
|
|
810
948
|
this.clients.clear();
|
|
949
|
+
this.retiredClients.clear();
|
|
811
950
|
this.connectionErrors = {};
|
|
812
951
|
this.configCache.clear();
|
|
813
952
|
this.toolCache.clear();
|
|
@@ -824,9 +963,7 @@ class MCPManager {
|
|
|
824
963
|
setupClientNotifications(clientName, client) {
|
|
825
964
|
try {
|
|
826
965
|
client.on("resourceUpdated", async (params) => {
|
|
827
|
-
this.logger.debug(
|
|
828
|
-
`Received resource update notification from ${clientName}: ${params.uri}`
|
|
829
|
-
);
|
|
966
|
+
this.logger.debug(`Received resource update notification from ${clientName}`);
|
|
830
967
|
await this.handleResourceUpdated(clientName, params);
|
|
831
968
|
});
|
|
832
969
|
client.on("promptsListChanged", async () => {
|
|
@@ -838,8 +975,10 @@ class MCPManager {
|
|
|
838
975
|
await this.handleToolsListChanged(clientName, client);
|
|
839
976
|
});
|
|
840
977
|
this.logger.debug(`Set up notification listeners for client: ${clientName}`);
|
|
841
|
-
} catch
|
|
842
|
-
this.logger.warn(`Failed to set up notification listeners for ${clientName}
|
|
978
|
+
} catch {
|
|
979
|
+
this.logger.warn(`Failed to set up notification listeners for ${clientName}`, {
|
|
980
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
981
|
+
});
|
|
843
982
|
}
|
|
844
983
|
}
|
|
845
984
|
/**
|
|
@@ -859,18 +998,22 @@ class MCPManager {
|
|
|
859
998
|
client,
|
|
860
999
|
summary: updatedResource
|
|
861
1000
|
});
|
|
862
|
-
this.logger.debug(`Updated resource cache for: ${
|
|
1001
|
+
this.logger.debug(`Updated resource cache for server: ${serverName}`);
|
|
863
1002
|
}
|
|
864
|
-
} catch
|
|
865
|
-
this.logger.warn(`Failed to refresh resource ${
|
|
1003
|
+
} catch {
|
|
1004
|
+
this.logger.warn(`Failed to refresh resource for server ${serverName}`, {
|
|
1005
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
1006
|
+
});
|
|
866
1007
|
}
|
|
867
1008
|
}
|
|
868
1009
|
this.eventBus.emit("mcp:resource-updated", {
|
|
869
1010
|
serverName,
|
|
870
1011
|
resourceUri: params.uri
|
|
871
1012
|
});
|
|
872
|
-
} catch
|
|
873
|
-
this.logger.error(
|
|
1013
|
+
} catch {
|
|
1014
|
+
this.logger.error("Error handling resource update", {
|
|
1015
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
1016
|
+
});
|
|
874
1017
|
}
|
|
875
1018
|
}
|
|
876
1019
|
/**
|
|
@@ -905,11 +1048,15 @@ class MCPManager {
|
|
|
905
1048
|
serverName,
|
|
906
1049
|
prompts: promptNames
|
|
907
1050
|
});
|
|
908
|
-
} catch
|
|
909
|
-
this.logger.warn(`Failed to refresh prompts for ${serverName}
|
|
1051
|
+
} catch {
|
|
1052
|
+
this.logger.warn(`Failed to refresh prompts for ${serverName}`, {
|
|
1053
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
1054
|
+
});
|
|
910
1055
|
}
|
|
911
|
-
} catch
|
|
912
|
-
this.logger.error(
|
|
1056
|
+
} catch {
|
|
1057
|
+
this.logger.error("Error handling prompts list change", {
|
|
1058
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
1059
|
+
});
|
|
913
1060
|
}
|
|
914
1061
|
}
|
|
915
1062
|
/**
|
|
@@ -1007,11 +1154,15 @@ class MCPManager {
|
|
|
1007
1154
|
serverName,
|
|
1008
1155
|
tools: toolNames
|
|
1009
1156
|
});
|
|
1010
|
-
} catch
|
|
1011
|
-
this.logger.warn(`Failed to refresh tools for ${serverName}
|
|
1157
|
+
} catch {
|
|
1158
|
+
this.logger.warn(`Failed to refresh tools for ${serverName}`, {
|
|
1159
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
1160
|
+
});
|
|
1012
1161
|
}
|
|
1013
|
-
} catch
|
|
1014
|
-
this.logger.error(
|
|
1162
|
+
} catch {
|
|
1163
|
+
this.logger.error("Error handling tools list change", {
|
|
1164
|
+
code: import_error_codes.MCPErrorCode.PROTOCOL_ERROR
|
|
1165
|
+
});
|
|
1015
1166
|
}
|
|
1016
1167
|
}
|
|
1017
1168
|
}
|
package/dist/mcp/manager.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ValidatedServersConfig, ValidatedMcpServerConfig } from './schemas.js';
|
|
2
2
|
import type { Logger } from '../logger/v2/types.js';
|
|
3
|
-
import type { GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
-
import type { McpClient, MCPResolvedResource, McpAuthProviderFactory } from './types.js';
|
|
3
|
+
import type { CallToolResult, GetPromptResult, ReadResourceResult } from '@modelcontextprotocol/sdk/types.js';
|
|
4
|
+
import type { McpClient, MCPDirectToolCall, ConfiguredMcpServerStatus, MCPResolvedResource, McpAuthProviderFactory } from './types.js';
|
|
5
5
|
import type { MCPToolDescriptor, ToolSet } from '../tools/types.js';
|
|
6
6
|
import { type AgentEventBus } from '../events/index.js';
|
|
7
7
|
import type { PromptDefinition } from '../prompts/types.js';
|
|
@@ -15,6 +15,10 @@ type ToolCacheEntry = {
|
|
|
15
15
|
};
|
|
16
16
|
export declare class MCPManager {
|
|
17
17
|
private clients;
|
|
18
|
+
private retiredClients;
|
|
19
|
+
private desiredConfigurations;
|
|
20
|
+
private connectingOperations;
|
|
21
|
+
private pendingConnectionOperations;
|
|
18
22
|
private connectionErrors;
|
|
19
23
|
private configCache;
|
|
20
24
|
private toolCache;
|
|
@@ -133,6 +137,8 @@ export declare class MCPManager {
|
|
|
133
137
|
* @returns The client that provides the tool, or undefined if not found
|
|
134
138
|
*/
|
|
135
139
|
getToolClient(toolName: string): McpClient | undefined;
|
|
140
|
+
/** Call a literal upstream identity and retain its complete MCP protocol result. */
|
|
141
|
+
callToolDirect(request: MCPDirectToolCall): Promise<CallToolResult>;
|
|
136
142
|
/**
|
|
137
143
|
* Execute a specific MCP tool with the given arguments.
|
|
138
144
|
* @param toolName Name of the MCP tool to execute (may include server prefix)
|
|
@@ -193,6 +199,16 @@ export declare class MCPManager {
|
|
|
193
199
|
* @returns Promise resolving to the resource content.
|
|
194
200
|
*/
|
|
195
201
|
readResource(resourceKey: string): Promise<ReadResourceResult>;
|
|
202
|
+
/** Register desired configuration without connecting or changing legacy restart configuration. */
|
|
203
|
+
configureServer(name: string, config: ValidatedMcpServerConfig): void;
|
|
204
|
+
/** Forget an explicit desired registration; disconnecting alone retains it. */
|
|
205
|
+
forgetServerConfiguration(name: string): void;
|
|
206
|
+
/** Connect an explicitly registered, enabled configuration using the existing engine. */
|
|
207
|
+
connectConfiguredServer(name: string): Promise<void>;
|
|
208
|
+
/** List only explicitly registered desired configurations, never raw configs or diagnostics. */
|
|
209
|
+
getConfiguredServerStatuses(): readonly ConfiguredMcpServerStatus[];
|
|
210
|
+
private assertConfigurationMutable;
|
|
211
|
+
private finishConnectionAttempt;
|
|
196
212
|
/**
|
|
197
213
|
* Initialize clients from server configurations
|
|
198
214
|
* @param serverConfigs Server configurations with individual connection modes
|
|
@@ -207,6 +223,9 @@ export declare class MCPManager {
|
|
|
207
223
|
* @throws Error if the connection fails.
|
|
208
224
|
*/
|
|
209
225
|
connectServer(name: string, config: ValidatedMcpServerConfig): Promise<void>;
|
|
226
|
+
private trackConnectionOperation;
|
|
227
|
+
private connectServerAndCache;
|
|
228
|
+
private discardFailedClient;
|
|
210
229
|
/**
|
|
211
230
|
* Get all registered clients
|
|
212
231
|
* @returns Map of client names to client instances
|
|
@@ -243,8 +262,13 @@ export declare class MCPManager {
|
|
|
243
262
|
* @throws Error if server doesn't exist or config is not cached.
|
|
244
263
|
*/
|
|
245
264
|
restartServer(name: string): Promise<void>;
|
|
265
|
+
private restartServerAndCache;
|
|
246
266
|
/**
|
|
247
|
-
*
|
|
267
|
+
* Drain already-started connection/restart operations, including discovery, then
|
|
268
|
+
* disconnect registered clients and clear caches. Desired registrations remain reusable.
|
|
269
|
+
* Callers must stop starting new connection/restart operations before teardown.
|
|
270
|
+
* Draining waits for existing protocol/authentication completion; it does not cancel
|
|
271
|
+
* startup or introduce an additional deadline.
|
|
248
272
|
*/
|
|
249
273
|
disconnectAll(): Promise<void>;
|
|
250
274
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/mcp/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,uBAAuB,CAAC;
|
|
1
|
+
{"version":3,"file":"manager.d.ts","sourceRoot":"","sources":["../../src/mcp/manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,sBAAsB,EAAE,wBAAwB,EAAE,MAAM,cAAc,CAAC;AACrF,OAAO,KAAK,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