@1mcp/agent 0.11.0 → 0.13.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +45 -50
- package/build/auth/clientSessionManager.d.ts +94 -0
- package/build/auth/clientSessionManager.d.ts.map +1 -0
- package/build/auth/clientSessionManager.js +220 -0
- package/build/auth/clientSessionManager.js.map +1 -0
- package/build/auth/sdkOAuthClientProvider.d.ts +93 -0
- package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthClientProvider.js +199 -0
- package/build/auth/sdkOAuthClientProvider.js.map +1 -0
- package/build/auth/sdkOAuthServerProvider.d.ts +63 -0
- package/build/auth/sdkOAuthServerProvider.d.ts.map +1 -0
- package/build/auth/sdkOAuthServerProvider.js +428 -0
- package/build/auth/sdkOAuthServerProvider.js.map +1 -0
- package/build/{server/auth/sessionManager.d.ts → auth/serverSessionManager.d.ts} +26 -37
- package/build/auth/serverSessionManager.d.ts.map +1 -0
- package/build/{server/auth/sessionManager.js → auth/serverSessionManager.js} +104 -19
- package/build/auth/serverSessionManager.js.map +1 -0
- package/build/auth/sessionTypes.d.ts +24 -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/capabilities/capabilityManager.d.ts +2 -2
- package/build/capabilities/capabilityManager.d.ts.map +1 -1
- package/build/capabilities/capabilityManager.js +40 -7
- package/build/capabilities/capabilityManager.js.map +1 -1
- package/build/config/{configManager.d.ts → mcpConfigManager.d.ts} +18 -7
- package/build/config/mcpConfigManager.d.ts.map +1 -0
- package/build/config/{configManager.js → mcpConfigManager.js} +50 -10
- package/build/config/mcpConfigManager.js.map +1 -0
- package/build/constants.d.ts +36 -14
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +40 -17
- package/build/constants.js.map +1 -1
- package/build/{client.d.ts → core/client/clientFactory.d.ts} +1 -1
- package/build/core/client/clientFactory.d.ts.map +1 -0
- package/build/{client.js → core/client/clientFactory.js} +2 -2
- package/build/core/client/clientFactory.js.map +1 -0
- package/build/{clients → core/client}/clientManager.d.ts +14 -6
- package/build/core/client/clientManager.d.ts.map +1 -0
- package/build/core/client/clientManager.js +209 -0
- package/build/core/client/clientManager.js.map +1 -0
- package/build/{server/config/serverConfig.d.ts → core/server/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 +39 -0
- package/build/core/server/serverManager.d.ts.map +1 -0
- package/build/core/server/serverManager.js +169 -0
- package/build/core/server/serverManager.js.map +1 -0
- package/build/core/types/client.d.ts +51 -0
- package/build/core/types/client.d.ts.map +1 -0
- package/build/core/types/client.js +15 -0
- package/build/core/types/client.js.map +1 -0
- package/build/core/types/index.d.ts +4 -0
- package/build/core/types/index.d.ts.map +1 -0
- package/build/core/types/index.js +5 -0
- package/build/core/types/index.js.map +1 -0
- package/build/core/types/server.d.ts +14 -0
- package/build/core/types/server.d.ts.map +1 -0
- package/build/core/types/server.js +2 -0
- package/build/core/types/server.js.map +1 -0
- package/build/{types.d.ts → core/types/transport.d.ts} +59 -49
- package/build/core/types/transport.d.ts.map +1 -0
- package/build/{types.js → core/types/transport.js} +11 -13
- package/build/core/types/transport.js.map +1 -0
- package/build/handlers/notificationHandlers.d.ts +3 -3
- package/build/handlers/notificationHandlers.d.ts.map +1 -1
- package/build/handlers/notificationHandlers.js +13 -9
- 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 +25 -3
- package/build/handlers/requestHandlers.js.map +1 -1
- package/build/index.js +48 -8
- package/build/index.js.map +1 -1
- package/build/logger/logger.js +1 -1
- package/build/logger/logger.js.map +1 -1
- package/build/{middleware/loggingMiddleware.d.ts → logger/mcpLoggingEnhancer.d.ts} +1 -1
- package/build/logger/mcpLoggingEnhancer.d.ts.map +1 -0
- package/build/{middleware/loggingMiddleware.js → logger/mcpLoggingEnhancer.js} +2 -2
- package/build/logger/mcpLoggingEnhancer.js.map +1 -0
- package/build/server.d.ts +1 -1
- package/build/server.d.ts.map +1 -1
- package/build/server.js +9 -6
- package/build/server.js.map +1 -1
- package/build/services/configReloadService.d.ts +15 -5
- package/build/services/configReloadService.d.ts.map +1 -1
- package/build/services/configReloadService.js +31 -14
- package/build/services/configReloadService.js.map +1 -1
- package/build/transport/http/middlewares/errorHandler.d.ts.map +1 -0
- package/build/{server → transport/http/middlewares}/errorHandler.js +1 -1
- package/build/transport/http/middlewares/errorHandler.js.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts +42 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -0
- package/build/transport/http/middlewares/scopeAuthMiddleware.js +136 -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 +4 -0
- package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -0
- package/build/transport/http/routes/oauthRoutes.js +474 -0
- package/build/transport/http/routes/oauthRoutes.js.map +1 -0
- package/build/transport/http/routes/sseRoutes.d.ts +4 -0
- package/build/transport/http/routes/sseRoutes.d.ts.map +1 -0
- package/build/{server → transport/http}/routes/sseRoutes.js +12 -10
- package/build/transport/http/routes/sseRoutes.js.map +1 -0
- package/build/transport/http/routes/streamableHttpRoutes.d.ts +4 -0
- package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -0
- package/build/{server → transport/http}/routes/streamableHttpRoutes.js +46 -13
- package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -0
- package/build/{server/expressServer.d.ts → transport/http/server.d.ts} +5 -4
- package/build/transport/http/server.d.ts.map +1 -0
- package/build/{server/expressServer.js → transport/http/server.js} +60 -23
- package/build/transport/http/server.js.map +1 -0
- 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 +14 -14
- package/build/utils/clientFiltering.js.map +1 -1
- package/build/utils/errorHandling.d.ts +0 -11
- package/build/utils/errorHandling.d.ts.map +1 -1
- package/build/utils/errorHandling.js +1 -18
- package/build/utils/errorHandling.js.map +1 -1
- package/build/utils/errorTypes.js +4 -4
- package/build/utils/errorTypes.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 +87 -8
- 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 +23 -9
- package/build/client.d.ts.map +0 -1
- package/build/client.js.map +0 -1
- package/build/clients/clientManager.d.ts.map +0 -1
- package/build/clients/clientManager.js +0 -147
- package/build/clients/clientManager.js.map +0 -1
- package/build/config/configManager.d.ts.map +0 -1
- package/build/config/configManager.js.map +0 -1
- package/build/config/transportConfig.d.ts +0 -7
- package/build/config/transportConfig.d.ts.map +0 -1
- package/build/config/transportConfig.js +0 -90
- package/build/config/transportConfig.js.map +0 -1
- package/build/middleware/loggingMiddleware.d.ts.map +0 -1
- package/build/middleware/loggingMiddleware.js.map +0 -1
- package/build/server/auth/authManager.d.ts +0 -109
- package/build/server/auth/authManager.d.ts.map +0 -1
- package/build/server/auth/authManager.js +0 -173
- package/build/server/auth/authManager.js.map +0 -1
- package/build/server/auth/authMiddleware.d.ts +0 -16
- package/build/server/auth/authMiddleware.d.ts.map +0 -1
- package/build/server/auth/authMiddleware.js +0 -45
- package/build/server/auth/authMiddleware.js.map +0 -1
- package/build/server/auth/sessionManager.d.ts.map +0 -1
- package/build/server/auth/sessionManager.js.map +0 -1
- package/build/server/config/serverConfig.d.ts.map +0 -1
- package/build/server/config/serverConfig.js +0 -117
- package/build/server/config/serverConfig.js.map +0 -1
- package/build/server/errorHandler.d.ts.map +0 -1
- package/build/server/errorHandler.js.map +0 -1
- package/build/server/expressServer.d.ts.map +0 -1
- package/build/server/expressServer.js.map +0 -1
- package/build/server/routes/oauthRoutes.d.ts +0 -14
- package/build/server/routes/oauthRoutes.d.ts.map +0 -1
- package/build/server/routes/oauthRoutes.js +0 -132
- package/build/server/routes/oauthRoutes.js.map +0 -1
- package/build/server/routes/sseRoutes.d.ts +0 -4
- package/build/server/routes/sseRoutes.d.ts.map +0 -1
- package/build/server/routes/sseRoutes.js.map +0 -1
- package/build/server/routes/streamableHttpRoutes.d.ts +0 -4
- package/build/server/routes/streamableHttpRoutes.d.ts.map +0 -1
- package/build/server/routes/streamableHttpRoutes.js.map +0 -1
- package/build/server/tagsExtractor.d.ts.map +0 -1
- package/build/server/tagsExtractor.js.map +0 -1
- package/build/serverManager.d.ts +0 -27
- package/build/serverManager.d.ts.map +0 -1
- package/build/serverManager.js +0 -87
- package/build/serverManager.js.map +0 -1
- package/build/types.d.ts.map +0 -1
- package/build/types.js.map +0 -1
- /package/build/{server → transport/http/middlewares}/errorHandler.d.ts +0 -0
- /package/build/{server → transport/http/middlewares}/tagsExtractor.d.ts +0 -0
- /package/build/{server → transport/http/middlewares}/tagsExtractor.js +0 -0
package/build/constants.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*/
|
|
4
4
|
// Server configuration
|
|
5
5
|
export const PORT = 3050;
|
|
6
|
-
export const HOST = '
|
|
6
|
+
export const HOST = 'localhost';
|
|
7
7
|
// API endpoints
|
|
8
8
|
export const SSE_ENDPOINT = '/sse';
|
|
9
9
|
export const MESSAGES_ENDPOINT = '/messages';
|
|
@@ -11,7 +11,7 @@ export const STREAMABLE_HTTP_ENDPOINT = '/mcp';
|
|
|
11
11
|
// MCP constants
|
|
12
12
|
export const MCP_CONFIG_FILE = 'mcp.json';
|
|
13
13
|
export const MCP_SERVER_NAME = '1mcp';
|
|
14
|
-
export const MCP_SERVER_VERSION = '0.
|
|
14
|
+
export const MCP_SERVER_VERSION = '0.13.0';
|
|
15
15
|
export const MCP_URI_SEPARATOR = '_1mcp_';
|
|
16
16
|
// Global config paths
|
|
17
17
|
export const CONFIG_DIR_NAME = '1mcp';
|
|
@@ -44,26 +44,49 @@ export const CONNECTION_RETRY = {
|
|
|
44
44
|
};
|
|
45
45
|
// Authentication and session settings
|
|
46
46
|
export const AUTH_CONFIG = {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
47
|
+
// Server-side authentication
|
|
48
|
+
SERVER: {
|
|
49
|
+
DEFAULT_ENABLED: false,
|
|
50
|
+
SESSION: {
|
|
51
|
+
TTL_MINUTES: 24 * 60, // 24 hours
|
|
52
|
+
STORAGE_DIR: 'sessions',
|
|
53
|
+
FILE_PREFIX: 'session_',
|
|
54
|
+
FILE_EXTENSION: '.json',
|
|
55
|
+
},
|
|
56
|
+
OAUTH: {
|
|
57
|
+
CODE_TTL_MS: 60 * 1000, // 1 minute
|
|
58
|
+
TOKEN_TTL_MS: 24 * 60 * 60 * 1000, // 24 hours
|
|
59
|
+
},
|
|
60
|
+
PREFIXES: {
|
|
61
|
+
SESSION_ID: 'sess-',
|
|
62
|
+
ACCESS_TOKEN: 'tk-',
|
|
63
|
+
AUTH_CODE: 'code-',
|
|
64
|
+
CLIENT_ID: 'client-',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
// Client-side authentication
|
|
68
|
+
CLIENT: {
|
|
69
|
+
OAUTH: {
|
|
70
|
+
TTL_MS: 30 * 24 * 60 * 60 * 1000, // 30 days
|
|
71
|
+
CODE_VERIFIER_TTL_MS: 10 * 60 * 1000, // 10 minutes
|
|
72
|
+
STATE_TTL_MS: 10 * 60 * 1000, // 10 minutes
|
|
73
|
+
DEFAULT_TOKEN_EXPIRY_SECONDS: 3600, // 1 hour
|
|
74
|
+
DEFAULT_CALLBACK_PATH: '/oauth/callback',
|
|
75
|
+
DEFAULT_SCOPES: [],
|
|
76
|
+
},
|
|
77
|
+
PREFIXES: {
|
|
78
|
+
CLIENT: 'cli_',
|
|
79
|
+
TOKENS: 'tok_',
|
|
80
|
+
VERIFIER: 'ver_',
|
|
81
|
+
STATE: 'sta_',
|
|
82
|
+
},
|
|
60
83
|
},
|
|
61
84
|
};
|
|
62
85
|
// Rate limiting configuration for OAuth endpoints
|
|
63
86
|
export const RATE_LIMIT_CONFIG = {
|
|
64
87
|
OAUTH: {
|
|
65
|
-
WINDOW_MS: 60 * 1000, //
|
|
66
|
-
MAX:
|
|
88
|
+
WINDOW_MS: 15 * 60 * 1000, // 15 minutes
|
|
89
|
+
MAX: 100, // max requests per window per IP
|
|
67
90
|
MESSAGE: { error: 'Too many requests, please try again later.' },
|
|
68
91
|
},
|
|
69
92
|
};
|
package/build/constants.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|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qBAAqB,EAAE,iBAAiB;YACxC,cAAc,EAAE,EAAE;SACnB;QACD,QAAQ,EAAE;YACR,MAAM,EAAE,MAAM;YACd,MAAM,EAAE,MAAM;YACd,QAAQ,EAAE,MAAM;YAChB,KAAK,EAAE,MAAM;SACd;KACF;CACF,CAAC;AAEF,kDAAkD;AAClD,MAAM,CAAC,MAAM,iBAAiB,GAAG;IAC/B,KAAK,EAAE;QACL,SAAS,EAAE,EAAE,GAAG,EAAE,GAAG,IAAI,EAAE,aAAa;QACxC,GAAG,EAAE,GAAG,EAAE,iCAAiC;QAC3C,OAAO,EAAE,EAAE,KAAK,EAAE,4CAA4C,EAAE;KACjE;CACF,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAuB;IACzD,WAAW,EAAE,EAAE;IACf,SAAS,EAAE;QACT,WAAW,EAAE,KAAK;KACnB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,KAAK;KACnB;IACD,OAAO,EAAE;QACP,WAAW,EAAE,KAAK;KACnB;IACD,OAAO,EAAE,EAAE;CACZ,CAAC;AAEF,MAAM,CAAC,MAAM,uBAAuB,GAAuB;IACzD,KAAK,EAAE;QACL,WAAW,EAAE,KAAK;KACnB;IACD,QAAQ,EAAE;QACR,WAAW,EAAE,KAAK;KACnB;IACD,WAAW,EAAE;QACX,WAAW,EAAE,KAAK;KACnB;CACF,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientFactory.d.ts","sourceRoot":"","sources":["../../../src/core/client/clientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AAGnE,wBAA8B,YAAY;;;;;;;;;;;;;;;;;;;;;;IAYzC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Client } from '@modelcontextprotocol/sdk/client/index.js';
|
|
2
|
-
import { MCP_SERVER_NAME, MCP_SERVER_VERSION, MCP_CLIENT_CAPABILITIES } from '
|
|
2
|
+
import { MCP_SERVER_NAME, MCP_SERVER_VERSION, MCP_CLIENT_CAPABILITIES } from '../../constants.js';
|
|
3
3
|
export default async function createClient() {
|
|
4
4
|
const client = new Client({
|
|
5
5
|
name: MCP_SERVER_NAME,
|
|
@@ -9,4 +9,4 @@ export default async function createClient() {
|
|
|
9
9
|
});
|
|
10
10
|
return client;
|
|
11
11
|
}
|
|
12
|
-
//# sourceMappingURL=
|
|
12
|
+
//# sourceMappingURL=clientFactory.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientFactory.js","sourceRoot":"","sources":["../../../src/core/client/clientFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAC;AACnE,OAAO,EAAE,eAAe,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAElG,MAAM,CAAC,OAAO,CAAC,KAAK,UAAU,YAAY;IACxC,MAAM,MAAM,GAAG,IAAI,MAAM,CACvB;QACE,IAAI,EAAE,eAAe;QACrB,OAAO,EAAE,kBAAkB;KAC5B,EACD;QACE,YAAY,EAAE,uBAAuB;KACtC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -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
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clientManager.d.ts","sourceRoot":"","sources":["../../../src/core/client/clientManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,2C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0 +1,209 @@
|
|
|
1
|
+
import { ErrorCode } from '@modelcontextprotocol/sdk/types.js';
|
|
2
|
+
import { UnauthorizedError } from '@modelcontextprotocol/sdk/client/auth.js';
|
|
3
|
+
import createClient from './clientFactory.js';
|
|
4
|
+
import logger from '../../logger/logger.js';
|
|
5
|
+
import { CONNECTION_RETRY, MCP_SERVER_NAME } from '../../constants.js';
|
|
6
|
+
import { ClientConnectionError, ClientNotFoundError, MCPError, CapabilityError } from '../../utils/errorTypes.js';
|
|
7
|
+
import { ClientStatus, } from '../types/index.js';
|
|
8
|
+
import { AgentConfigManager } from '../server/agentConfig.js';
|
|
9
|
+
/**
|
|
10
|
+
* Creates client instances for all transports with retry logic
|
|
11
|
+
* @param transports Record of transport instances
|
|
12
|
+
* @returns Record of client instances
|
|
13
|
+
*/
|
|
14
|
+
export async function createClients(transports) {
|
|
15
|
+
const clients = new Map();
|
|
16
|
+
for (const [name, transport] of Object.entries(transports)) {
|
|
17
|
+
logger.info(`Creating client for ${name}`);
|
|
18
|
+
try {
|
|
19
|
+
const client = await createClient();
|
|
20
|
+
// Connect with retry logic
|
|
21
|
+
const connectedClient = await connectWithRetry(client, transport, name);
|
|
22
|
+
clients.set(name, {
|
|
23
|
+
name,
|
|
24
|
+
transport,
|
|
25
|
+
client: connectedClient,
|
|
26
|
+
status: ClientStatus.Connected,
|
|
27
|
+
lastConnected: new Date(),
|
|
28
|
+
});
|
|
29
|
+
logger.info(`Client created for ${name}`);
|
|
30
|
+
connectedClient.onclose = () => {
|
|
31
|
+
const clientInfo = clients.get(name);
|
|
32
|
+
if (clientInfo) {
|
|
33
|
+
clientInfo.status = ClientStatus.Disconnected;
|
|
34
|
+
}
|
|
35
|
+
logger.info(`Client ${name} disconnected`);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
catch (error) {
|
|
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
|
+
}
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
return clients;
|
|
76
|
+
}
|
|
77
|
+
/**
|
|
78
|
+
* Connects a client to its transport with retry logic and OAuth support
|
|
79
|
+
* @param client The client to connect
|
|
80
|
+
* @param transport The transport to connect to
|
|
81
|
+
* @param name The name of the client for logging
|
|
82
|
+
* @returns The connected client (may be a new instance after retries)
|
|
83
|
+
*/
|
|
84
|
+
async function connectWithRetry(client, transport, name) {
|
|
85
|
+
let retryDelay = CONNECTION_RETRY.INITIAL_DELAY_MS;
|
|
86
|
+
let currentClient = client;
|
|
87
|
+
for (let i = 0; i < CONNECTION_RETRY.MAX_ATTEMPTS; i++) {
|
|
88
|
+
try {
|
|
89
|
+
await currentClient.connect(transport);
|
|
90
|
+
const sv = await currentClient.getServerVersion();
|
|
91
|
+
if (sv?.name === MCP_SERVER_NAME) {
|
|
92
|
+
throw new ClientConnectionError(name, new Error('Aborted to prevent circular dependency'));
|
|
93
|
+
}
|
|
94
|
+
logger.info(`Successfully connected to ${name} with server ${sv?.name} version ${sv?.version}`);
|
|
95
|
+
return currentClient;
|
|
96
|
+
}
|
|
97
|
+
catch (error) {
|
|
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);
|
|
104
|
+
}
|
|
105
|
+
// Handle other connection errors
|
|
106
|
+
else {
|
|
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
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
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'));
|
|
124
|
+
}
|
|
125
|
+
// OAuth authorization flow is now handled by the SDK's built-in implementation
|
|
126
|
+
/**
|
|
127
|
+
* Gets a client by name with error handling
|
|
128
|
+
* @param clients Record of client instances
|
|
129
|
+
* @param clientName The name of the client to get
|
|
130
|
+
* @returns The client instance
|
|
131
|
+
* @throws ClientNotFoundError if the client is not found
|
|
132
|
+
*/
|
|
133
|
+
export function getClient(clients, clientName) {
|
|
134
|
+
const client = clients.get(clientName);
|
|
135
|
+
if (!client) {
|
|
136
|
+
throw new ClientNotFoundError(clientName);
|
|
137
|
+
}
|
|
138
|
+
return client;
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Executes an operation with error handling and retry logic
|
|
142
|
+
* @param operation The operation to execute
|
|
143
|
+
* @param context The execution context (client info or server info)
|
|
144
|
+
* @param options Operation options including timeout and retry settings
|
|
145
|
+
* @returns The result of the operation
|
|
146
|
+
*/
|
|
147
|
+
export async function executeOperation(operation, contextName, options = {}) {
|
|
148
|
+
const { retryCount = 0, retryDelay = 1000 } = options;
|
|
149
|
+
let lastError;
|
|
150
|
+
for (let i = 0; i <= retryCount; i++) {
|
|
151
|
+
try {
|
|
152
|
+
return await operation();
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
lastError = error instanceof Error ? error : new Error(String(error));
|
|
156
|
+
if (i < retryCount) {
|
|
157
|
+
logger.info(`Retrying operation ${operation.name} on ${contextName} after ${retryDelay}ms`);
|
|
158
|
+
await new Promise((resolve) => setTimeout(resolve, retryDelay));
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
// If we get here, we've exhausted all retries
|
|
163
|
+
logger.error(`Operation failed on ${contextName} after ${retryCount + 1} attempts: ${lastError}`);
|
|
164
|
+
if (lastError instanceof MCPError) {
|
|
165
|
+
throw lastError;
|
|
166
|
+
}
|
|
167
|
+
const mcpError = new MCPError(`Error executing operation on ${contextName}`, ErrorCode.InternalError, {
|
|
168
|
+
originalError: lastError,
|
|
169
|
+
});
|
|
170
|
+
throw mcpError;
|
|
171
|
+
}
|
|
172
|
+
/**
|
|
173
|
+
* Executes a client operation with error handling and retry logic
|
|
174
|
+
* @param clients Record of client instances
|
|
175
|
+
* @param clientName The name of the client to use
|
|
176
|
+
* @param operation The operation to execute
|
|
177
|
+
* @param options Operation options including timeout and retry settings
|
|
178
|
+
* @param requiredCapability The capability required for this operation
|
|
179
|
+
*/
|
|
180
|
+
export async function executeClientOperation(clients, clientName, operation, options = {}, requiredCapability) {
|
|
181
|
+
const clientInfo = getClient(clients, clientName);
|
|
182
|
+
if (requiredCapability && !clientInfo.capabilities?.[requiredCapability]) {
|
|
183
|
+
throw new CapabilityError(clientName, String(requiredCapability));
|
|
184
|
+
}
|
|
185
|
+
return executeOperation(() => operation(clientInfo), `client ${clientName}`, options);
|
|
186
|
+
}
|
|
187
|
+
/**
|
|
188
|
+
* Executes a server operation with error handling and retry logic
|
|
189
|
+
* @param server The server to execute the operation on
|
|
190
|
+
* @param operation The operation to execute
|
|
191
|
+
* @param options Operation options including timeout and retry settings
|
|
192
|
+
*/
|
|
193
|
+
export async function executeServerOperation(server, operation, options = {}) {
|
|
194
|
+
return executeOperation(() => operation(server), 'server', options);
|
|
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
|
+
}
|
|
209
|
+
//# sourceMappingURL=clientManager.js.map
|
|
@@ -0,0 +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,EAAE,iBAAiB,EAAE,MAAM,0CAA0C,CAAC;AAC7E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,kBAAqC;IAErC,MAAM,UAAU,GAAG,SAAS,CAAC,OAAO,EAAE,UAAU,CAAC,CAAC;IAElD,IAAI,kBAAkB,IAAI,CAAC,UAAU,CAAC,YAAY,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC;QACzE,MAAM,IAAI,eAAe,CAAC,UAAU,EAAE,MAAM,CAAC,kBAAkB,CAAC,CAAC,CAAC;IACpE,CAAC;IAED,OAAO,gBAAgB,CAAC,GAAG,EAAE,CAAC,SAAS,CAAC,UAAU,CAAC,EAAE,UAAU,UAAU,EAAE,EAAE,OAAO,CAAC,CAAC;AACxF,CAAC;AAED;;;;;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,MAAM,CAAC;IACb,IAAI,EAAE;QACJ,OAAO,EAAE,OAAO,CAAC;QACjB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,kBAAkB,CAAC,EAAE,MAAM,CAAC;QAC5B,cAAc,EAAE,MAAM,CAAC;QACvB,eAAe,EAAE,MAAM,CAAC;KACzB,CAAC;IACF,SAAS,EAAE;QACT,QAAQ,EAAE,MAAM,CAAC;QACjB,GAAG,EAAE,MAAM,CAAC;KACb,CAAC;IACF,QAAQ,EAAE;QACR,IAAI,EAAE,OAAO,CAAC;QACd,eAAe,EAAE,OAAO,CAAC;QACzB,gBAAgB,EAAE,OAAO,CAAC;KAC3B,CAAC;CACH;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAqB;IAC5C,OAAO,CAAC,MAAM,CAAc;IAE5B;;;;;OAKG;IACH,OAAO;IAsBP;;;;;;;OAOG;WACW,WAAW,IAAI,kBAAkB;IAO/C;;;;;;;OAOG;IACI,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,WAAW,CAAC,GAAG,IAAI;IAaxD;;;;;;;OAOG;IACI,SAAS,IAAI,WAAW;IAI/B;;;;OAIG;IACI,aAAa,IAAI,OAAO;IAI/B;;;;OAIG;IACI,oBAAoB,IAAI,MAAM;IAIrC;;;;OA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