@1mcp/agent 0.13.0 → 0.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.
Files changed (125) hide show
  1. package/README.md +28 -20
  2. package/build/auth/sdkOAuthClientProvider.d.ts +1 -1
  3. package/build/auth/sdkOAuthClientProvider.d.ts.map +1 -1
  4. package/build/auth/sdkOAuthClientProvider.js +11 -6
  5. package/build/auth/sdkOAuthClientProvider.js.map +1 -1
  6. package/build/auth/sdkOAuthServerProvider.d.ts +4 -3
  7. package/build/auth/sdkOAuthServerProvider.d.ts.map +1 -1
  8. package/build/auth/sdkOAuthServerProvider.js +41 -110
  9. package/build/auth/sdkOAuthServerProvider.js.map +1 -1
  10. package/build/auth/sessionTypes.d.ts +24 -10
  11. package/build/auth/sessionTypes.d.ts.map +1 -1
  12. package/build/auth/storage/authCodeRepository.d.ts +25 -0
  13. package/build/auth/storage/authCodeRepository.d.ts.map +1 -0
  14. package/build/auth/storage/authCodeRepository.js +50 -0
  15. package/build/auth/storage/authCodeRepository.js.map +1 -0
  16. package/build/auth/storage/authRequestRepository.d.ts +25 -0
  17. package/build/auth/storage/authRequestRepository.d.ts.map +1 -0
  18. package/build/auth/storage/authRequestRepository.js +51 -0
  19. package/build/auth/storage/authRequestRepository.js.map +1 -0
  20. package/build/auth/storage/clientDataRepository.d.ts +25 -0
  21. package/build/auth/storage/clientDataRepository.d.ts.map +1 -0
  22. package/build/auth/storage/clientDataRepository.js +45 -0
  23. package/build/auth/storage/clientDataRepository.js.map +1 -0
  24. package/build/auth/storage/clientSessionRepository.d.ts +77 -0
  25. package/build/auth/storage/clientSessionRepository.d.ts.map +1 -0
  26. package/build/auth/storage/clientSessionRepository.js +120 -0
  27. package/build/auth/storage/clientSessionRepository.js.map +1 -0
  28. package/build/auth/storage/fileStorageService.d.ts +68 -0
  29. package/build/auth/storage/fileStorageService.d.ts.map +1 -0
  30. package/build/auth/storage/fileStorageService.js +262 -0
  31. package/build/auth/storage/fileStorageService.js.map +1 -0
  32. package/build/auth/storage/oauthStorageService.d.ts +57 -0
  33. package/build/auth/storage/oauthStorageService.d.ts.map +1 -0
  34. package/build/auth/storage/oauthStorageService.js +131 -0
  35. package/build/auth/storage/oauthStorageService.js.map +1 -0
  36. package/build/auth/storage/sessionRepository.d.ts +29 -0
  37. package/build/auth/storage/sessionRepository.d.ts.map +1 -0
  38. package/build/auth/storage/sessionRepository.js +64 -0
  39. package/build/auth/storage/sessionRepository.js.map +1 -0
  40. package/build/constants.d.ts +26 -11
  41. package/build/constants.d.ts.map +1 -1
  42. package/build/constants.js +32 -11
  43. package/build/constants.js.map +1 -1
  44. package/build/core/client/clientManager.d.ts +55 -39
  45. package/build/core/client/clientManager.d.ts.map +1 -1
  46. package/build/core/client/clientManager.js +180 -171
  47. package/build/core/client/clientManager.js.map +1 -1
  48. package/build/core/server/agentConfig.d.ts +13 -0
  49. package/build/core/server/agentConfig.d.ts.map +1 -1
  50. package/build/core/server/agentConfig.js +18 -2
  51. package/build/core/server/agentConfig.js.map +1 -1
  52. package/build/core/server/serverManager.d.ts +11 -4
  53. package/build/core/server/serverManager.d.ts.map +1 -1
  54. package/build/core/server/serverManager.js +47 -23
  55. package/build/core/server/serverManager.js.map +1 -1
  56. package/build/core/types/server.d.ts +17 -0
  57. package/build/core/types/server.d.ts.map +1 -1
  58. package/build/core/types/server.js +14 -1
  59. package/build/core/types/server.js.map +1 -1
  60. package/build/handlers/notificationHandlers.d.ts +2 -2
  61. package/build/handlers/notificationHandlers.d.ts.map +1 -1
  62. package/build/handlers/notificationHandlers.js +15 -10
  63. package/build/handlers/notificationHandlers.js.map +1 -1
  64. package/build/handlers/requestHandlers.d.ts +1 -1
  65. package/build/handlers/requestHandlers.d.ts.map +1 -1
  66. package/build/handlers/requestHandlers.js +68 -67
  67. package/build/handlers/requestHandlers.js.map +1 -1
  68. package/build/index.js +7 -0
  69. package/build/index.js.map +1 -1
  70. package/build/logger/mcpLoggingEnhancer.d.ts.map +1 -1
  71. package/build/logger/mcpLoggingEnhancer.js +18 -1
  72. package/build/logger/mcpLoggingEnhancer.js.map +1 -1
  73. package/build/server.d.ts.map +1 -1
  74. package/build/server.js +3 -2
  75. package/build/server.js.map +1 -1
  76. package/build/services/configReloadService.d.ts.map +1 -1
  77. package/build/services/configReloadService.js +3 -2
  78. package/build/services/configReloadService.js.map +1 -1
  79. package/build/transport/http/middlewares/httpRequestLogger.d.ts +16 -0
  80. package/build/transport/http/middlewares/httpRequestLogger.d.ts.map +1 -0
  81. package/build/transport/http/middlewares/httpRequestLogger.js +41 -0
  82. package/build/transport/http/middlewares/httpRequestLogger.js.map +1 -0
  83. package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts +4 -7
  84. package/build/transport/http/middlewares/scopeAuthMiddleware.d.ts.map +1 -1
  85. package/build/transport/http/middlewares/scopeAuthMiddleware.js +6 -12
  86. package/build/transport/http/middlewares/scopeAuthMiddleware.js.map +1 -1
  87. package/build/transport/http/routes/oauthRoutes.d.ts +6 -2
  88. package/build/transport/http/routes/oauthRoutes.d.ts.map +1 -1
  89. package/build/transport/http/routes/oauthRoutes.js +333 -337
  90. package/build/transport/http/routes/oauthRoutes.js.map +1 -1
  91. package/build/transport/http/routes/sseRoutes.d.ts.map +1 -1
  92. package/build/transport/http/routes/sseRoutes.js +11 -5
  93. package/build/transport/http/routes/sseRoutes.js.map +1 -1
  94. package/build/transport/http/routes/streamableHttpRoutes.d.ts.map +1 -1
  95. package/build/transport/http/routes/streamableHttpRoutes.js +11 -10
  96. package/build/transport/http/routes/streamableHttpRoutes.js.map +1 -1
  97. package/build/transport/http/server.d.ts +1 -0
  98. package/build/transport/http/server.d.ts.map +1 -1
  99. package/build/transport/http/server.js +11 -5
  100. package/build/transport/http/server.js.map +1 -1
  101. package/build/transport/transportFactory.js +2 -2
  102. package/build/transport/transportFactory.js.map +1 -1
  103. package/build/utils/clientFiltering.d.ts.map +1 -1
  104. package/build/utils/clientFiltering.js +40 -5
  105. package/build/utils/clientFiltering.js.map +1 -1
  106. package/build/utils/operationExecution.d.ts +10 -0
  107. package/build/utils/operationExecution.d.ts.map +1 -0
  108. package/build/utils/operationExecution.js +36 -0
  109. package/build/utils/operationExecution.js.map +1 -0
  110. package/build/utils/pagination.d.ts.map +1 -1
  111. package/build/utils/pagination.js +22 -13
  112. package/build/utils/pagination.js.map +1 -1
  113. package/package.json +1 -1
  114. package/build/auth/clientSessionManager.d.ts +0 -94
  115. package/build/auth/clientSessionManager.d.ts.map +0 -1
  116. package/build/auth/clientSessionManager.js +0 -220
  117. package/build/auth/clientSessionManager.js.map +0 -1
  118. package/build/auth/serverSessionManager.d.ts +0 -185
  119. package/build/auth/serverSessionManager.d.ts.map +0 -1
  120. package/build/auth/serverSessionManager.js +0 -461
  121. package/build/auth/serverSessionManager.js.map +0 -1
  122. package/build/core/client/clientFactory.d.ts +0 -25
  123. package/build/core/client/clientFactory.d.ts.map +0 -1
  124. package/build/core/client/clientFactory.js +0 -12
  125. package/build/core/client/clientFactory.js.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authCodeRepository.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/authCodeRepository.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,kBAAkB;IACjB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,kBAAkB;IAE/C;;OAEG;IACH,MAAM,CACJ,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,QAAQ,EAAE,MAAM,EAChB,MAAM,EAAE,MAAM,EAAE,EAChB,KAAK,EAAE,MAAM,EACb,aAAa,CAAC,EAAE,MAAM,GACrB,MAAM;IAiBT;;OAEG;IACH,GAAG,CAAC,IAAI,EAAE,MAAM,GAAG,YAAY,GAAG,IAAI;IAItC;;OAEG;IACH,MAAM,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO;CAO9B"}
@@ -0,0 +1,50 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import logger from '../../logger/logger.js';
3
+ import { AUTH_CONFIG } from '../../constants.js';
4
+ /**
5
+ * Repository for authorization code operations
6
+ *
7
+ * Manages OAuth 2.1 authorization codes for token exchange.
8
+ * Authorization codes are short-lived (1 minute) and single-use.
9
+ */
10
+ export class AuthCodeRepository {
11
+ storage;
12
+ constructor(storage) {
13
+ this.storage = storage;
14
+ }
15
+ /**
16
+ * Creates a new authorization code
17
+ */
18
+ create(clientId, redirectUri, resource, scopes, ttlMs, codeChallenge) {
19
+ const code = AUTH_CONFIG.SERVER.AUTH_CODE.ID_PREFIX + randomUUID();
20
+ const authCodeData = {
21
+ clientId,
22
+ redirectUri,
23
+ resource,
24
+ scopes,
25
+ codeChallenge,
26
+ expires: Date.now() + ttlMs,
27
+ createdAt: Date.now(),
28
+ };
29
+ this.storage.writeData(AUTH_CONFIG.SERVER.AUTH_CODE.FILE_PREFIX, code, authCodeData);
30
+ logger.info(`Created auth code: ${code} for client: ${clientId}`);
31
+ return code;
32
+ }
33
+ /**
34
+ * Retrieves authorization code data by code
35
+ */
36
+ get(code) {
37
+ return this.storage.readData(AUTH_CONFIG.SERVER.AUTH_CODE.FILE_PREFIX, code);
38
+ }
39
+ /**
40
+ * Deletes an authorization code by code
41
+ */
42
+ delete(code) {
43
+ const result = this.storage.deleteData(AUTH_CONFIG.SERVER.AUTH_CODE.FILE_PREFIX, code);
44
+ if (result) {
45
+ logger.info(`Deleted auth code: ${code}`);
46
+ }
47
+ return result;
48
+ }
49
+ }
50
+ //# sourceMappingURL=authCodeRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authCodeRepository.js","sourceRoot":"","sources":["../../../src/auth/storage/authCodeRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,MAAM,MAAM,wBAAw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AAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ import { AuthRequestData } from '../sessionTypes.js';
2
+ import { FileStorageService } from './fileStorageService.js';
3
+ /**
4
+ * Repository for authorization request operations
5
+ *
6
+ * Manages temporary authorization requests used in the consent flow.
7
+ * These store OAuth parameters securely server-side while user reviews consent.
8
+ */
9
+ export declare class AuthRequestRepository {
10
+ private storage;
11
+ constructor(storage: FileStorageService);
12
+ /**
13
+ * Creates a new authorization request
14
+ */
15
+ create(clientId: string, redirectUri: string, codeChallenge?: string, state?: string, resource?: string, scopes?: string[]): string;
16
+ /**
17
+ * Retrieves authorization request data by ID
18
+ */
19
+ get(authRequestId: string): AuthRequestData | null;
20
+ /**
21
+ * Deletes an authorization request by ID
22
+ */
23
+ delete(authRequestId: string): boolean;
24
+ }
25
+ //# sourceMappingURL=authRequestRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authRequestRepository.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/authRequestRepository.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAC;AACrD,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAE7D;;;;;GAKG;AACH,qBAAa,qBAAqB;IACpB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,kBAAkB;IAE/C;;OAEG;IACH,MAAM,CACJ,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,aAAa,CAAC,EAAE,MAAM,EACtB,KAAK,CAAC,EAAE,MAAM,EACd,QAAQ,CAAC,EAAE,MAAM,EACjB,MAAM,CAAC,EAAE,MAAM,EAAE,GAChB,MAAM;IAkBT;;OAEG;IACH,GAAG,CAAC,aAAa,EAAE,MAAM,GAAG,eAAe,GAAG,IAAI;IAIlD;;OAEG;IACH,MAAM,CAAC,aAAa,EAAE,MAAM,GAAG,OAAO;CAOvC"}
@@ -0,0 +1,51 @@
1
+ import { randomUUID } from 'node:crypto';
2
+ import logger from '../../logger/logger.js';
3
+ import { AUTH_CONFIG } from '../../constants.js';
4
+ /**
5
+ * Repository for authorization request operations
6
+ *
7
+ * Manages temporary authorization requests used in the consent flow.
8
+ * These store OAuth parameters securely server-side while user reviews consent.
9
+ */
10
+ export class AuthRequestRepository {
11
+ storage;
12
+ constructor(storage) {
13
+ this.storage = storage;
14
+ }
15
+ /**
16
+ * Creates a new authorization request
17
+ */
18
+ create(clientId, redirectUri, codeChallenge, state, resource, scopes) {
19
+ const authRequestId = AUTH_CONFIG.SERVER.AUTH_REQUEST.ID_PREFIX + randomUUID();
20
+ const authRequestData = {
21
+ clientId,
22
+ redirectUri,
23
+ codeChallenge,
24
+ state,
25
+ resource,
26
+ scopes,
27
+ expires: Date.now() + AUTH_CONFIG.SERVER.AUTH_REQUEST.TTL_MS,
28
+ createdAt: Date.now(),
29
+ };
30
+ this.storage.writeData(AUTH_CONFIG.SERVER.AUTH_REQUEST.FILE_PREFIX, authRequestId, authRequestData);
31
+ logger.info(`Created auth request: ${authRequestId} for client: ${clientId}`);
32
+ return authRequestId;
33
+ }
34
+ /**
35
+ * Retrieves authorization request data by ID
36
+ */
37
+ get(authRequestId) {
38
+ return this.storage.readData(AUTH_CONFIG.SERVER.AUTH_REQUEST.FILE_PREFIX, authRequestId);
39
+ }
40
+ /**
41
+ * Deletes an authorization request by ID
42
+ */
43
+ delete(authRequestId) {
44
+ const result = this.storage.deleteData(AUTH_CONFIG.SERVER.AUTH_REQUEST.FILE_PREFIX, authRequestId);
45
+ if (result) {
46
+ logger.info(`Deleted auth request: ${authRequestId}`);
47
+ }
48
+ return result;
49
+ }
50
+ }
51
+ //# sourceMappingURL=authRequestRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"authRequestRepository.js","sourceRoot":"","sources":["../../../src/auth/storage/authRequestRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,MAAM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,IAAI,CAAC,yBAAyB,aAAa,EAAE,CAAC,CAAC;QACxD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,25 @@
1
+ import { FileStorageService } from './fileStorageService.js';
2
+ import { OAuthClientInformationFull } from '@modelcontextprotocol/sdk/shared/auth.js';
3
+ /**
4
+ * Repository for OAuth client data operations
5
+ *
6
+ * Manages registered OAuth client information with automatic expiration.
7
+ * Client data is stored for a configurable period (default 30 days).
8
+ */
9
+ export declare class ClientDataRepository {
10
+ private storage;
11
+ constructor(storage: FileStorageService);
12
+ /**
13
+ * Saves OAuth client data
14
+ */
15
+ save(clientId: string, data: OAuthClientInformationFull, ttlMs: number): string;
16
+ /**
17
+ * Retrieves OAuth client data by client ID
18
+ */
19
+ get(clientId: string): OAuthClientInformationFull | null;
20
+ /**
21
+ * Deletes OAuth client data by client ID
22
+ */
23
+ delete(clientId: string): boolean;
24
+ }
25
+ //# sourceMappingURL=clientDataRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientDataRepository.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/clientDataRepository.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AAEtF;;;;;GAKG;AACH,qBAAa,oBAAoB;IACnB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,kBAAkB;IAE/C;;OAEG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,0BAA0B,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAY/E;;OAEG;IACH,GAAG,CAAC,QAAQ,EAAE,MAAM,GAAG,0BAA0B,GAAG,IAAI;IAKxD;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;CAOlC"}
@@ -0,0 +1,45 @@
1
+ import logger from '../../logger/logger.js';
2
+ import { AUTH_CONFIG } from '../../constants.js';
3
+ /**
4
+ * Repository for OAuth client data operations
5
+ *
6
+ * Manages registered OAuth client information with automatic expiration.
7
+ * Client data is stored for a configurable period (default 30 days).
8
+ */
9
+ export class ClientDataRepository {
10
+ storage;
11
+ constructor(storage) {
12
+ this.storage = storage;
13
+ }
14
+ /**
15
+ * Saves OAuth client data
16
+ */
17
+ save(clientId, data, ttlMs) {
18
+ const clientData = {
19
+ ...data,
20
+ expires: data.client_secret_expires_at ? data.client_secret_expires_at * 1000 : Date.now() + ttlMs,
21
+ createdAt: data.client_id_issued_at ? data.client_id_issued_at * 1000 : Date.now(),
22
+ };
23
+ this.storage.writeData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, clientId, clientData);
24
+ logger.info(`Saved client data: ${clientId}`);
25
+ return clientId;
26
+ }
27
+ /**
28
+ * Retrieves OAuth client data by client ID
29
+ */
30
+ get(clientId) {
31
+ const clientData = this.storage.readData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, clientId);
32
+ return clientData;
33
+ }
34
+ /**
35
+ * Deletes OAuth client data by client ID
36
+ */
37
+ delete(clientId) {
38
+ const result = this.storage.deleteData(AUTH_CONFIG.SERVER.SESSION.FILE_PREFIX, clientId);
39
+ if (result) {
40
+ logger.info(`Deleted client data: ${clientId}`);
41
+ }
42
+ return result;
43
+ }
44
+ }
45
+ //# sourceMappingURL=clientDataRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientDataRepository.js","sourceRoot":"","sources":["../../../src/auth/storage/clientDataRepository.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAKjD;;;;;GAKG;AACH,MAAM,OAAO,oBAAoB;IACX;IAApB,YAAoB,OAA2B;QAA3B,YAAO,GAAP,OAAO,CAAoB;IAAG,CAAC;IAEnD;;OAEG;IACH,IAAI,CAAC,QAAgB,EAAE,IAAgC,EAAE,KAAa;QACpE,MAAM,UAAU,GAAe;YAC7B,GAAG,IAAI;YACP,OAAO,EAAE,IAAI,CAAC,wBAAwB,CAAC,CAAC,CAAC,IAAI,CAAC,wBAAwB,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE,GAAG,KAAK;YAClG,SAAS,EAAE,IAAI,CAAC,mBAAmB,CAAC,CAAC,CAAC,IAAI,CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC,CAAC,IAAI,CAAC,GAAG,EAAE;SACnF,CAAC;QAEF,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,EAAE,UAAU,CAAC,CAAC;QACrF,MAAM,CAAC,IAAI,CAAC,sBAAsB,QAAQ,EAAE,CAAC,CAAC;QAC9C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED;;OAEG;IACH,GAAG,CAAC,QAAgB;QAClB,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,QAAQ,CAAa,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACvG,OAAO,UAAU,CAAC;IACpB,CAAC;IAED;;OAEG;IACH,MAAM,CAAC,QAAgB;QACrB,MAAM,MAAM,GAAG,IAAI,CAAC,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,EAAE,QAAQ,CAAC,CAAC;QACzF,IAAI,MAAM,EAAE,CAAC;YACX,MAAM,CAAC,IAAI,CAAC,wBAAwB,QAAQ,EAAE,CAAC,CAAC;QAClD,CAAC;QACD,OAAO,MAAM,CAAC;IAChB,CAAC;CACF"}
@@ -0,0 +1,77 @@
1
+ import { FileStorageService } from './fileStorageService.js';
2
+ import { ClientSessionData } from '../sessionTypes.js';
3
+ /**
4
+ * ClientSessionRepository handles OAuth 2.1 client session storage using the layered storage architecture.
5
+ *
6
+ * This repository manages client sessions for OAuth connections to downstream MCP servers.
7
+ * It follows the same patterns as other repositories (SessionRepository, AuthCodeRepository, etc.)
8
+ * and uses the FileStorageService for consistent data management.
9
+ *
10
+ * Features:
11
+ * - Repository pattern with FileStorageService backend
12
+ * - Server name sanitization for security
13
+ * - Automatic expiration handling
14
+ * - Consistent with other storage repositories
15
+ * - Type-safe client session data management
16
+ *
17
+ * @example
18
+ * ```typescript
19
+ * const storage = new FileStorageService('/path/to/sessions');
20
+ * const repository = new ClientSessionRepository(storage);
21
+ *
22
+ * const sessionData = {
23
+ * serverName: 'test-server',
24
+ * clientInfo: JSON.stringify(clientInfo),
25
+ * tokens: JSON.stringify(tokens),
26
+ * expires: Date.now() + 3600000,
27
+ * createdAt: Date.now()
28
+ * };
29
+ *
30
+ * repository.save('test-server', sessionData, 3600000);
31
+ * const session = repository.get('test-server');
32
+ * ```
33
+ */
34
+ export declare class ClientSessionRepository {
35
+ private storage;
36
+ constructor(storage: FileStorageService);
37
+ /**
38
+ * Saves or updates a client session.
39
+ *
40
+ * @param serverName - The server name for the client session
41
+ * @param clientSessionData - The client session data to store
42
+ * @param ttlMs - Time to live in milliseconds
43
+ * @returns The sanitized server name used as key
44
+ */
45
+ save(serverName: string, clientSessionData: ClientSessionData, ttlMs: number): string;
46
+ /**
47
+ * Retrieves client session data by server name.
48
+ *
49
+ * @param serverName - The server name to retrieve client session for
50
+ * @returns Client session data if exists and not expired, null otherwise
51
+ */
52
+ get(serverName: string): ClientSessionData | null;
53
+ /**
54
+ * Deletes a client session by server name.
55
+ *
56
+ * @param serverName - The server name to delete client session for
57
+ * @returns True if client session was deleted, false if it didn't exist
58
+ */
59
+ delete(serverName: string): boolean;
60
+ /**
61
+ * Lists all client session server names.
62
+ *
63
+ * This method scans the storage for client session files and extracts
64
+ * the server names from the file names.
65
+ *
66
+ * @returns Array of server names that have client sessions
67
+ */
68
+ list(): string[];
69
+ /**
70
+ * Creates a standardized session ID for the server name.
71
+ *
72
+ * @param sanitizedServerName - The sanitized server name
73
+ * @returns The session ID for storage
74
+ */
75
+ private getSessionId;
76
+ }
77
+ //# sourceMappingURL=clientSessionRepository.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientSessionRepository.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/clientSessionRepository.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AAC7D,OAAO,EAAE,iBAAiB,EAAE,MAAM,oBAAoB,CAAC;AAKvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,qBAAa,uBAAuB;IACtB,OAAO,CAAC,OAAO;gBAAP,OAAO,EAAE,kBAAkB;IAE/C;;;;;;;OAOG;IACH,IAAI,CAAC,UAAU,EAAE,MAAM,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM;IAerF;;;;;OAKG;IACH,GAAG,CAAC,UAAU,EAAE,MAAM,GAAG,iBAAiB,GAAG,IAAI;IAOjD;;;;;OAKG;IACH,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,OAAO;IAOnC;;;;;;;OAOG;IACH,IAAI,IAAI,MAAM,EAAE;IA0BhB;;;;;OAKG;IACH,OAAO,CAAC,YAAY;CAGrB"}
@@ -0,0 +1,120 @@
1
+ import { AUTH_CONFIG } from '../../constants.js';
2
+ import { sanitizeServerName } from '../../utils/sanitization.js';
3
+ import logger from '../../logger/logger.js';
4
+ /**
5
+ * ClientSessionRepository handles OAuth 2.1 client session storage using the layered storage architecture.
6
+ *
7
+ * This repository manages client sessions for OAuth connections to downstream MCP servers.
8
+ * It follows the same patterns as other repositories (SessionRepository, AuthCodeRepository, etc.)
9
+ * and uses the FileStorageService for consistent data management.
10
+ *
11
+ * Features:
12
+ * - Repository pattern with FileStorageService backend
13
+ * - Server name sanitization for security
14
+ * - Automatic expiration handling
15
+ * - Consistent with other storage repositories
16
+ * - Type-safe client session data management
17
+ *
18
+ * @example
19
+ * ```typescript
20
+ * const storage = new FileStorageService('/path/to/sessions');
21
+ * const repository = new ClientSessionRepository(storage);
22
+ *
23
+ * const sessionData = {
24
+ * serverName: 'test-server',
25
+ * clientInfo: JSON.stringify(clientInfo),
26
+ * tokens: JSON.stringify(tokens),
27
+ * expires: Date.now() + 3600000,
28
+ * createdAt: Date.now()
29
+ * };
30
+ *
31
+ * repository.save('test-server', sessionData, 3600000);
32
+ * const session = repository.get('test-server');
33
+ * ```
34
+ */
35
+ export class ClientSessionRepository {
36
+ storage;
37
+ constructor(storage) {
38
+ this.storage = storage;
39
+ }
40
+ /**
41
+ * Saves or updates a client session.
42
+ *
43
+ * @param serverName - The server name for the client session
44
+ * @param clientSessionData - The client session data to store
45
+ * @param ttlMs - Time to live in milliseconds
46
+ * @returns The sanitized server name used as key
47
+ */
48
+ save(serverName, clientSessionData, ttlMs) {
49
+ const sanitizedServerName = sanitizeServerName(serverName);
50
+ const sessionId = this.getSessionId(sanitizedServerName);
51
+ const dataWithExpiry = {
52
+ ...clientSessionData,
53
+ expires: Date.now() + ttlMs,
54
+ createdAt: clientSessionData.createdAt || Date.now(),
55
+ };
56
+ this.storage.writeData(AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX, sessionId, dataWithExpiry);
57
+ logger.info(`Saved client session for server: ${serverName}`);
58
+ return sanitizedServerName;
59
+ }
60
+ /**
61
+ * Retrieves client session data by server name.
62
+ *
63
+ * @param serverName - The server name to retrieve client session for
64
+ * @returns Client session data if exists and not expired, null otherwise
65
+ */
66
+ get(serverName) {
67
+ const sanitizedServerName = sanitizeServerName(serverName);
68
+ const sessionId = this.getSessionId(sanitizedServerName);
69
+ return this.storage.readData(AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX, sessionId);
70
+ }
71
+ /**
72
+ * Deletes a client session by server name.
73
+ *
74
+ * @param serverName - The server name to delete client session for
75
+ * @returns True if client session was deleted, false if it didn't exist
76
+ */
77
+ delete(serverName) {
78
+ const sanitizedServerName = sanitizeServerName(serverName);
79
+ const sessionId = this.getSessionId(sanitizedServerName);
80
+ return this.storage.deleteData(AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX, sessionId);
81
+ }
82
+ /**
83
+ * Lists all client session server names.
84
+ *
85
+ * This method scans the storage for client session files and extracts
86
+ * the server names from the file names.
87
+ *
88
+ * @returns Array of server names that have client sessions
89
+ */
90
+ list() {
91
+ // Concatenate FILE_PREFIX and ID_PREFIX to get the full prefix pattern
92
+ const fullPrefix = AUTH_CONFIG.CLIENT.SESSION.FILE_PREFIX + AUTH_CONFIG.CLIENT.SESSION.ID_PREFIX;
93
+ // Get all files that match the full prefix pattern
94
+ const files = this.storage.listFiles(fullPrefix);
95
+ // Extract server names from file names
96
+ return files
97
+ .map((file) => {
98
+ // Remove full prefix and .json suffix to get the server name
99
+ let serverName = file;
100
+ if (serverName.startsWith(fullPrefix)) {
101
+ serverName = serverName.substring(fullPrefix.length);
102
+ }
103
+ if (serverName.endsWith('.json')) {
104
+ serverName = serverName.substring(0, serverName.length - 5);
105
+ }
106
+ return serverName;
107
+ })
108
+ .filter((serverName) => serverName.length > 0);
109
+ }
110
+ /**
111
+ * Creates a standardized session ID for the server name.
112
+ *
113
+ * @param sanitizedServerName - The sanitized server name
114
+ * @returns The session ID for storage
115
+ */
116
+ getSessionId(sanitizedServerName) {
117
+ return `${AUTH_CONFIG.CLIENT.SESSION.ID_PREFIX}${sanitizedServerName}`;
118
+ }
119
+ }
120
+ //# sourceMappingURL=clientSessionRepository.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"clientSessionRepository.js","sourceRoot":"","sources":["../../../src/auth/storage/clientSessionRepository.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,kBAAkB,EAAE,MAAM,6BAA6B,CAAC;AACjE,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAE5C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;A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AM,CAAC,OAAO,CAAC,WAAW,EAAE,SAAS,CAAC,CAAC;IACpF,CAAC;IAED;;;;;;;OAOG;IACH,IAAI;QACF,uEAAuE;QACvE,MAAM,UAAU,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,WAAW,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC;QAEjG,mDAAmD;QACnD,MAAM,KAAK,GAAG,IAAI,CAAC,OAAO,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QAEjD,uCAAuC;QACvC,OAAO,KAAK;aACT,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE;YACZ,6DAA6D;YAC7D,IAAI,UAAU,GAAG,IAAI,CAAC;YAEtB,IAAI,UAAU,CAAC,UAAU,CAAC,UAAU,CAAC,EAAE,CAAC;gBACtC,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC;YACvD,CAAC;YAED,IAAI,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC;gBACjC,UAAU,GAAG,UAAU,CAAC,SAAS,CAAC,CAAC,EAAE,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;YAC9D,CAAC;YAED,OAAO,UAAU,CAAC;QACpB,CAAC,CAAC;aACD,MAAM,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,UAAU,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;IACnD,CAAC;IAED;;;;;OAKG;IACK,YAAY,CAAC,mBAA2B;QAC9C,OAAO,GAAG,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,GAAG,mBAAmB,EAAE,CAAC;IACzE,CAAC;CACF"}
@@ -0,0 +1,68 @@
1
+ import { ExpirableData } from '../sessionTypes.js';
2
+ /**
3
+ * Generic file storage service with unified cleanup for all expirable data types.
4
+ *
5
+ * This service provides a common foundation for storing sessions, auth codes,
6
+ * auth requests, and client data with automatic cleanup of expired items.
7
+ *
8
+ * Features:
9
+ * - Generic CRUD operations for any expirable data type
10
+ * - Unified periodic cleanup every 5 minutes
11
+ * - Path traversal protection
12
+ * - Automatic directory creation
13
+ * - Corruption handling (removes corrupted files)
14
+ */
15
+ export declare class FileStorageService {
16
+ private storageDir;
17
+ private cleanupInterval;
18
+ constructor(storageDir?: string);
19
+ /**
20
+ * Ensures the storage directory exists
21
+ */
22
+ private ensureDirectory;
23
+ /**
24
+ * Gets the file path for a given prefix and ID
25
+ */
26
+ getFilePath(filePrefix: string, id: string): string;
27
+ /**
28
+ * Validates ID format for security
29
+ */
30
+ private isValidId;
31
+ /**
32
+ * Writes data to a file with the specified prefix and ID
33
+ */
34
+ writeData<T extends ExpirableData>(filePrefix: string, id: string, data: T): void;
35
+ /**
36
+ * Reads data from a file with the specified prefix and ID
37
+ * Returns null if file doesn't exist or data is expired
38
+ */
39
+ readData<T extends ExpirableData>(filePrefix: string, id: string): T | null;
40
+ /**
41
+ * Deletes data file with the specified prefix and ID
42
+ */
43
+ deleteData(filePrefix: string, id: string): boolean;
44
+ /**
45
+ * Starts periodic cleanup of expired data files
46
+ */
47
+ private startPeriodicCleanup;
48
+ /**
49
+ * Unified cleanup for all expired data types
50
+ */
51
+ cleanupExpiredData(): number;
52
+ /**
53
+ * Lists all files in the storage directory that match a given prefix.
54
+ *
55
+ * @param filePrefix - The file prefix to filter by (optional)
56
+ * @returns Array of file names (without directory path)
57
+ */
58
+ listFiles(filePrefix?: string): string[];
59
+ /**
60
+ * Gets the storage directory path
61
+ */
62
+ getStorageDir(): string;
63
+ /**
64
+ * Graceful shutdown - stops cleanup interval
65
+ */
66
+ shutdown(): void;
67
+ }
68
+ //# sourceMappingURL=fileStorageService.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fileStorageService.d.ts","sourceRoot":"","sources":["../../../src/auth/storage/fileStorageService.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,qBAAa,kBAAkB;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,eAAe,CAA+C;gBAE1D,UAAU,CAAC,EAAE,MAAM;IAM/B;;OAEG;IACH,OAAO,CAAC,eAAe;IAYvB;;OAEG;IACI,WAAW,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,MAAM;IAmB1D;;OAEG;IACH,OAAO,CAAC,SAAS;IAiDjB;;OAEG;IACH,SAAS,CAAC,CAAC,SAAS,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,GAAG,IAAI;IAWjF;;;OAGG;IACH,QAAQ,CAAC,CAAC,SAAS,aAAa,EAAE,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,CAAC,GAAG,IAAI;IA4B3E;;OAEG;IACH,UAAU,CAAC,UAAU,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,GAAG,OAAO;IAoBnD;;OAEG;IACH,OAAO,CAAC,oBAAoB;IAU5B;;OAEG;IACI,kBAAkB,IAAI,MAAM;IAyCnC;;;;;OAKG;IACH,SAAS,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE;IAwBxC;;OAEG;IACH,aAAa,IAAI,MAAM;IAIvB;;OAEG;IACH,QAAQ,IAAI,IAAI;CAOjB"}