@1mcp/agent 0.10.1 → 0.11.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 +14 -0
- package/build/clients/clientManager.d.ts +3 -2
- package/build/clients/clientManager.d.ts.map +1 -1
- package/build/clients/clientManager.js +10 -2
- package/build/clients/clientManager.js.map +1 -1
- package/build/constants.d.ts +25 -1
- package/build/constants.d.ts.map +1 -1
- package/build/constants.js +31 -2
- package/build/constants.js.map +1 -1
- package/build/handlers/notificationHandlers.d.ts.map +1 -1
- package/build/handlers/notificationHandlers.js +41 -14
- package/build/handlers/notificationHandlers.js.map +1 -1
- package/build/handlers/requestHandlers.d.ts.map +1 -1
- package/build/handlers/requestHandlers.js +43 -1
- package/build/handlers/requestHandlers.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.d.ts.map +1 -1
- package/build/index.js +43 -4
- package/build/index.js.map +1 -1
- package/build/middleware/loggingMiddleware.d.ts.map +1 -1
- package/build/middleware/loggingMiddleware.js +10 -6
- package/build/middleware/loggingMiddleware.js.map +1 -1
- package/build/server/auth/authManager.d.ts +109 -0
- package/build/server/auth/authManager.d.ts.map +1 -0
- package/build/server/auth/authManager.js +173 -0
- package/build/server/auth/authManager.js.map +1 -0
- package/build/server/auth/authMiddleware.d.ts +16 -0
- package/build/server/auth/authMiddleware.d.ts.map +1 -0
- package/build/server/auth/authMiddleware.js +45 -0
- package/build/server/auth/authMiddleware.js.map +1 -0
- package/build/server/auth/sessionManager.d.ts +196 -0
- package/build/server/auth/sessionManager.d.ts.map +1 -0
- package/build/server/auth/sessionManager.js +376 -0
- package/build/server/auth/sessionManager.js.map +1 -0
- package/build/server/config/serverConfig.d.ts +100 -0
- package/build/server/config/serverConfig.d.ts.map +1 -0
- package/build/server/config/serverConfig.js +117 -0
- package/build/server/config/serverConfig.js.map +1 -0
- package/build/server/expressServer.d.ts +60 -2
- package/build/server/expressServer.d.ts.map +1 -1
- package/build/server/expressServer.js +91 -153
- package/build/server/expressServer.js.map +1 -1
- package/build/server/routes/oauthRoutes.d.ts +14 -0
- package/build/server/routes/oauthRoutes.d.ts.map +1 -0
- package/build/server/routes/oauthRoutes.js +132 -0
- package/build/server/routes/oauthRoutes.js.map +1 -0
- package/build/server/routes/sseRoutes.d.ts +4 -0
- package/build/server/routes/sseRoutes.d.ts.map +1 -0
- package/build/server/routes/sseRoutes.js +64 -0
- package/build/server/routes/sseRoutes.js.map +1 -0
- package/build/server/routes/streamableHttpRoutes.d.ts +4 -0
- package/build/server/routes/streamableHttpRoutes.d.ts.map +1 -0
- package/build/server/routes/streamableHttpRoutes.js +94 -0
- package/build/server/routes/streamableHttpRoutes.js.map +1 -0
- package/build/server.js +1 -1
- package/build/server.js.map +1 -1
- package/build/serverManager.d.ts +3 -1
- package/build/serverManager.d.ts.map +1 -1
- package/build/serverManager.js +8 -1
- package/build/serverManager.js.map +1 -1
- package/build/services/configReloadService.d.ts.map +1 -1
- package/build/services/configReloadService.js +4 -0
- package/build/services/configReloadService.js.map +1 -1
- package/build/types.d.ts +2 -1
- package/build/types.d.ts.map +1 -1
- package/build/utils/errorTypes.d.ts +4 -1
- package/build/utils/errorTypes.d.ts.map +1 -1
- package/build/utils/errorTypes.js +9 -1
- package/build/utils/errorTypes.js.map +1 -1
- package/package.json +9 -5
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import fs from 'fs';
|
|
2
|
+
import path from 'path';
|
|
3
|
+
import { randomUUID } from 'node:crypto';
|
|
4
|
+
import logger from '../../logger/logger.js';
|
|
5
|
+
import { AUTH_CONFIG, getGlobalConfigDir } from '../../constants.js';
|
|
6
|
+
/**
|
|
7
|
+
* SessionManager handles file-based session storage with automatic cleanup.
|
|
8
|
+
*
|
|
9
|
+
* This class manages OAuth 2.1 sessions and authorization codes using
|
|
10
|
+
* the local filesystem. It provides automatic cleanup of expired sessions
|
|
11
|
+
* and supports configurable storage locations.
|
|
12
|
+
*
|
|
13
|
+
* Features:
|
|
14
|
+
* - File-based session storage with JSON format
|
|
15
|
+
* - Automatic cleanup of expired sessions every 5 minutes
|
|
16
|
+
* - Prefixed identifiers for easy debugging
|
|
17
|
+
* - Configurable storage directory
|
|
18
|
+
*
|
|
19
|
+
* @example
|
|
20
|
+
* ```typescript
|
|
21
|
+
* const sessionManager = new SessionManager('/custom/path');
|
|
22
|
+
* const sessionId = sessionManager.createSession('client-123', 'resource', 3600000);
|
|
23
|
+
* const session = sessionManager.getSession(sessionId);
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export class SessionManager {
|
|
27
|
+
sessionStoragePath;
|
|
28
|
+
cleanupInterval = null;
|
|
29
|
+
/**
|
|
30
|
+
* Creates a new SessionManager instance.
|
|
31
|
+
*
|
|
32
|
+
* Initializes the session storage directory and starts the automatic
|
|
33
|
+
* cleanup process for expired sessions.
|
|
34
|
+
*
|
|
35
|
+
* @param sessionStoragePath - Optional custom path for session storage
|
|
36
|
+
*/
|
|
37
|
+
constructor(sessionStoragePath) {
|
|
38
|
+
this.sessionStoragePath = sessionStoragePath || path.join(getGlobalConfigDir(), AUTH_CONFIG.SESSION_STORAGE_DIR);
|
|
39
|
+
this.ensureSessionDirectory();
|
|
40
|
+
this.startCleanupInterval();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Ensures the session storage directory exists.
|
|
44
|
+
*
|
|
45
|
+
* Creates the directory structure if it doesn't exist, including
|
|
46
|
+
* parent directories as needed.
|
|
47
|
+
*
|
|
48
|
+
* @throws Error if directory creation fails
|
|
49
|
+
*/
|
|
50
|
+
ensureSessionDirectory() {
|
|
51
|
+
try {
|
|
52
|
+
if (!fs.existsSync(this.sessionStoragePath)) {
|
|
53
|
+
fs.mkdirSync(this.sessionStoragePath, { recursive: true });
|
|
54
|
+
logger.info(`Created session storage directory: ${this.sessionStoragePath}`);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
catch (error) {
|
|
58
|
+
logger.error(`Failed to create session directory: ${error}`);
|
|
59
|
+
throw error;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Gets the file path for a session ID.
|
|
64
|
+
*
|
|
65
|
+
* @param sessionId - The session identifier
|
|
66
|
+
* @returns Full file path for the session file
|
|
67
|
+
*/
|
|
68
|
+
getSessionFilePath(sessionId) {
|
|
69
|
+
const filePath = path.resolve(this.sessionStoragePath, `${AUTH_CONFIG.SESSION_FILE_PREFIX}${sessionId}${AUTH_CONFIG.SESSION_FILE_EXTENSION}`);
|
|
70
|
+
if (!filePath.startsWith(this.sessionStoragePath)) {
|
|
71
|
+
throw new Error('Invalid session file path');
|
|
72
|
+
}
|
|
73
|
+
return filePath;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Gets the file path for an authorization code.
|
|
77
|
+
*
|
|
78
|
+
* @param code - The authorization code
|
|
79
|
+
* @returns Full file path for the auth code file
|
|
80
|
+
*/
|
|
81
|
+
getAuthCodeFilePath(code) {
|
|
82
|
+
const filePath = path.resolve(this.sessionStoragePath, `auth_code_${code}${AUTH_CONFIG.SESSION_FILE_EXTENSION}`);
|
|
83
|
+
if (!filePath.startsWith(this.sessionStoragePath)) {
|
|
84
|
+
throw new Error('Invalid authorization code path');
|
|
85
|
+
}
|
|
86
|
+
return filePath;
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Utility to validate session IDs and auth codes for safe characters (alphanumeric and dashes only).
|
|
90
|
+
* @param id - The session ID or auth code to validate
|
|
91
|
+
* @returns true if valid, false otherwise
|
|
92
|
+
*/
|
|
93
|
+
isValidId(id) {
|
|
94
|
+
return /^[a-zA-Z0-9-]+$/.test(id);
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Creates a new session with the specified parameters.
|
|
98
|
+
*
|
|
99
|
+
* Generates a unique session ID with prefix, stores the session data
|
|
100
|
+
* as a JSON file, and returns the session identifier.
|
|
101
|
+
*
|
|
102
|
+
* @param clientId - The client identifier
|
|
103
|
+
* @param resource - The resource this session can access
|
|
104
|
+
* @param ttlMs - Time-to-live in milliseconds
|
|
105
|
+
* @returns The generated session ID with prefix
|
|
106
|
+
* @throws Error if session creation fails
|
|
107
|
+
*/
|
|
108
|
+
createSession(clientId, resource, ttlMs) {
|
|
109
|
+
const sessionId = AUTH_CONFIG.PREFIXES.SESSION_ID + randomUUID();
|
|
110
|
+
const sessionData = {
|
|
111
|
+
clientId,
|
|
112
|
+
resource,
|
|
113
|
+
expires: Date.now() + ttlMs,
|
|
114
|
+
createdAt: Date.now(),
|
|
115
|
+
};
|
|
116
|
+
try {
|
|
117
|
+
const filePath = this.getSessionFilePath(sessionId);
|
|
118
|
+
fs.writeFileSync(filePath, JSON.stringify(sessionData, null, 2));
|
|
119
|
+
logger.info(`Created session: ${sessionId} for client: ${clientId}`);
|
|
120
|
+
return sessionId;
|
|
121
|
+
}
|
|
122
|
+
catch (error) {
|
|
123
|
+
logger.error(`Failed to create session: ${error}`);
|
|
124
|
+
throw error;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
/**
|
|
128
|
+
* Retrieves session data by session ID.
|
|
129
|
+
*
|
|
130
|
+
* Reads the session file and validates expiration. If the session
|
|
131
|
+
* is expired, it's automatically deleted and null is returned.
|
|
132
|
+
*
|
|
133
|
+
* @param sessionId - The session identifier to retrieve
|
|
134
|
+
* @returns Session data if valid and not expired, null otherwise
|
|
135
|
+
*/
|
|
136
|
+
getSession(sessionId) {
|
|
137
|
+
if (!this.isValidId(sessionId)) {
|
|
138
|
+
logger.warn(`Rejected getSession with invalid sessionId: ${sessionId}`);
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
try {
|
|
142
|
+
const filePath = this.getSessionFilePath(sessionId);
|
|
143
|
+
if (!fs.existsSync(filePath)) {
|
|
144
|
+
return null;
|
|
145
|
+
}
|
|
146
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
147
|
+
const sessionData = JSON.parse(data);
|
|
148
|
+
if (sessionData.expires < Date.now()) {
|
|
149
|
+
this.deleteSession(sessionId);
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
return sessionData;
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
logger.error(`Failed to read session ${sessionId}: ${error}`);
|
|
156
|
+
return null;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Deletes a session by session ID.
|
|
161
|
+
*
|
|
162
|
+
* Removes the session file from the filesystem if it exists.
|
|
163
|
+
*
|
|
164
|
+
* @param sessionId - The session identifier to delete
|
|
165
|
+
* @returns True if session was deleted, false if it didn't exist
|
|
166
|
+
*/
|
|
167
|
+
deleteSession(sessionId) {
|
|
168
|
+
if (!this.isValidId(sessionId)) {
|
|
169
|
+
logger.warn(`Rejected deleteSession with invalid sessionId: ${sessionId}`);
|
|
170
|
+
return false;
|
|
171
|
+
}
|
|
172
|
+
try {
|
|
173
|
+
const filePath = this.getSessionFilePath(sessionId);
|
|
174
|
+
if (fs.existsSync(filePath)) {
|
|
175
|
+
fs.unlinkSync(filePath);
|
|
176
|
+
logger.info(`Deleted session: ${sessionId}`);
|
|
177
|
+
return true;
|
|
178
|
+
}
|
|
179
|
+
return false;
|
|
180
|
+
}
|
|
181
|
+
catch (error) {
|
|
182
|
+
logger.error(`Failed to delete session ${sessionId}: ${error}`);
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Creates a new authorization code for OAuth 2.1 flow.
|
|
188
|
+
*
|
|
189
|
+
* Generates a unique authorization code with prefix, stores the code data
|
|
190
|
+
* as a JSON file, and returns the code identifier.
|
|
191
|
+
*
|
|
192
|
+
* @param clientId - The client identifier
|
|
193
|
+
* @param redirectUri - The redirect URI for this code
|
|
194
|
+
* @param resource - The resource this code grants access to
|
|
195
|
+
* @param ttlMs - Time-to-live in milliseconds
|
|
196
|
+
* @returns The generated authorization code with prefix
|
|
197
|
+
* @throws Error if code creation fails
|
|
198
|
+
*/
|
|
199
|
+
createAuthCode(clientId, redirectUri, resource, ttlMs) {
|
|
200
|
+
const code = AUTH_CONFIG.PREFIXES.AUTH_CODE + randomUUID();
|
|
201
|
+
const authCodeData = {
|
|
202
|
+
clientId,
|
|
203
|
+
redirectUri,
|
|
204
|
+
resource,
|
|
205
|
+
expires: Date.now() + ttlMs,
|
|
206
|
+
createdAt: Date.now(),
|
|
207
|
+
};
|
|
208
|
+
try {
|
|
209
|
+
const filePath = this.getAuthCodeFilePath(code);
|
|
210
|
+
fs.writeFileSync(filePath, JSON.stringify(authCodeData, null, 2));
|
|
211
|
+
logger.info(`Created auth code: ${code} for client: ${clientId}`);
|
|
212
|
+
return code;
|
|
213
|
+
}
|
|
214
|
+
catch (error) {
|
|
215
|
+
logger.error(`Failed to create auth code: ${error}`);
|
|
216
|
+
throw error;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
/**
|
|
220
|
+
* Retrieves authorization code data by code.
|
|
221
|
+
*
|
|
222
|
+
* Reads the auth code file and validates expiration. If the code
|
|
223
|
+
* is expired, it's automatically deleted and null is returned.
|
|
224
|
+
*
|
|
225
|
+
* @param code - The authorization code to retrieve
|
|
226
|
+
* @returns Auth code data if valid and not expired, null otherwise
|
|
227
|
+
*/
|
|
228
|
+
getAuthCode(code) {
|
|
229
|
+
if (!this.isValidId(code)) {
|
|
230
|
+
logger.warn(`Rejected getAuthCode with invalid code: ${code}`);
|
|
231
|
+
return null;
|
|
232
|
+
}
|
|
233
|
+
try {
|
|
234
|
+
const filePath = this.getAuthCodeFilePath(code);
|
|
235
|
+
if (!fs.existsSync(filePath)) {
|
|
236
|
+
return null;
|
|
237
|
+
}
|
|
238
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
239
|
+
const authCodeData = JSON.parse(data);
|
|
240
|
+
if (authCodeData.expires < Date.now()) {
|
|
241
|
+
this.deleteAuthCode(code);
|
|
242
|
+
return null;
|
|
243
|
+
}
|
|
244
|
+
return authCodeData;
|
|
245
|
+
}
|
|
246
|
+
catch (error) {
|
|
247
|
+
logger.error(`Failed to read auth code ${code}: ${error}`);
|
|
248
|
+
return null;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Deletes an authorization code by code.
|
|
253
|
+
*
|
|
254
|
+
* Removes the auth code file from the filesystem if it exists.
|
|
255
|
+
*
|
|
256
|
+
* @param code - The authorization code to delete
|
|
257
|
+
* @returns True if code was deleted, false if it didn't exist
|
|
258
|
+
*/
|
|
259
|
+
deleteAuthCode(code) {
|
|
260
|
+
if (!this.isValidId(code)) {
|
|
261
|
+
logger.warn(`Rejected deleteAuthCode with invalid code: ${code}`);
|
|
262
|
+
return false;
|
|
263
|
+
}
|
|
264
|
+
try {
|
|
265
|
+
const filePath = this.getAuthCodeFilePath(code);
|
|
266
|
+
if (fs.existsSync(filePath)) {
|
|
267
|
+
fs.unlinkSync(filePath);
|
|
268
|
+
logger.info(`Deleted auth code: ${code}`);
|
|
269
|
+
return true;
|
|
270
|
+
}
|
|
271
|
+
return false;
|
|
272
|
+
}
|
|
273
|
+
catch (error) {
|
|
274
|
+
logger.error(`Failed to delete auth code ${code}: ${error}`);
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
/**
|
|
279
|
+
* Starts the automatic cleanup interval for expired sessions.
|
|
280
|
+
*
|
|
281
|
+
* Runs cleanup every 5 minutes to remove expired sessions and
|
|
282
|
+
* authorization codes from the filesystem.
|
|
283
|
+
*/
|
|
284
|
+
startCleanupInterval() {
|
|
285
|
+
// Clean up expired sessions every 5 minutes
|
|
286
|
+
this.cleanupInterval = setInterval(() => {
|
|
287
|
+
this.cleanupExpiredSessions();
|
|
288
|
+
}, 5 * 60 * 1000);
|
|
289
|
+
}
|
|
290
|
+
/**
|
|
291
|
+
* Cleans up expired sessions and authorization codes.
|
|
292
|
+
*
|
|
293
|
+
* Scans the session storage directory and removes all expired
|
|
294
|
+
* session and auth code files. Also handles corrupted files
|
|
295
|
+
* by removing them to prevent future errors.
|
|
296
|
+
*/
|
|
297
|
+
cleanupExpiredSessions() {
|
|
298
|
+
try {
|
|
299
|
+
const files = fs.readdirSync(this.sessionStoragePath);
|
|
300
|
+
let cleanedCount = 0;
|
|
301
|
+
for (const file of files) {
|
|
302
|
+
if (file.endsWith(AUTH_CONFIG.SESSION_FILE_EXTENSION)) {
|
|
303
|
+
const filePath = path.join(this.sessionStoragePath, file);
|
|
304
|
+
try {
|
|
305
|
+
const data = fs.readFileSync(filePath, 'utf8');
|
|
306
|
+
const sessionData = JSON.parse(data);
|
|
307
|
+
if (sessionData.expires < Date.now()) {
|
|
308
|
+
fs.unlinkSync(filePath);
|
|
309
|
+
cleanedCount++;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
catch (error) {
|
|
313
|
+
logger.warn(`Failed to process session file ${file}: ${error}`);
|
|
314
|
+
// Remove corrupted files
|
|
315
|
+
try {
|
|
316
|
+
fs.unlinkSync(filePath);
|
|
317
|
+
cleanedCount++;
|
|
318
|
+
}
|
|
319
|
+
catch (unlinkError) {
|
|
320
|
+
logger.error(`Failed to remove corrupted file ${file}: ${unlinkError}`);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
}
|
|
325
|
+
if (cleanedCount > 0) {
|
|
326
|
+
logger.info(`Cleaned up ${cleanedCount} expired sessions`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
catch (error) {
|
|
330
|
+
logger.error(`Failed to cleanup expired sessions: ${error}`);
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
/**
|
|
334
|
+
* Performs graceful shutdown of the SessionManager.
|
|
335
|
+
*
|
|
336
|
+
* Stops the cleanup interval to prevent memory leaks and
|
|
337
|
+
* ensures proper resource cleanup.
|
|
338
|
+
*/
|
|
339
|
+
shutdown() {
|
|
340
|
+
if (this.cleanupInterval) {
|
|
341
|
+
clearInterval(this.cleanupInterval);
|
|
342
|
+
this.cleanupInterval = null;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
/**
|
|
346
|
+
* Creates a new session with a custom ID (no prefix).
|
|
347
|
+
* Used for access tokens where the token ID is generated separately.
|
|
348
|
+
*
|
|
349
|
+
* @param tokenId - The raw UUID to use for the session (no prefix)
|
|
350
|
+
* @param clientId - The client identifier
|
|
351
|
+
* @param resource - The resource this session can access
|
|
352
|
+
* @param ttlMs - Time-to-live in milliseconds
|
|
353
|
+
* @returns The generated session ID with prefix
|
|
354
|
+
* @throws Error if session creation fails
|
|
355
|
+
*/
|
|
356
|
+
createSessionWithId(tokenId, clientId, resource, ttlMs) {
|
|
357
|
+
const sessionId = AUTH_CONFIG.PREFIXES.SESSION_ID + tokenId;
|
|
358
|
+
const sessionData = {
|
|
359
|
+
clientId,
|
|
360
|
+
resource,
|
|
361
|
+
expires: Date.now() + ttlMs,
|
|
362
|
+
createdAt: Date.now(),
|
|
363
|
+
};
|
|
364
|
+
try {
|
|
365
|
+
const filePath = this.getSessionFilePath(sessionId);
|
|
366
|
+
fs.writeFileSync(filePath, JSON.stringify(sessionData, null, 2));
|
|
367
|
+
logger.info(`Created session: ${sessionId} for client: ${clientId}`);
|
|
368
|
+
return sessionId;
|
|
369
|
+
}
|
|
370
|
+
catch (error) {
|
|
371
|
+
logger.error(`Failed to create session: ${error}`);
|
|
372
|
+
throw error;
|
|
373
|
+
}
|
|
374
|
+
}
|
|
375
|
+
}
|
|
376
|
+
//# sourceMappingURL=sessionManager.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sessionManager.js","sourceRoot":"","sources":["../../../src/server/auth/sessionManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,IAAI,CAAC;AACpB,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AACzC,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,WAA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CAAC,QAAQ,EAAE,IAAI,CAAC,SAAS,CAAC,WAAW,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,CAAC;YACjE,MAAM,CAAC,IAAI,CAAC,oBAAoB,SAAS,gBAAgB,QAAQ,EAAE,CAAC,CAAC;YACrE,OAAO,SAAS,CAAC;QACnB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,MAAM,CAAC,KAAK,CAAC,6BAA6B,KAAK,EAAE,CAAC,CAAC;YACnD,MAAM,KAAK,CAAC;QACd,CAAC;IACH,CAAC;CACF"}
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Configuration interface for server-specific settings.
|
|
3
|
+
*
|
|
4
|
+
* Defines the structure for authentication and session management configuration
|
|
5
|
+
* that can be customized via CLI arguments or environment variables.
|
|
6
|
+
*/
|
|
7
|
+
export interface ServerConfig {
|
|
8
|
+
auth: {
|
|
9
|
+
enabled: boolean;
|
|
10
|
+
sessionTtlMinutes: number;
|
|
11
|
+
sessionStoragePath?: string;
|
|
12
|
+
oauthCodeTtlMs: number;
|
|
13
|
+
oauthTokenTtlMs: number;
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* ServerConfigManager manages server-specific configuration settings.
|
|
18
|
+
*
|
|
19
|
+
* This singleton class handles authentication and session configuration
|
|
20
|
+
* that differs from the main MCP server configuration. It provides
|
|
21
|
+
* centralized access to server settings with default values and
|
|
22
|
+
* runtime configuration updates.
|
|
23
|
+
*
|
|
24
|
+
* @example
|
|
25
|
+
* ```typescript
|
|
26
|
+
* const configManager = ServerConfigManager.getInstance();
|
|
27
|
+
* configManager.updateConfig({
|
|
28
|
+
* auth: { enabled: true, sessionTtlMinutes: 60 }
|
|
29
|
+
* });
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
export declare class ServerConfigManager {
|
|
33
|
+
private static instance;
|
|
34
|
+
private config;
|
|
35
|
+
/**
|
|
36
|
+
* Private constructor to enforce singleton pattern.
|
|
37
|
+
*
|
|
38
|
+
* Initializes the configuration with default values from constants.
|
|
39
|
+
* Should not be called directly - use getInstance() instead.
|
|
40
|
+
*/
|
|
41
|
+
private constructor();
|
|
42
|
+
/**
|
|
43
|
+
* Gets the singleton instance of ServerConfigManager.
|
|
44
|
+
*
|
|
45
|
+
* Creates a new instance if one doesn't exist, otherwise returns
|
|
46
|
+
* the existing instance to ensure configuration consistency.
|
|
47
|
+
*
|
|
48
|
+
* @returns The singleton ServerConfigManager instance
|
|
49
|
+
*/
|
|
50
|
+
static getInstance(): ServerConfigManager;
|
|
51
|
+
/**
|
|
52
|
+
* Updates the server configuration with new values.
|
|
53
|
+
*
|
|
54
|
+
* Merges the provided updates with existing configuration, allowing
|
|
55
|
+
* partial updates while preserving other settings.
|
|
56
|
+
*
|
|
57
|
+
* @param updates - Partial configuration object with new values
|
|
58
|
+
*/
|
|
59
|
+
updateConfig(updates: Partial<ServerConfig>): void;
|
|
60
|
+
/**
|
|
61
|
+
* Gets a copy of the current server configuration.
|
|
62
|
+
*
|
|
63
|
+
* Returns a deep copy to prevent external modification of the
|
|
64
|
+
* internal configuration state.
|
|
65
|
+
*
|
|
66
|
+
* @returns Current server configuration
|
|
67
|
+
*/
|
|
68
|
+
getConfig(): ServerConfig;
|
|
69
|
+
/**
|
|
70
|
+
* Checks if authentication is currently enabled.
|
|
71
|
+
*
|
|
72
|
+
* @returns True if OAuth 2.1 authentication is enabled, false otherwise
|
|
73
|
+
*/
|
|
74
|
+
isAuthEnabled(): boolean;
|
|
75
|
+
/**
|
|
76
|
+
* Gets the session time-to-live in minutes.
|
|
77
|
+
*
|
|
78
|
+
* @returns Session TTL in minutes
|
|
79
|
+
*/
|
|
80
|
+
getSessionTtlMinutes(): number;
|
|
81
|
+
/**
|
|
82
|
+
* Gets the custom session storage path if configured.
|
|
83
|
+
*
|
|
84
|
+
* @returns Custom session storage path or undefined if using default
|
|
85
|
+
*/
|
|
86
|
+
getSessionStoragePath(): string | undefined;
|
|
87
|
+
/**
|
|
88
|
+
* Gets the OAuth authorization code time-to-live in milliseconds.
|
|
89
|
+
*
|
|
90
|
+
* @returns OAuth code TTL in milliseconds
|
|
91
|
+
*/
|
|
92
|
+
getOAuthCodeTtlMs(): number;
|
|
93
|
+
/**
|
|
94
|
+
* Gets the OAuth access token time-to-live in milliseconds.
|
|
95
|
+
*
|
|
96
|
+
* @returns OAuth token TTL in milliseconds
|
|
97
|
+
*/
|
|
98
|
+
getOAuthTokenTtlMs(): number;
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=serverConfig.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverConfig.d.ts","sourceRoot":"","sources":["../../../src/server/config/serverConfig.ts"],"names":[],"mappings":"AAEA;;;;;GAKG;AACH,MAAM,WAAW,YAAY;IAC3B,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;CACH;AAED;;;;;;;;;;;;;;;GAeG;AACH,qBAAa,mBAAmB;IAC9B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAsB;IAC7C,OAAO,CAAC,MAAM,CAAe;IAE7B;;;;;OAKG;IACH,OAAO;IAWP;;;;;;;OAOG;WACW,WAAW,IAAI,mBAAmB;IAOhD;;;;;;;OAOG;IACI,YAAY,CAAC,OAAO,EAAE,OAAO,CAAC,YAAY,CAAC,GAAG,IAAI;IAOzD;;;;;;;OAOG;IACI,SAAS,IAAI,YAAY;IAIhC;;;;OAIG;IACI,aAAa,IAAI,OAAO;IAI/B;;;;OAIG;IACI,oBAAoB,IAAI,MAAM;IAIrC;;;;OAIG;IACI,qBAAqB,IAAI,MAAM,GAAG,SAAS;IAIlD;;;;OAIG;IACI,iBAAiB,IAAI,MAAM;IAIlC;;;;OAIG;IACI,kBAAkB,IAAI,MAAM;CAGpC"}
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { AUTH_CONFIG } from '../../constants.js';
|
|
2
|
+
/**
|
|
3
|
+
* ServerConfigManager manages server-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 server settings with default values and
|
|
8
|
+
* runtime configuration updates.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```typescript
|
|
12
|
+
* const configManager = ServerConfigManager.getInstance();
|
|
13
|
+
* configManager.updateConfig({
|
|
14
|
+
* auth: { enabled: true, sessionTtlMinutes: 60 }
|
|
15
|
+
* });
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
export class ServerConfigManager {
|
|
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
|
+
auth: {
|
|
30
|
+
enabled: AUTH_CONFIG.DEFAULT_ENABLED,
|
|
31
|
+
sessionTtlMinutes: AUTH_CONFIG.DEFAULT_SESSION_TTL_MINUTES,
|
|
32
|
+
oauthCodeTtlMs: AUTH_CONFIG.DEFAULT_OAUTH_CODE_TTL_MS,
|
|
33
|
+
oauthTokenTtlMs: AUTH_CONFIG.DEFAULT_OAUTH_TOKEN_TTL_MS,
|
|
34
|
+
},
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Gets the singleton instance of ServerConfigManager.
|
|
39
|
+
*
|
|
40
|
+
* Creates a new instance if one doesn't exist, otherwise returns
|
|
41
|
+
* the existing instance to ensure configuration consistency.
|
|
42
|
+
*
|
|
43
|
+
* @returns The singleton ServerConfigManager instance
|
|
44
|
+
*/
|
|
45
|
+
static getInstance() {
|
|
46
|
+
if (!ServerConfigManager.instance) {
|
|
47
|
+
ServerConfigManager.instance = new ServerConfigManager();
|
|
48
|
+
}
|
|
49
|
+
return ServerConfigManager.instance;
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Updates the server configuration with new values.
|
|
53
|
+
*
|
|
54
|
+
* Merges the provided updates with existing configuration, allowing
|
|
55
|
+
* partial updates while preserving other settings.
|
|
56
|
+
*
|
|
57
|
+
* @param updates - Partial configuration object with new values
|
|
58
|
+
*/
|
|
59
|
+
updateConfig(updates) {
|
|
60
|
+
this.config = { ...this.config, ...updates };
|
|
61
|
+
if (updates.auth) {
|
|
62
|
+
this.config.auth = { ...this.config.auth, ...updates.auth };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Gets a copy of the current server configuration.
|
|
67
|
+
*
|
|
68
|
+
* Returns a deep copy to prevent external modification of the
|
|
69
|
+
* internal configuration state.
|
|
70
|
+
*
|
|
71
|
+
* @returns Current server configuration
|
|
72
|
+
*/
|
|
73
|
+
getConfig() {
|
|
74
|
+
return { ...this.config };
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Checks if authentication is currently enabled.
|
|
78
|
+
*
|
|
79
|
+
* @returns True if OAuth 2.1 authentication is enabled, false otherwise
|
|
80
|
+
*/
|
|
81
|
+
isAuthEnabled() {
|
|
82
|
+
return this.config.auth.enabled;
|
|
83
|
+
}
|
|
84
|
+
/**
|
|
85
|
+
* Gets the session time-to-live in minutes.
|
|
86
|
+
*
|
|
87
|
+
* @returns Session TTL in minutes
|
|
88
|
+
*/
|
|
89
|
+
getSessionTtlMinutes() {
|
|
90
|
+
return this.config.auth.sessionTtlMinutes;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Gets the custom session storage path if configured.
|
|
94
|
+
*
|
|
95
|
+
* @returns Custom session storage path or undefined if using default
|
|
96
|
+
*/
|
|
97
|
+
getSessionStoragePath() {
|
|
98
|
+
return this.config.auth.sessionStoragePath;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Gets the OAuth authorization code time-to-live in milliseconds.
|
|
102
|
+
*
|
|
103
|
+
* @returns OAuth code TTL in milliseconds
|
|
104
|
+
*/
|
|
105
|
+
getOAuthCodeTtlMs() {
|
|
106
|
+
return this.config.auth.oauthCodeTtlMs;
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Gets the OAuth access token time-to-live in milliseconds.
|
|
110
|
+
*
|
|
111
|
+
* @returns OAuth token TTL in milliseconds
|
|
112
|
+
*/
|
|
113
|
+
getOAuthTokenTtlMs() {
|
|
114
|
+
return this.config.auth.oauthTokenTtlMs;
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
//# sourceMappingURL=serverConfig.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"serverConfig.js","sourceRoot":"","sources":["../../../src/server/config/serverConfig.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AAkBjD;;;;;;;;;;;;;;;GAeG;AACH,MAAM,OAAO,mBAAmB;IACtB,MAAM,CAAC,QAAQ,CAAsB;IACrC,MAAM,CAAe;IAE7B;;;;;OAKG;IACH;QACE,IAAI,CAAC,MAAM,GAAG;YACZ,IAAI,EAAE;gBACJ,OAAO,EAAE,WAAW,CAAC,eAAe;gBACpC,iBAAiB,EAAE,WAAW,CAAC,2BAA2B;gBAC1D,cAAc,EAAE,WAAW,CAAC,yBAAyB;gBACrD,eAAe,EAAE,WAAW,CAAC,0BAA0B;aACxD;SACF,CAAC;IACJ,CAAC;IAED;;;;;;;OAOG;IACI,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,mBAAmB,CAAC,QAAQ,EAAE,CAAC;YAClC,mBAAmB,CAAC,QAAQ,GAAG,IAAI,mBAAmB,EAAE,CAAC;QAC3D,CAAC;QACD,OAAO,mBAAmB,CAAC,QAAQ,CAAC;IACtC,CAAC;IAED;;;;;;;OAOG;IACI,YAAY,CAAC,OAA8B;QAChD,IAAI,CAAC,MAAM,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,GAAG,OAAO,EAAE,CAAC;QAC7C,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;YACjB,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,EAAE,GAAG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;QAC9D,CAAC;IACH,CAAC;IAED;;;;;;;OAOG;IACI,SAAS;QACd,OAAO,EAAE,GAAG,IAAI,CAAC,MAAM,EAAE,CAAC;IAC5B,CAAC;IAED;;;;OAIG;IACI,aAAa;QAClB,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC;IAClC,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;CACF"}
|
|
@@ -1,11 +1,69 @@
|
|
|
1
1
|
import { ServerManager } from '../serverManager.js';
|
|
2
|
+
/**
|
|
3
|
+
* ExpressServer orchestrates the HTTP/SSE transport layer for the MCP server.
|
|
4
|
+
*
|
|
5
|
+
* This class manages the Express application, authentication, and route setup.
|
|
6
|
+
* It provides both HTTP and SSE transport options with optional OAuth 2.1 authentication.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* ```typescript
|
|
10
|
+
* const serverManager = await setupServer();
|
|
11
|
+
* const expressServer = new ExpressServer(serverManager);
|
|
12
|
+
* expressServer.start(3050, 'localhost');
|
|
13
|
+
* ```
|
|
14
|
+
*/
|
|
2
15
|
export declare class ExpressServer {
|
|
3
16
|
private app;
|
|
4
17
|
private serverManager;
|
|
18
|
+
private authManager;
|
|
19
|
+
private configManager;
|
|
20
|
+
/**
|
|
21
|
+
* Creates a new ExpressServer instance.
|
|
22
|
+
*
|
|
23
|
+
* Initializes the Express application, sets up middleware, authentication,
|
|
24
|
+
* and configures all routes for MCP transport and OAuth endpoints.
|
|
25
|
+
*
|
|
26
|
+
* @param serverManager - The server manager instance for handling MCP operations
|
|
27
|
+
*/
|
|
5
28
|
constructor(serverManager: ServerManager);
|
|
29
|
+
/**
|
|
30
|
+
* Sets up Express middleware including CORS, body parsing, and error handling.
|
|
31
|
+
*
|
|
32
|
+
* Configures the basic middleware stack required for the MCP server:
|
|
33
|
+
* - CORS for cross-origin requests
|
|
34
|
+
* - JSON body parsing
|
|
35
|
+
* - Global error handling
|
|
36
|
+
*/
|
|
6
37
|
private setupMiddleware;
|
|
7
|
-
|
|
8
|
-
|
|
38
|
+
/**
|
|
39
|
+
* Sets up all application routes including OAuth and MCP transport endpoints.
|
|
40
|
+
*
|
|
41
|
+
* Configures the following route groups:
|
|
42
|
+
* - OAuth 2.1 endpoints (always available, auth can be disabled)
|
|
43
|
+
* - Streamable HTTP transport routes with authentication middleware
|
|
44
|
+
* - SSE transport routes with authentication middleware
|
|
45
|
+
*
|
|
46
|
+
* Logs the authentication status for debugging purposes.
|
|
47
|
+
*/
|
|
48
|
+
private setupRoutes;
|
|
49
|
+
/**
|
|
50
|
+
* Starts the Express server on the specified port and host.
|
|
51
|
+
*
|
|
52
|
+
* Binds the Express application to the network interface and logs
|
|
53
|
+
* the server status including authentication configuration.
|
|
54
|
+
*
|
|
55
|
+
* @param port - The port number to listen on
|
|
56
|
+
* @param host - The host address to bind to
|
|
57
|
+
*/
|
|
9
58
|
start(port: number, host: string): void;
|
|
59
|
+
/**
|
|
60
|
+
* Performs graceful shutdown of the Express server.
|
|
61
|
+
*
|
|
62
|
+
* Cleans up resources including:
|
|
63
|
+
* - Authentication manager shutdown
|
|
64
|
+
* - Session cleanup
|
|
65
|
+
* - Timer cleanup
|
|
66
|
+
*/
|
|
67
|
+
shutdown(): void;
|
|
10
68
|
}
|
|
11
69
|
//# sourceMappingURL=expressServer.d.ts.map
|