@1mcp/agent 0.12.0 → 0.13.1
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 +22 -37
- package/build/auth/sdkOAuthClientProvider.d.ts +93 -0
- package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthClientProvider.js +204 -0
- package/build/auth/sdkOAuthClientProvider.js.map +1 -0
- package/build/auth/sdkOAuthServerProvider.d.ts +64 -0
- package/build/auth/sdkOAuthServerProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthServerProvider.js +359 -0
- package/build/auth/sdkOAuthServerProvider.js.map +1 -0
- package/build/auth/sessionTypes.d.ts +38 -0
- package/build/auth/sessionTypes.d.ts.map +1 -0
- package/build/auth/sessionTypes.js +3 -0
- package/build/auth/sessionTypes.js.map +1 -0
- package/build/auth/storage/authCodeRepository.d.ts +25 -0
- package/build/auth/storage/authCodeRepository.d.ts.map +1 -0
- package/build/auth/storage/authCodeRepository.js +50 -0
- package/build/auth/storage/authCodeRepository.js.map +1 -0
- package/build/auth/storage/authRequestRepository.d.ts +25 -0
- package/build/auth/storage/authRequestRepository.d.ts.map +1 -0
- package/build/auth/storage/authRequestRepository.js +51 -0
- package/build/auth/storage/authRequestRepository.js.map +1 -0
- package/build/auth/storage/clientDataRepository.d.ts +25 -0
- package/build/auth/storage/clientDataRepository.d.ts.map +1 -0
- package/build/auth/storage/clientDataRepository.js +45 -0
- package/build/auth/storage/clientDataRepository.js.map +1 -0
- package/build/auth/storage/clientSessionRepository.d.ts +77 -0
- package/build/auth/storage/clientSessionRepository.d.ts.map +1 -0
- package/build/auth/storage/clientSessionRepository.js +120 -0
- package/build/auth/storage/clientSessionRepository.js.map +1 -0
- package/build/auth/storage/fileStorageService.d.ts +68 -0
- package/build/auth/storage/fileStorageService.d.ts.map +1 -0
- package/build/auth/storage/fileStorageService.js +262 -0
- package/build/auth/storage/fileStorageService.js.map +1 -0
- package/build/auth/storage/oauthStorageService.d.ts +57 -0
- package/build/auth/storage/oauthStorageService.d.ts.map +1 -0
- package/build/auth/storage/oauthStorageService.js +131 -0
- package/build/auth/storage/oauthStorageService.js.map +1 -0
- package/build/auth/storage/sessionRepository.d.ts +29 -0
- package/build/auth/storage/sessionRepository.d.ts.map +1 -0
- package/build/auth/storage/sessionRepository.js +64 -0
- package/build/auth/storage/sessionRepository.js.map +1 -0
- package/build/capabilities/capabilityManager.d.ts +2 -2
- package/build/capabilities/capabilityManager.d.ts.map +1 -1
- package/build/capabilities/capabilityManager.js +1 -1
- package/build/capabilities/capabilityManager.js.map +1 -1
- package/build/config/{configManager.d.ts → mcpConfigManager.d.ts} +11 -6
- package/build/config/mcpConfigManager.d.ts.map +1 -0
- package/build/config/{configManager.js → mcpConfigManager.js} +26 -8
- package/build/config/mcpConfigManager.js.map +1 -0
- package/build/constants.d.ts +51 -14
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +61 -17
- package/build/constants.js.map +1 -1
- package/build/core/client/clientManager.d.ts +14 -6
- package/build/core/client/clientManager.d.ts.map +1 -1
- package/build/core/client/clientManager.js +90 -28
- package/build/core/client/clientManager.js.map +1 -1
- package/build/core/server/{serverConfig.d.ts → agentConfig.d.ts} +50 -15
- package/build/core/server/agentConfig.d.ts.map +1 -0
- package/build/core/server/agentConfig.js +166 -0
- package/build/core/server/agentConfig.js.map +1 -0
- package/build/core/server/serverManager.d.ts +12 -5
- package/build/core/server/serverManager.d.ts.map +1 -1
- package/build/core/server/serverManager.js +12 -2
- package/build/core/server/serverManager.js.map +1 -1
- package/build/core/types/client.d.ts +22 -9
- package/build/core/types/client.d.ts.map +1 -1
- package/build/core/types/client.js +2 -0
- package/build/core/types/client.js.map +1 -1
- package/build/core/types/server.d.ts +3 -3
- package/build/core/types/server.d.ts.map +1 -1
- package/build/core/types/transport.d.ts +58 -0
- package/build/core/types/transport.d.ts.map +1 -1
- package/build/core/types/transport.js +10 -0
- package/build/core/types/transport.js.map +1 -1
- package/build/handlers/notificationHandlers.d.ts +3 -3
- package/build/handlers/notificationHandlers.d.ts.map +1 -1
- package/build/handlers/notificationHandlers.js +2 -2
- package/build/handlers/notificationHandlers.js.map +1 -1
- package/build/handlers/requestHandlers.d.ts +2 -2
- package/build/handlers/requestHandlers.d.ts.map +1 -1
- package/build/handlers/requestHandlers.js +4 -3
- package/build/handlers/requestHandlers.js.map +1 -1
- package/build/index.js +47 -7
- package/build/index.js.map +1 -1
- package/build/{transport/http/middleware/loggingMiddleware.d.ts → logger/mcpLoggingEnhancer.d.ts} +1 -1
- package/build/logger/mcpLoggingEnhancer.d.ts.map +1 -0
- package/build/{transport/http/middleware/loggingMiddleware.js → logger/mcpLoggingEnhancer.js} +2 -2
- package/build/logger/mcpLoggingEnhancer.js.map +1 -0
- package/build/server.js +4 -4
- package/build/server.js.map +1 -1
- package/build/services/configReloadService.d.ts +2 -2
- package/build/services/configReloadService.d.ts.map +1 -1
- package/build/services/configReloadService.js +4 -4
- package/build/services/configReloadService.js.map +1 -1
- package/build/transport/http/middlewares/errorHandler.d.ts.map +1 -0
- package/build/transport/http/{errorHandler.js → middlewares/errorHandler.js} +1 -1
- package/build/transport/http/middlewares/errorHandler.js.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts +39 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.js +129 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.js.map +1 -0
- package/build/transport/http/middlewares/securityMiddleware.d.ts +30 -0
- package/build/transport/http/middlewares/securityMiddleware.d.ts.map +1 -0
- package/build/transport/http/middlewares/securityMiddleware.js +201 -0
- package/build/transport/http/middlewares/securityMiddleware.js.map +1 -0
- package/build/transport/http/middlewares/tagsExtractor.d.ts.map +1 -0
- package/build/transport/http/middlewares/tagsExtractor.js.map +1 -0
- package/build/transport/http/routes/oauthRoutes.d.ts +5 -11
- package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/oauthRoutes.js +460 -122
- package/build/transport/http/routes/oauthRoutes.js.map +1 -1
- package/build/transport/http/routes/sseRoutes.d.ts +3 -2
- package/build/transport/http/routes/sseRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/sseRoutes.js +10 -7
- package/build/transport/http/routes/sseRoutes.js.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.d.ts +3 -2
- package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
- package/build/transport/http/routes/streamableHttpRoutes.js +17 -10
- package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -1
- package/build/transport/http/server.d.ts +3 -2
- package/build/transport/http/server.d.ts.map +1 -1
- package/build/transport/http/server.js +58 -21
- package/build/transport/http/server.js.map +1 -1
- package/build/transport/transportFactory.d.ts +9 -0
- package/build/transport/transportFactory.d.ts.map +1 -0
- package/build/transport/transportFactory.js +148 -0
- package/build/transport/transportFactory.js.map +1 -0
- package/build/utils/clientFiltering.d.ts +4 -4
- package/build/utils/clientFiltering.d.ts.map +1 -1
- package/build/utils/clientFiltering.js +54 -19
- package/build/utils/clientFiltering.js.map +1 -1
- package/build/utils/errorHandling.d.ts +0 -12
- package/build/utils/errorHandling.d.ts.map +1 -1
- package/build/utils/errorHandling.js +1 -42
- package/build/utils/errorHandling.js.map +1 -1
- package/build/utils/pagination.d.ts +2 -2
- package/build/utils/pagination.d.ts.map +1 -1
- package/build/utils/pagination.js +4 -4
- package/build/utils/pagination.js.map +1 -1
- package/build/utils/parsing.d.ts +13 -0
- package/build/utils/parsing.d.ts.map +1 -0
- package/build/utils/parsing.js +32 -0
- package/build/utils/parsing.js.map +1 -0
- package/build/utils/sanitization.d.ts +60 -0
- package/build/utils/sanitization.d.ts.map +1 -0
- package/build/utils/sanitization.js +149 -0
- package/build/utils/sanitization.js.map +1 -0
- package/build/utils/scopeValidation.d.ts +102 -0
- package/build/utils/scopeValidation.d.ts.map +1 -0
- package/build/utils/scopeValidation.js +244 -0
- package/build/utils/scopeValidation.js.map +1 -0
- package/package.json +20 -11
- package/build/auth/authManager.d.ts +0 -109
- package/build/auth/authManager.d.ts.map +0 -1
- package/build/auth/authManager.js +0 -173
- package/build/auth/authManager.js.map +0 -1
- package/build/auth/authMiddleware.d.ts +0 -16
- package/build/auth/authMiddleware.d.ts.map +0 -1
- package/build/auth/authMiddleware.js +0 -45
- package/build/auth/authMiddleware.js.map +0 -1
- package/build/auth/sessionManager.d.ts +0 -197
- package/build/auth/sessionManager.d.ts.map +0 -1
- package/build/auth/sessionManager.js +0 -408
- package/build/auth/sessionManager.js.map +0 -1
- package/build/config/configManager.d.ts.map +0 -1
- package/build/config/configManager.js.map +0 -1
- package/build/core/server/serverConfig.d.ts.map +0 -1
- package/build/core/server/serverConfig.js +0 -117
- package/build/core/server/serverConfig.js.map +0 -1
- package/build/transport/config.d.ts +0 -7
- package/build/transport/config.d.ts.map +0 -1
- package/build/transport/config.js +0 -90
- package/build/transport/config.js.map +0 -1
- package/build/transport/http/errorHandler.d.ts.map +0 -1
- package/build/transport/http/errorHandler.js.map +0 -1
- package/build/transport/http/middleware/loggingMiddleware.d.ts.map +0 -1
- package/build/transport/http/middleware/loggingMiddleware.js.map +0 -1
- package/build/utils/tagsExtractor.d.ts.map +0 -1
- package/build/utils/tagsExtractor.js.map +0 -1
- /package/build/transport/http/{errorHandler.d.ts → middlewares/errorHandler.d.ts} +0 -0
- /package/build/{utils → transport/http/middlewares}/tagsExtractor.d.ts +0 -0
- /package/build/{utils → transport/http/middlewares}/tagsExtractor.js +0 -0
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
+
import { OutboundConnection, OutboundConnections, OperationOptions, InboundConnection, ServerCapability, AuthProviderTransport } from '../types/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* Creates client instances for all transports with retry logic
|
|
5
5
|
* @param transports Record of transport instances
|
|
6
6
|
* @returns Record of client instances
|
|
7
7
|
*/
|
|
8
|
-
export declare function createClients(transports: Record<string,
|
|
8
|
+
export declare function createClients(transports: Record<string, AuthProviderTransport>): Promise<OutboundConnections>;
|
|
9
9
|
/**
|
|
10
10
|
* Gets a client by name with error handling
|
|
11
11
|
* @param clients Record of client instances
|
|
@@ -13,7 +13,7 @@ export declare function createClients(transports: Record<string, Transport>): Pr
|
|
|
13
13
|
* @returns The client instance
|
|
14
14
|
* @throws ClientNotFoundError if the client is not found
|
|
15
15
|
*/
|
|
16
|
-
export declare function getClient(clients:
|
|
16
|
+
export declare function getClient(clients: OutboundConnections, clientName: string): OutboundConnection;
|
|
17
17
|
/**
|
|
18
18
|
* Executes an operation with error handling and retry logic
|
|
19
19
|
* @param operation The operation to execute
|
|
@@ -30,12 +30,20 @@ export declare function executeOperation<T>(operation: () => Promise<T>, context
|
|
|
30
30
|
* @param options Operation options including timeout and retry settings
|
|
31
31
|
* @param requiredCapability The capability required for this operation
|
|
32
32
|
*/
|
|
33
|
-
export declare function executeClientOperation<T>(clients:
|
|
33
|
+
export declare function executeClientOperation<T>(clients: OutboundConnections, clientName: string, operation: (clientInfo: OutboundConnection) => Promise<T>, options?: OperationOptions, requiredCapability?: ServerCapability): Promise<T>;
|
|
34
34
|
/**
|
|
35
35
|
* Executes a server operation with error handling and retry logic
|
|
36
36
|
* @param server The server to execute the operation on
|
|
37
37
|
* @param operation The operation to execute
|
|
38
38
|
* @param options Operation options including timeout and retry settings
|
|
39
39
|
*/
|
|
40
|
-
export declare function executeServerOperation<T>(server:
|
|
40
|
+
export declare function executeServerOperation<T>(server: InboundConnection, operation: (server: InboundConnection) => Promise<T>, options?: OperationOptions): Promise<T>;
|
|
41
|
+
/**
|
|
42
|
+
* Custom error class for OAuth authorization required
|
|
43
|
+
*/
|
|
44
|
+
export declare class OAuthRequiredError extends Error {
|
|
45
|
+
serverName: string;
|
|
46
|
+
client: Client;
|
|
47
|
+
constructor(serverName: string, client: Client);
|
|
48
|
+
}
|
|
41
49
|
//# sourceMappingURL=clientManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientManager.d.ts","sourceRoot":"","sources":["../../../src/core/client/clientManager.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"clientManager.d.ts","sourceRoot":"","sources":["../../../src/core/client/clientManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAQnE,OAAO,EAEL,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,qBAAqB,EACtB,MAAM,mBAAmB,CAAC;AAG3B;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,qBAAqB,CAAC,GAAG,OAAO,CAAC,mBAAmB,CAAC,CAkEnH;AA4DD;;;;;;GAMG;AACH,wBAAgB,SAAS,CAAC,OAAO,EAAE,mBAAmB,EAAE,UAAU,EAAE,MAAM,GAAG,kBAAkB,CAM9F;AAED;;;;;;GAMG;AACH,wBAAsB,gBAAgB,CAAC,CAAC,EACtC,SAAS,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,EAC3B,WAAW,EAAE,MAAM,EACnB,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,CAAC,CAAC,CA2BZ;AAED;;;;;;;GAOG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,OAAO,EAAE,mBAAmB,EAC5B,UAAU,EAAE,MAAM,EAClB,SAAS,EAAE,CAAC,UAAU,EAAE,kBAAkB,KAAK,OAAO,CAAC,CAAC,CAAC,EACzD,OAAO,GAAE,gBAAqB,EAC9B,kBAAkB,CAAC,EAAE,gBAAgB,GACpC,OAAO,CAAC,CAAC,CAAC,CAQZ;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,CAAC,EAC5C,MAAM,EAAE,iBAAiB,EACzB,SAAS,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,OAAO,CAAC,CAAC,CAAC,EACpD,OAAO,GAAE,gBAAqB,GAC7B,OAAO,CAAC,CAAC,CAAC,CAEZ;AAED;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,KAAK;IAElC,UAAU,EAAE,MAAM;IAClB,MAAM,EAAE,MAAM;gBADd,UAAU,EAAE,MAAM,EAClB,MAAM,EAAE,MAAM;CAKxB"}
|
|
@@ -1,79 +1,128 @@
|
|
|
1
1
|
import { ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
2
3
|
import createClient from './clientFactory.js';
|
|
3
4
|
import logger from '../../logger/logger.js';
|
|
4
5
|
import { CONNECTION_RETRY, MCP_SERVER_NAME } from '../../constants.js';
|
|
5
6
|
import { ClientConnectionError, ClientNotFoundError, MCPError, CapabilityError } from '../../utils/errorTypes.js';
|
|
6
|
-
import { ClientStatus } from '../types/index.js';
|
|
7
|
+
import { ClientStatus, } from '../types/index.js';
|
|
8
|
+
import { AgentConfigManager } from '../server/agentConfig.js';
|
|
7
9
|
/**
|
|
8
10
|
* Creates client instances for all transports with retry logic
|
|
9
11
|
* @param transports Record of transport instances
|
|
10
12
|
* @returns Record of client instances
|
|
11
13
|
*/
|
|
12
14
|
export async function createClients(transports) {
|
|
13
|
-
const clients =
|
|
15
|
+
const clients = new Map();
|
|
14
16
|
for (const [name, transport] of Object.entries(transports)) {
|
|
15
17
|
logger.info(`Creating client for ${name}`);
|
|
16
18
|
try {
|
|
17
19
|
const client = await createClient();
|
|
18
20
|
// Connect with retry logic
|
|
19
|
-
await connectWithRetry(client, transport, name);
|
|
20
|
-
clients
|
|
21
|
+
const connectedClient = await connectWithRetry(client, transport, name);
|
|
22
|
+
clients.set(name, {
|
|
21
23
|
name,
|
|
22
24
|
transport,
|
|
23
|
-
client,
|
|
25
|
+
client: connectedClient,
|
|
24
26
|
status: ClientStatus.Connected,
|
|
25
27
|
lastConnected: new Date(),
|
|
26
|
-
};
|
|
28
|
+
});
|
|
27
29
|
logger.info(`Client created for ${name}`);
|
|
28
|
-
|
|
29
|
-
|
|
30
|
+
connectedClient.onclose = () => {
|
|
31
|
+
const clientInfo = clients.get(name);
|
|
32
|
+
if (clientInfo) {
|
|
33
|
+
clientInfo.status = ClientStatus.Disconnected;
|
|
34
|
+
}
|
|
30
35
|
logger.info(`Client ${name} disconnected`);
|
|
31
36
|
};
|
|
32
37
|
}
|
|
33
38
|
catch (error) {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
name
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if (error instanceof OAuthRequiredError) {
|
|
40
|
+
// Handle OAuth required - set client to AwaitingOAuth status
|
|
41
|
+
logger.info(`OAuth authorization required for ${name}`);
|
|
42
|
+
// Try to get authorization URL from OAuth provider
|
|
43
|
+
let authorizationUrl;
|
|
44
|
+
try {
|
|
45
|
+
// Extract OAuth provider from transport if available
|
|
46
|
+
const oauthProvider = transport.oauthProvider;
|
|
47
|
+
if (oauthProvider && typeof oauthProvider.getAuthorizationUrl === 'function') {
|
|
48
|
+
authorizationUrl = oauthProvider.getAuthorizationUrl();
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
catch (urlError) {
|
|
52
|
+
logger.warn(`Could not extract authorization URL for ${name}:`, urlError);
|
|
53
|
+
}
|
|
54
|
+
clients.set(name, {
|
|
55
|
+
name,
|
|
56
|
+
transport,
|
|
57
|
+
client: error.client,
|
|
58
|
+
status: ClientStatus.AwaitingOAuth,
|
|
59
|
+
authorizationUrl,
|
|
60
|
+
oauthStartTime: new Date(),
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
else {
|
|
64
|
+
logger.error(`Failed to create client for ${name}: ${error}`);
|
|
65
|
+
clients.set(name, {
|
|
66
|
+
name,
|
|
67
|
+
transport,
|
|
68
|
+
client: await createClient(),
|
|
69
|
+
status: ClientStatus.Error,
|
|
70
|
+
lastError: error instanceof Error ? error : new Error(String(error)),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
42
73
|
}
|
|
43
74
|
}
|
|
44
|
-
return
|
|
75
|
+
return clients;
|
|
45
76
|
}
|
|
46
77
|
/**
|
|
47
|
-
* Connects a client to its transport with retry logic
|
|
78
|
+
* Connects a client to its transport with retry logic and OAuth support
|
|
48
79
|
* @param client The client to connect
|
|
49
80
|
* @param transport The transport to connect to
|
|
50
81
|
* @param name The name of the client for logging
|
|
82
|
+
* @returns The connected client (may be a new instance after retries)
|
|
51
83
|
*/
|
|
52
84
|
async function connectWithRetry(client, transport, name) {
|
|
53
85
|
let retryDelay = CONNECTION_RETRY.INITIAL_DELAY_MS;
|
|
86
|
+
let currentClient = client;
|
|
54
87
|
for (let i = 0; i < CONNECTION_RETRY.MAX_ATTEMPTS; i++) {
|
|
55
88
|
try {
|
|
56
|
-
await
|
|
57
|
-
const sv = await
|
|
89
|
+
await currentClient.connect(transport);
|
|
90
|
+
const sv = await currentClient.getServerVersion();
|
|
58
91
|
if (sv?.name === MCP_SERVER_NAME) {
|
|
59
92
|
throw new ClientConnectionError(name, new Error('Aborted to prevent circular dependency'));
|
|
60
93
|
}
|
|
61
94
|
logger.info(`Successfully connected to ${name} with server ${sv?.name} version ${sv?.version}`);
|
|
62
|
-
return;
|
|
95
|
+
return currentClient;
|
|
63
96
|
}
|
|
64
97
|
catch (error) {
|
|
65
|
-
|
|
66
|
-
if (
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
98
|
+
// Handle OAuth authorization flow (managed by SDK)
|
|
99
|
+
if (error instanceof UnauthorizedError) {
|
|
100
|
+
const serverConfig = AgentConfigManager.getInstance().getConfig();
|
|
101
|
+
logger.info(`OAuth authorization required for ${name}. Visit http://localhost:${serverConfig.port}/oauth to authorize`);
|
|
102
|
+
// Throw special error that includes OAuth info
|
|
103
|
+
throw new OAuthRequiredError(name, currentClient);
|
|
70
104
|
}
|
|
105
|
+
// Handle other connection errors
|
|
71
106
|
else {
|
|
72
|
-
|
|
107
|
+
const errorMessage = error instanceof Error ? error.message : String(error);
|
|
108
|
+
logger.error(`Failed to connect to ${name}: ${errorMessage}`);
|
|
109
|
+
if (i < CONNECTION_RETRY.MAX_ATTEMPTS - 1) {
|
|
110
|
+
logger.info(`Retrying in ${retryDelay}ms...`);
|
|
111
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
112
|
+
retryDelay *= 2; // Exponential backoff
|
|
113
|
+
// Create a new client for retry to avoid "already started" errors
|
|
114
|
+
currentClient = await createClient();
|
|
115
|
+
}
|
|
116
|
+
else {
|
|
117
|
+
throw new ClientConnectionError(name, error instanceof Error ? error : new Error(String(error)));
|
|
118
|
+
}
|
|
73
119
|
}
|
|
74
120
|
}
|
|
75
121
|
}
|
|
122
|
+
// This should never be reached due to the throw in the else block above
|
|
123
|
+
throw new ClientConnectionError(name, new Error('Max retries exceeded'));
|
|
76
124
|
}
|
|
125
|
+
// OAuth authorization flow is now handled by the SDK's built-in implementation
|
|
77
126
|
/**
|
|
78
127
|
* Gets a client by name with error handling
|
|
79
128
|
* @param clients Record of client instances
|
|
@@ -82,7 +131,7 @@ async function connectWithRetry(client, transport, name) {
|
|
|
82
131
|
* @throws ClientNotFoundError if the client is not found
|
|
83
132
|
*/
|
|
84
133
|
export function getClient(clients, clientName) {
|
|
85
|
-
const client = clients
|
|
134
|
+
const client = clients.get(clientName);
|
|
86
135
|
if (!client) {
|
|
87
136
|
throw new ClientNotFoundError(clientName);
|
|
88
137
|
}
|
|
@@ -144,4 +193,17 @@ export async function executeClientOperation(clients, clientName, operation, opt
|
|
|
144
193
|
export async function executeServerOperation(server, operation, options = {}) {
|
|
145
194
|
return executeOperation(() => operation(server), 'server', options);
|
|
146
195
|
}
|
|
196
|
+
/**
|
|
197
|
+
* Custom error class for OAuth authorization required
|
|
198
|
+
*/
|
|
199
|
+
export class OAuthRequiredError extends Error {
|
|
200
|
+
serverName;
|
|
201
|
+
client;
|
|
202
|
+
constructor(serverName, client) {
|
|
203
|
+
super(`OAuth authorization required for ${serverName}`);
|
|
204
|
+
this.serverName = serverName;
|
|
205
|
+
this.client = client;
|
|
206
|
+
this.name = 'OAuthRequiredError';
|
|
207
|
+
}
|
|
208
|
+
}
|
|
147
209
|
//# sourceMappingURL=clientManager.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"clientManager.js","sourceRoot":"","sources":["../../../src/core/client/clientManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAClH,OAAO,
|
|
1
|
+
{"version":3,"file":"clientManager.js","sourceRoot":"","sources":["../../../src/core/client/clientManager.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,SAAS,EAAE,MAAM,oCAAoC,CAAC;AAC/D,OAAO,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E,OAAO,YAAY,MAAM,oBAAoB,CAAC;AAC9C,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,gBAAgB,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACvE,OAAO,EAAE,qBAAqB,EAAE,mBAAmB,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,2BAA2B,CAAC;AAClH,OAAO,EACL,YAAY,GAOb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,kBAAkB,EAAE,MAAM,0BAA0B,CAAC;AAE9D;;;;GAIG;AACH,MAAM,CAAC,KAAK,UAAU,aAAa,CAAC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;;GAKG;AACH,MAAM,CAAC,KAAK,UAAU,sBAAsB,CAC1C,MAAyB,EACzB,SAAoD,EACpD,UAA4B,EAAE;IAE9B,OAAO,gBAAgB,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,MAAM,CAAC,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC;AACtE,CAAC;AAED;;GAEG;AACH,MAAM,OAAO,kBAAmB,SAAQ,KAAK;IAElC;IACA;IAFT,YACS,UAAkB,EAClB,MAAc;QAErB,KAAK,CAAC,oCAAoC,UAAU,EAAE,CAAC,CAAC;QAHjD,eAAU,GAAV,UAAU,CAAQ;QAClB,WAAM,GAAN,MAAM,CAAQ;QAGrB,IAAI,CAAC,IAAI,GAAG,oBAAoB,CAAC;IACnC,CAAC;CACF"}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Configuration interface for
|
|
2
|
+
* Configuration interface for agent-specific settings.
|
|
3
3
|
*
|
|
4
4
|
* Defines the structure for authentication and session management configuration
|
|
5
5
|
* that can be customized via CLI arguments or environment variables.
|
|
6
6
|
*/
|
|
7
|
-
export interface
|
|
7
|
+
export interface AgentConfig {
|
|
8
|
+
host: string;
|
|
9
|
+
port: number;
|
|
8
10
|
auth: {
|
|
9
11
|
enabled: boolean;
|
|
10
12
|
sessionTtlMinutes: number;
|
|
@@ -12,24 +14,33 @@ export interface ServerConfig {
|
|
|
12
14
|
oauthCodeTtlMs: number;
|
|
13
15
|
oauthTokenTtlMs: number;
|
|
14
16
|
};
|
|
17
|
+
rateLimit: {
|
|
18
|
+
windowMs: number;
|
|
19
|
+
max: number;
|
|
20
|
+
};
|
|
21
|
+
features: {
|
|
22
|
+
auth: boolean;
|
|
23
|
+
scopeValidation: boolean;
|
|
24
|
+
enhancedSecurity: boolean;
|
|
25
|
+
};
|
|
15
26
|
}
|
|
16
27
|
/**
|
|
17
|
-
*
|
|
28
|
+
* AgentConfigManager manages agent-specific configuration settings.
|
|
18
29
|
*
|
|
19
30
|
* This singleton class handles authentication and session configuration
|
|
20
31
|
* that differs from the main MCP server configuration. It provides
|
|
21
|
-
* centralized access to
|
|
32
|
+
* centralized access to agent settings with default values and
|
|
22
33
|
* runtime configuration updates.
|
|
23
34
|
*
|
|
24
35
|
* @example
|
|
25
36
|
* ```typescript
|
|
26
|
-
* const configManager =
|
|
37
|
+
* const configManager = AgentConfigManager.getInstance();
|
|
27
38
|
* configManager.updateConfig({
|
|
28
39
|
* auth: { enabled: true, sessionTtlMinutes: 60 }
|
|
29
40
|
* });
|
|
30
41
|
* ```
|
|
31
42
|
*/
|
|
32
|
-
export declare class
|
|
43
|
+
export declare class AgentConfigManager {
|
|
33
44
|
private static instance;
|
|
34
45
|
private config;
|
|
35
46
|
/**
|
|
@@ -40,32 +51,32 @@ export declare class ServerConfigManager {
|
|
|
40
51
|
*/
|
|
41
52
|
private constructor();
|
|
42
53
|
/**
|
|
43
|
-
* Gets the singleton instance of
|
|
54
|
+
* Gets the singleton instance of AgentConfigManager.
|
|
44
55
|
*
|
|
45
56
|
* Creates a new instance if one doesn't exist, otherwise returns
|
|
46
57
|
* the existing instance to ensure configuration consistency.
|
|
47
58
|
*
|
|
48
|
-
* @returns The singleton
|
|
59
|
+
* @returns The singleton AgentConfigManager instance
|
|
49
60
|
*/
|
|
50
|
-
static getInstance():
|
|
61
|
+
static getInstance(): AgentConfigManager;
|
|
51
62
|
/**
|
|
52
|
-
* Updates the
|
|
63
|
+
* Updates the agent configuration with new values.
|
|
53
64
|
*
|
|
54
65
|
* Merges the provided updates with existing configuration, allowing
|
|
55
66
|
* partial updates while preserving other settings.
|
|
56
67
|
*
|
|
57
68
|
* @param updates - Partial configuration object with new values
|
|
58
69
|
*/
|
|
59
|
-
updateConfig(updates: Partial<
|
|
70
|
+
updateConfig(updates: Partial<AgentConfig>): void;
|
|
60
71
|
/**
|
|
61
|
-
* Gets a copy of the current
|
|
72
|
+
* Gets a copy of the current agent configuration.
|
|
62
73
|
*
|
|
63
74
|
* Returns a deep copy to prevent external modification of the
|
|
64
75
|
* internal configuration state.
|
|
65
76
|
*
|
|
66
|
-
* @returns Current
|
|
77
|
+
* @returns Current agent configuration
|
|
67
78
|
*/
|
|
68
|
-
getConfig():
|
|
79
|
+
getConfig(): AgentConfig;
|
|
69
80
|
/**
|
|
70
81
|
* Checks if authentication is currently enabled.
|
|
71
82
|
*
|
|
@@ -96,5 +107,29 @@ export declare class ServerConfigManager {
|
|
|
96
107
|
* @returns OAuth token TTL in milliseconds
|
|
97
108
|
*/
|
|
98
109
|
getOAuthTokenTtlMs(): number;
|
|
110
|
+
/**
|
|
111
|
+
* Gets the rate limit window in milliseconds.
|
|
112
|
+
*
|
|
113
|
+
* @returns Rate limit window in milliseconds
|
|
114
|
+
*/
|
|
115
|
+
getRateLimitWindowMs(): number;
|
|
116
|
+
/**
|
|
117
|
+
* Gets the maximum number of requests per rate limit window.
|
|
118
|
+
*
|
|
119
|
+
* @returns Maximum requests per window
|
|
120
|
+
*/
|
|
121
|
+
getRateLimitMax(): number;
|
|
122
|
+
/**
|
|
123
|
+
* Checks if scope validation is enabled.
|
|
124
|
+
*
|
|
125
|
+
* @returns True if tag-based scope validation is enabled, false otherwise
|
|
126
|
+
*/
|
|
127
|
+
isScopeValidationEnabled(): boolean;
|
|
128
|
+
/**
|
|
129
|
+
* Checks if enhanced security middleware is enabled.
|
|
130
|
+
*
|
|
131
|
+
* @returns True if enhanced security middleware is enabled, false otherwise
|
|
132
|
+
*/
|
|
133
|
+
isEnhancedSecurityEnabled(): boolean;
|
|
99
134
|
}
|
|
100
|
-
//# sourceMappingURL=
|
|
135
|
+
//# sourceMappingURL=agentConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentConfig.d.ts","sourceRoot":"","sources":["../../../src/core/server/agentConfig.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,WAAW;IAC1B,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MA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';
|
|
2
|
+
/**
|
|
3
|
+
* AgentConfigManager manages agent-specific configuration settings.
|
|
4
|
+
*
|
|
5
|
+
* This singleton class handles authentication and session configuration
|
|
6
|
+
* that differs from the main MCP server configuration. It provides
|
|
7
|
+
* centralized access to agent settings with default values and
|
|
8
|
+
* runtime configuration updates.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const configManager = AgentConfigManager.getInstance();
|
|
13
|
+
* configManager.updateConfig({
|
|
14
|
+
* auth: { enabled: true, sessionTtlMinutes: 60 }
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class AgentConfigManager {
|
|
19
|
+
static instance;
|
|
20
|
+
config;
|
|
21
|
+
/**
|
|
22
|
+
* Private constructor to enforce singleton pattern.
|
|
23
|
+
*
|
|
24
|
+
* Initializes the configuration with default values from constants.
|
|
25
|
+
* Should not be called directly - use getInstance() instead.
|
|
26
|
+
*/
|
|
27
|
+
constructor() {
|
|
28
|
+
this.config = {
|
|
29
|
+
host: HOST,
|
|
30
|
+
port: PORT,
|
|
31
|
+
auth: {
|
|
32
|
+
enabled: AUTH_CONFIG.SERVER.DEFAULT_ENABLED,
|
|
33
|
+
sessionTtlMinutes: AUTH_CONFIG.SERVER.SESSION.TTL_MINUTES,
|
|
34
|
+
oauthCodeTtlMs: AUTH_CONFIG.SERVER.AUTH_CODE.TTL_MS,
|
|
35
|
+
oauthTokenTtlMs: AUTH_CONFIG.SERVER.TOKEN.TTL_MS,
|
|
36
|
+
},
|
|
37
|
+
rateLimit: {
|
|
38
|
+
windowMs: RATE_LIMIT_CONFIG.OAUTH.WINDOW_MS,
|
|
39
|
+
max: RATE_LIMIT_CONFIG.OAUTH.MAX,
|
|
40
|
+
},
|
|
41
|
+
features: {
|
|
42
|
+
auth: AUTH_CONFIG.SERVER.DEFAULT_ENABLED,
|
|
43
|
+
scopeValidation: AUTH_CONFIG.SERVER.DEFAULT_ENABLED,
|
|
44
|
+
enhancedSecurity: false,
|
|
45
|
+
},
|
|
46
|
+
};
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Gets the singleton instance of AgentConfigManager.
|
|
50
|
+
*
|
|
51
|
+
* Creates a new instance if one doesn't exist, otherwise returns
|
|
52
|
+
* the existing instance to ensure configuration consistency.
|
|
53
|
+
*
|
|
54
|
+
* @returns The singleton AgentConfigManager instance
|
|
55
|
+
*/
|
|
56
|
+
static getInstance() {
|
|
57
|
+
if (!AgentConfigManager.instance) {
|
|
58
|
+
AgentConfigManager.instance = new AgentConfigManager();
|
|
59
|
+
}
|
|
60
|
+
return AgentConfigManager.instance;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Updates the agent configuration with new values.
|
|
64
|
+
*
|
|
65
|
+
* Merges the provided updates with existing configuration, allowing
|
|
66
|
+
* partial updates while preserving other settings.
|
|
67
|
+
*
|
|
68
|
+
* @param updates - Partial configuration object with new values
|
|
69
|
+
*/
|
|
70
|
+
updateConfig(updates) {
|
|
71
|
+
this.config = { ...this.config, ...updates };
|
|
72
|
+
if (updates.auth) {
|
|
73
|
+
this.config.auth = { ...this.config.auth, ...updates.auth };
|
|
74
|
+
}
|
|
75
|
+
if (updates.rateLimit) {
|
|
76
|
+
this.config.rateLimit = { ...this.config.rateLimit, ...updates.rateLimit };
|
|
77
|
+
}
|
|
78
|
+
if (updates.features) {
|
|
79
|
+
this.config.features = { ...this.config.features, ...updates.features };
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Gets a copy of the current agent configuration.
|
|
84
|
+
*
|
|
85
|
+
* Returns a deep copy to prevent external modification of the
|
|
86
|
+
* internal configuration state.
|
|
87
|
+
*
|
|
88
|
+
* @returns Current agent configuration
|
|
89
|
+
*/
|
|
90
|
+
getConfig() {
|
|
91
|
+
return { ...this.config };
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* Checks if authentication is currently enabled.
|
|
95
|
+
*
|
|
96
|
+
* @returns True if OAuth 2.1 authentication is enabled, false otherwise
|
|
97
|
+
*/
|
|
98
|
+
isAuthEnabled() {
|
|
99
|
+
return this.config.features.auth;
|
|
100
|
+
}
|
|
101
|
+
/**
|
|
102
|
+
* Gets the session time-to-live in minutes.
|
|
103
|
+
*
|
|
104
|
+
* @returns Session TTL in minutes
|
|
105
|
+
*/
|
|
106
|
+
getSessionTtlMinutes() {
|
|
107
|
+
return this.config.auth.sessionTtlMinutes;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Gets the custom session storage path if configured.
|
|
111
|
+
*
|
|
112
|
+
* @returns Custom session storage path or undefined if using default
|
|
113
|
+
*/
|
|
114
|
+
getSessionStoragePath() {
|
|
115
|
+
return this.config.auth.sessionStoragePath;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Gets the OAuth authorization code time-to-live in milliseconds.
|
|
119
|
+
*
|
|
120
|
+
* @returns OAuth code TTL in milliseconds
|
|
121
|
+
*/
|
|
122
|
+
getOAuthCodeTtlMs() {
|
|
123
|
+
return this.config.auth.oauthCodeTtlMs;
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Gets the OAuth access token time-to-live in milliseconds.
|
|
127
|
+
*
|
|
128
|
+
* @returns OAuth token TTL in milliseconds
|
|
129
|
+
*/
|
|
130
|
+
getOAuthTokenTtlMs() {
|
|
131
|
+
return this.config.auth.oauthTokenTtlMs;
|
|
132
|
+
}
|
|
133
|
+
/**
|
|
134
|
+
* Gets the rate limit window in milliseconds.
|
|
135
|
+
*
|
|
136
|
+
* @returns Rate limit window in milliseconds
|
|
137
|
+
*/
|
|
138
|
+
getRateLimitWindowMs() {
|
|
139
|
+
return this.config.rateLimit.windowMs;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* Gets the maximum number of requests per rate limit window.
|
|
143
|
+
*
|
|
144
|
+
* @returns Maximum requests per window
|
|
145
|
+
*/
|
|
146
|
+
getRateLimitMax() {
|
|
147
|
+
return this.config.rateLimit.max;
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Checks if scope validation is enabled.
|
|
151
|
+
*
|
|
152
|
+
* @returns True if tag-based scope validation is enabled, false otherwise
|
|
153
|
+
*/
|
|
154
|
+
isScopeValidationEnabled() {
|
|
155
|
+
return this.config.features.scopeValidation;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Checks if enhanced security middleware is enabled.
|
|
159
|
+
*
|
|
160
|
+
* @returns True if enhanced security middleware is enabled, false otherwise
|
|
161
|
+
*/
|
|
162
|
+
isEnhancedSecurityEnabled() {
|
|
163
|
+
return this.config.features.enhancedSecurity;
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
//# sourceMappingURL=agentConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"agentConfig.js","sourceRoot":"","sources":["../../../src/core/server/agentConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,IAAI,EAAE,IAAI,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AA6BhF;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,kBAAkB;IACrB,MAAM,CAAC,QAAQ,CAAqB;IACpC,MAAM,CAAc;IAE5B;;;;;OAKG;IACH;QACE,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE,IAAI;YACV,IAAI,EAAE,IAAI;YACV,IAAI,EAAE;gBACJ,OAAO,EAAE,WAAW,CAAC,MAAM,CAAC,eAAe;gBAC3C,iBAAiB,EAAE,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW;gBACzD,cAAc,EAAE,WAAW,CAAC,MAAM,CAAC,SAAS,CAAC,MAAM;gBACnD,eAAe,EAAE,WAAW,CAAC,MAAM,CAAC,KAAK,CAAC,MAAM;aACjD;YACD,SAAS,EAAE;gBACT,QAAQ,EAAE,iBAAiB,CAAC,KAAK,CAAC,SAAS;g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;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,oBAAoB;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,iBAAiB,CAAC;IAC5C,CAAC;IAED;;;;OAIG;IACI,qBAAqB;QAC1B,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,kBAAkB,CAAC;IAC7C,CAAC;IAED;;;;OAIG;IACI,iBAAiB;QACtB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,cAAc,CAAC;IACzC,CAAC;IAED;;;;OAIG;IACI,kBAAkB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,eAAe,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACI,oBAAoB;QACzB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;IACxC,CAAC;IAED;;;;OAIG;IACI,eAAe;QACpB,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;IACnC,CAAC;IAED;;;;OAIG;IACI,wBAAwB;QAC7B,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,eAAe,CAAC;IAC9C,CAAC;IAED;;;;OAIG;IACI,yBAAyB;QAC9B,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,gBAAgB,CAAC;IAC/C,CAAC;CACF"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { Transport } from '@modelcontextprotocol/sdk/shared/transport.js';
|
|
2
|
-
import {
|
|
2
|
+
import { OutboundConnections, InboundConnection, InboundConnectionConfig } from '../types/index.js';
|
|
3
|
+
import type { OutboundConnection } from '../types/client.js';
|
|
3
4
|
export declare class ServerManager {
|
|
4
5
|
private static instance;
|
|
5
6
|
private servers;
|
|
@@ -15,18 +16,24 @@ export declare class ServerManager {
|
|
|
15
16
|
version: string;
|
|
16
17
|
}, capabilities: {
|
|
17
18
|
capabilities: Record<string, unknown>;
|
|
18
|
-
}, clients:
|
|
19
|
+
}, clients: OutboundConnections, transports: Record<string, Transport>): ServerManager;
|
|
19
20
|
static get current(): ServerManager;
|
|
20
21
|
static resetInstance(): void;
|
|
21
|
-
connectTransport(transport: Transport, sessionId: string, opts:
|
|
22
|
+
connectTransport(transport: Transport, sessionId: string, opts: InboundConnectionConfig): Promise<void>;
|
|
22
23
|
private performConnection;
|
|
23
24
|
private doConnect;
|
|
24
25
|
disconnectTransport(sessionId: string, forceClose?: boolean): void;
|
|
25
26
|
getTransport(sessionId: string): Transport | undefined;
|
|
26
27
|
getTransports(): Map<string, Transport>;
|
|
27
28
|
getClientTransports(): Record<string, Transport>;
|
|
29
|
+
getClients(): OutboundConnections;
|
|
30
|
+
/**
|
|
31
|
+
* Safely get a client by name. Returns undefined if not found or not an own property.
|
|
32
|
+
* Encapsulates access to prevent prototype pollution and accidental key collisions.
|
|
33
|
+
*/
|
|
34
|
+
getClient(serverName: string): OutboundConnection | undefined;
|
|
28
35
|
getActiveTransportsCount(): number;
|
|
29
|
-
getServer(sessionId: string):
|
|
30
|
-
updateClientsAndTransports(newClients:
|
|
36
|
+
getServer(sessionId: string): InboundConnection | undefined;
|
|
37
|
+
updateClientsAndTransports(newClients: OutboundConnections, newTransports: Record<string, Transport>): void;
|
|
31
38
|
}
|
|
32
39
|
//# sourceMappingURL=serverManager.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serverManager.d.ts","sourceRoot":"","sources":["../../../src/core/server/serverManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAK1E,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"serverManager.d.ts","sourceRoot":"","sources":["../../../src/core/server/serverManager.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,+CAA+C,CAAC;AAK1E,OAAO,E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CAAC,UAAU,EAAE,MAAM,GAAG,kBAAkB,GAAG,SAAS;IAI7D,wBAAwB,IAAI,MAAM;IAIlC,SAAS,CAAC,SAAS,EAAE,MAAM,GAAG,iBAAiB,GAAG,SAAS;IAI3D,0BAA0B,CAAC,UAAU,EAAE,mBAAmB,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAG,IAAI;CAInH"}
|
|
@@ -2,13 +2,13 @@ import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
|
2
2
|
import logger from '../../logger/logger.js';
|
|
3
3
|
import configReloadService from '../../services/configReloadService.js';
|
|
4
4
|
import { setupCapabilities } from '../../capabilities/capabilityManager.js';
|
|
5
|
-
import { enhanceServerWithLogging } from '../../
|
|
5
|
+
import { enhanceServerWithLogging } from '../../logger/mcpLoggingEnhancer.js';
|
|
6
6
|
export class ServerManager {
|
|
7
7
|
static instance;
|
|
8
8
|
servers = new Map();
|
|
9
9
|
serverConfig;
|
|
10
10
|
serverCapabilities;
|
|
11
|
-
clients =
|
|
11
|
+
clients = new Map();
|
|
12
12
|
transports = {};
|
|
13
13
|
connectionSemaphore = new Map();
|
|
14
14
|
disconnectingIds = new Set();
|
|
@@ -145,6 +145,16 @@ export class ServerManager {
|
|
|
145
145
|
getClientTransports() {
|
|
146
146
|
return this.transports;
|
|
147
147
|
}
|
|
148
|
+
getClients() {
|
|
149
|
+
return this.clients;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Safely get a client by name. Returns undefined if not found or not an own property.
|
|
153
|
+
* Encapsulates access to prevent prototype pollution and accidental key collisions.
|
|
154
|
+
*/
|
|
155
|
+
getClient(serverName) {
|
|
156
|
+
return this.clients.get(serverName);
|
|
157
|
+
}
|
|
148
158
|
getActiveTransportsCount() {
|
|
149
159
|
return this.servers.size;
|
|
150
160
|
}
|