@elliotding/ai-agent-mcp 0.1.25 → 0.1.27

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 (53) hide show
  1. package/package.json +4 -1
  2. package/.prompt-cache/cmd-cmd-client-sdk-ai-hub-generate-testcase.md +0 -101
  3. package/.prompt-cache/cmd-cmd-client-sdk-ai-hub-submit_zct_job.md +0 -158
  4. package/.prompt-cache/skill-skill-client-sdk-ai-hub-analyze-conf-status.md +0 -311
  5. package/.prompt-cache/skill-skill-client-sdk-ai-hub-analyze-sdk-log.md +0 -64
  6. package/.prompt-cache/skill-skill-client-sdk-ai-hub-analyze-zmb-log-errors.md +0 -84
  7. package/ai-resource-telemetry.json +0 -40
  8. package/src/api/cached-client.ts +0 -144
  9. package/src/api/client.ts +0 -697
  10. package/src/auth/index.ts +0 -11
  11. package/src/auth/middleware.ts +0 -244
  12. package/src/auth/permissions.ts +0 -323
  13. package/src/auth/token-validator.ts +0 -292
  14. package/src/cache/cache-manager.ts +0 -243
  15. package/src/cache/index.ts +0 -6
  16. package/src/cache/redis-client.ts +0 -249
  17. package/src/config/constants.ts +0 -33
  18. package/src/config/index.ts +0 -269
  19. package/src/filesystem/manager.ts +0 -235
  20. package/src/git/multi-source-manager.ts +0 -654
  21. package/src/git/operations.ts +0 -93
  22. package/src/index.ts +0 -157
  23. package/src/monitoring/health.ts +0 -132
  24. package/src/prompts/cache.ts +0 -140
  25. package/src/prompts/generator.ts +0 -143
  26. package/src/prompts/index.ts +0 -20
  27. package/src/prompts/manager.ts +0 -718
  28. package/src/resources/index.ts +0 -13
  29. package/src/resources/loader.ts +0 -563
  30. package/src/server/http.ts +0 -549
  31. package/src/server.ts +0 -206
  32. package/src/session/manager.ts +0 -296
  33. package/src/telemetry/index.ts +0 -10
  34. package/src/telemetry/manager.ts +0 -419
  35. package/src/tools/index.ts +0 -13
  36. package/src/tools/manage-subscription.ts +0 -388
  37. package/src/tools/registry.ts +0 -97
  38. package/src/tools/resolve-prompt-content.ts +0 -113
  39. package/src/tools/search-resources.ts +0 -185
  40. package/src/tools/sync-resources.ts +0 -829
  41. package/src/tools/track-usage.ts +0 -113
  42. package/src/tools/uninstall-resource.ts +0 -199
  43. package/src/tools/upload-resource.ts +0 -431
  44. package/src/transport/sse.ts +0 -308
  45. package/src/types/errors.ts +0 -146
  46. package/src/types/index.ts +0 -7
  47. package/src/types/mcp.ts +0 -61
  48. package/src/types/resources.ts +0 -141
  49. package/src/types/tools.ts +0 -305
  50. package/src/utils/cursor-paths.ts +0 -135
  51. package/src/utils/log-cleaner.ts +0 -92
  52. package/src/utils/logger.ts +0 -333
  53. package/src/utils/validation.ts +0 -262
@@ -1,549 +0,0 @@
1
- /**
2
- * HTTP Server with SSE Support
3
- * Uses SDK SSEServerTransport for standard MCP-over-SSE protocol,
4
- * matching the same pattern as the ACM MCP server.
5
- */
6
-
7
- import Fastify, { FastifyInstance, FastifyRequest, FastifyReply } from 'fastify';
8
- import cors from '@fastify/cors';
9
- import helmet from '@fastify/helmet';
10
- import { Server } from '@modelcontextprotocol/sdk/server/index.js';
11
- import { SSEServerTransport } from '@modelcontextprotocol/sdk/server/sse.js';
12
- import {
13
- CallToolRequestSchema,
14
- ListToolsRequestSchema,
15
- } from '@modelcontextprotocol/sdk/types.js';
16
- import { syncResources } from '../tools/sync-resources.js';
17
- import { telemetry } from '../telemetry/index.js';
18
- import { promptManager } from '../prompts/index.js';
19
- import { config } from '../config';
20
- import { logger } from '../utils/logger';
21
- import { sessionManager } from '../session/manager';
22
- import { toolRegistry } from '../tools/registry';
23
- import {
24
- tokenAuthOrLegacyMiddleware,
25
- checkToolCallPermission,
26
- type AuthenticatedRequest,
27
- } from '../auth/middleware';
28
- import { HealthChecker, type HealthStatus as MonitoringHealthStatus } from '../monitoring/health.js';
29
- import { CacheManager } from '../cache/cache-manager.js';
30
-
31
- export interface HealthStatus {
32
- status: 'healthy' | 'unhealthy';
33
- uptime: number;
34
- memory: {
35
- used: number;
36
- total: number;
37
- percentage: number;
38
- };
39
- sessions: {
40
- active: number;
41
- total: number;
42
- };
43
- services: MonitoringHealthStatus['services'];
44
- details?: MonitoringHealthStatus['details'];
45
- timestamp: string;
46
- }
47
-
48
- export class HTTPServer {
49
- private fastify: FastifyInstance;
50
- private startTime: number = Date.now();
51
- private healthChecker: HealthChecker | null = null;
52
-
53
- /** Active SDK SSE transports keyed by sessionId */
54
- private sseTransports: Map<string, SSEServerTransport> = new Map();
55
-
56
- constructor(cacheManager?: CacheManager) {
57
- this.fastify = Fastify({
58
- logger: false,
59
- bodyLimit: 10 * 1024 * 1024, // 10MB
60
- });
61
-
62
- if (cacheManager) {
63
- this.healthChecker = new HealthChecker(cacheManager);
64
- }
65
-
66
- this.setupMiddleware();
67
- this.setupRoutes();
68
- }
69
-
70
- // ─────────────────────────────────────────────────────────────────────────
71
- // Middleware
72
- // ─────────────────────────────────────────────────────────────────────────
73
-
74
- private setupMiddleware(): void {
75
- this.fastify.register(cors, {
76
- origin: true,
77
- credentials: true,
78
- });
79
-
80
- this.fastify.register(helmet, {
81
- contentSecurityPolicy: false, // Disable for SSE
82
- });
83
-
84
- this.fastify.addHook('onRequest', async (request) => {
85
- logger.debug(
86
- { method: request.method, url: request.url, ip: request.ip },
87
- 'HTTP request received'
88
- );
89
- });
90
-
91
- this.fastify.addHook('onResponse', async (request) => {
92
- logger.debug(
93
- {
94
- method: request.method,
95
- url: request.url,
96
- statusCode: (request.raw as { statusCode?: number }).statusCode || 200,
97
- },
98
- 'HTTP response sent'
99
- );
100
- });
101
- }
102
-
103
- // ─────────────────────────────────────────────────────────────────────────
104
- // Routes
105
- // ─────────────────────────────────────────────────────────────────────────
106
-
107
- private setupRoutes(): void {
108
- const basePath = config.http?.basePath ?? '';
109
-
110
- // Health check
111
- this.fastify.get(`${basePath}/health`, this.handleHealth.bind(this));
112
-
113
- // SSE connection — GET establishes the stream (SDK standard)
114
- this.fastify.get(`${basePath}/sse`, {
115
- preHandler: tokenAuthOrLegacyMiddleware,
116
- handler: this.handleSSEConnection.bind(this),
117
- });
118
-
119
- // Message endpoint — POST delivers JSON-RPC messages, sessionId in query
120
- this.fastify.post(`${basePath}/message`, this.handleMessage.bind(this));
121
-
122
- // OAuth discovery — return 404 so Cursor skips OAuth handshake
123
- this.fastify.get('/.well-known/oauth-authorization-server', async (_req, reply) => {
124
- reply.code(404).send({ error: 'OAuth not supported' });
125
- });
126
-
127
- // Root info
128
- this.fastify.get('/', async () => ({
129
- server: 'CSP AI Agent MCP Server',
130
- version: '1.0.0',
131
- transport: 'sse',
132
- basePath: basePath || '(none)',
133
- endpoints: {
134
- health: `GET ${basePath}/health`,
135
- sse: `GET ${basePath}/sse`,
136
- message: `POST ${basePath}/message?sessionId=<id>`,
137
- },
138
- }));
139
- }
140
-
141
- // ─────────────────────────────────────────────────────────────────────────
142
- // MCP Server factory
143
- // ─────────────────────────────────────────────────────────────────────────
144
-
145
- /**
146
- * Creates a new SDK Server instance and registers all tools from toolRegistry.
147
- * A fresh instance is created per SSE connection so that each session is
148
- * isolated (matching ACM's createMCPServer-per-connection pattern).
149
- */
150
- private createMcpServer(userId?: string, email?: string, groups?: string[], userToken?: string): Server {
151
- const server = new Server(
152
- { name: 'csp-ai-agent-mcp', version: '0.2.0' },
153
- // Declare prompts, tools, and logging capabilities only.
154
- // REMOVED resources capability to align with async-pilot's working implementation.
155
- // Cursor should use standard prompts/get instead of probing prompt:// as resources.
156
- { capabilities: { tools: {}, prompts: {}, logging: {} } }
157
- );
158
-
159
- // Install Prompt list/get handlers synchronously on this Server instance.
160
- // Pass userToken so GetPrompt can attribute telemetry to the correct user.
161
- promptManager.installHandlers(server, userToken);
162
-
163
- // tools/list
164
- server.setRequestHandler(ListToolsRequestSchema, () => ({
165
- tools: toolRegistry.getMCPToolDefinitions(),
166
- }));
167
-
168
- // Auto-sync subscribed resources once the MCP handshake is fully complete.
169
- // Runs in the background so it never blocks the connection setup.
170
- server.oninitialized = () => {
171
- logger.info({ userId }, 'MCP initialized — triggering background sync_resources');
172
- // Flush any pending telemetry immediately on (re)connect so events from
173
- // before a disconnect are not held until the next 10-second tick.
174
- telemetry.flushOnReconnect();
175
- syncResources({ mode: 'incremental', scope: 'global', user_token: userToken }).then(async (result) => {
176
- if (result.success) {
177
- logger.info(
178
- { userId, synced: result.data?.summary?.synced, cached: result.data?.summary?.cached },
179
- 'Auto sync_resources on connect completed'
180
- );
181
- // If the sync result includes local_actions_required (Rule files /
182
- // MCP entries that must be written on the user's local machine),
183
- // cache them in PromptManager. They will be embedded directly into
184
- // the csp-ai-agent-setup prompt content the next time the AI calls
185
- // GetPrompt for that prompt, so the AI receives them without needing
186
- // to call sync_resources again and without relying on sendLoggingMessage
187
- // (which is unreliable — the connection may already be closed by then).
188
- const actions = result.data?.local_actions_required;
189
- if (actions && actions.length > 0) {
190
- promptManager.storeSyncActions(userToken ?? '', actions);
191
- }
192
- } else {
193
- logger.warn({ userId, error: result.error }, 'Auto sync_resources on connect failed');
194
- }
195
- }).catch((err) => {
196
- logger.error({ userId, err }, 'Auto sync_resources on connect threw an error');
197
- });
198
- };
199
-
200
- // tools/call
201
- server.setRequestHandler(CallToolRequestSchema, async (request) => {
202
- const { name, arguments: args = {} } = request.params;
203
-
204
- // Permission check when user context is available
205
- if (userId && groups && groups.length > 0) {
206
- const permCheck = checkToolCallPermission(name, { userId, email: email ?? '', groups });
207
- if (!permCheck.allowed) {
208
- return {
209
- content: [{ type: 'text' as const, text: `Permission denied: ${permCheck.reason}` }],
210
- isError: true,
211
- };
212
- }
213
- }
214
-
215
- // Inject the authenticated token so every tool can call the CSP API without
216
- // requiring the AI to know about or pass user_token explicitly.
217
- // The AI-supplied user_token (if any) takes precedence; otherwise we fall back
218
- // to the token from the SSE connection that created this session.
219
- const enrichedArgs: Record<string, unknown> = {
220
- user_token: userToken,
221
- ...args,
222
- };
223
-
224
- try {
225
- const result = await toolRegistry.callTool(name, enrichedArgs);
226
- const text = typeof result === 'string' ? result : JSON.stringify(result, null, 2);
227
- return { content: [{ type: 'text' as const, text }] };
228
- } catch (err) {
229
- const msg = err instanceof Error ? err.message : String(err);
230
- logger.error({ toolName: name, err }, 'Tool execution failed');
231
- return {
232
- content: [{ type: 'text' as const, text: `Error: ${msg}` }],
233
- isError: true,
234
- };
235
- }
236
- });
237
-
238
- return server;
239
- }
240
-
241
- // ─────────────────────────────────────────────────────────────────────────
242
- // Handlers
243
- // ─────────────────────────────────────────────────────────────────────────
244
-
245
- /**
246
- * GET /sse — establish SSE stream using SDK SSEServerTransport.
247
- * Auth is validated via preHandler; user context is forwarded to the MCP server.
248
- */
249
- private async handleSSEConnection(
250
- request: AuthenticatedRequest,
251
- reply: FastifyReply
252
- ): Promise<void> {
253
- logger.info({ ip: request.ip }, 'SSE connection request received');
254
-
255
- const authHeader = request.headers.authorization;
256
- const token = authHeader?.replace(/^Bearer\s+/i, '');
257
- if (!token) {
258
- reply.code(401).send({ error: 'Unauthorized', message: 'Bearer token required' });
259
- return;
260
- }
261
-
262
- // Register the authenticated token so flush() can report telemetry for this user.
263
- // The token comes from the SSE Authorization header and is the single source of truth.
264
- telemetry.setUserToken(token);
265
-
266
- try {
267
- // Keep our session manager in sync for health/monitoring endpoints
268
- const sessionOptions = request.user
269
- ? { userId: request.user.userId, email: request.user.email, groups: request.user.groups }
270
- : undefined;
271
- const session = await sessionManager.createSession(token, request.ip ?? '', sessionOptions);
272
-
273
- logger.info(
274
- { sessionId: session.id, userId: session.userId, email: session.email },
275
- 'Session created'
276
- );
277
-
278
- // Heartbeat to keep proxies/load-balancers from dropping idle SSE streams
279
- const heartbeat = setInterval(() => {
280
- if (!reply.raw.destroyed) {
281
- try {
282
- reply.raw.write('event: heartbeat\ndata: {}\n\n');
283
- } catch {
284
- clearInterval(heartbeat);
285
- }
286
- } else {
287
- clearInterval(heartbeat);
288
- }
289
- }, 30_000);
290
-
291
- // Build the absolute message URL for the SSE endpoint event.
292
- // Cursor (and other MCP clients) use this URL to POST all subsequent
293
- // JSON-RPC messages (tools/call, prompts/get, etc.).
294
- //
295
- // publicOrigin is resolved at startup from (in priority order):
296
- // 1. PUBLIC_URL env var
297
- // 2. Origin extracted from CSP_API_BASE_URL (same host as the API)
298
- // 3. http://HTTP_HOST:HTTP_PORT (safe for local dev)
299
- // See config/index.ts for details.
300
- const basePath = config.http?.basePath ?? '';
301
- const publicOrigin = config.http?.publicOrigin ?? `http://127.0.0.1:${config.http?.port ?? 3000}`;
302
- const messagePath = `${basePath}/message`;
303
-
304
- // The MCP SDK SSEServerTransport.start() emits an `endpoint` SSE event
305
- // whose data is a *relative* path (pathname + ?sessionId=...), stripping
306
- // the origin. When deployed behind nginx, Cursor resolves this relative
307
- // path against whatever origin it used to open the SSE connection, which
308
- // may differ from our public API origin. The result is that GetPrompt /
309
- // tools/call POST requests go to the wrong address and never arrive.
310
- //
311
- // Fix: intercept the raw response stream's write() method. When the SDK
312
- // emits the relative endpoint event we replace it on-the-fly with the
313
- // full absolute URL so Cursor always uses the correct public address.
314
- // Only ONE endpoint event is ever written to the wire this way.
315
- const rawRes = reply.raw;
316
- const originalWrite = rawRes.write.bind(rawRes);
317
- (rawRes as NodeJS.WritableStream & { write: typeof originalWrite }).write = (
318
- chunk: unknown,
319
- encodingOrCb?: unknown,
320
- cb?: unknown,
321
- ): boolean => {
322
- if (typeof chunk === 'string' && chunk.startsWith('event: endpoint\ndata:')) {
323
- // The SDK wrote a relative endpoint event — replace with absolute URL.
324
- // We know the sessionId from transport.sessionId (read after construction).
325
- // Use a placeholder here; replaced below once we have the transport.
326
- // (This interceptor is set before connect(), so the write happens during
327
- // connect() → transport.start().)
328
- chunk = chunk.replace(
329
- /^(event: endpoint\ndata:).*/,
330
- `$1 ${publicOrigin}${messagePath}?sessionId=__SESSION_ID__`,
331
- );
332
- }
333
- if (typeof encodingOrCb === 'function') {
334
- return originalWrite(chunk as string, encodingOrCb as () => void);
335
- }
336
- if (typeof cb === 'function') {
337
- return originalWrite(chunk as string, encodingOrCb as BufferEncoding, cb as () => void);
338
- }
339
- return originalWrite(chunk as string);
340
- };
341
-
342
- const transport = new SSEServerTransport(messagePath, rawRes);
343
- const sdkSessionId = transport.sessionId;
344
-
345
- // Now patch the placeholder with the real sessionId that the SDK assigned.
346
- // The write interceptor is still active during connect() → start(), so we
347
- // swap it out for a version that knows the actual sessionId.
348
- (rawRes as NodeJS.WritableStream & { write: typeof originalWrite }).write = (
349
- chunk: unknown,
350
- encodingOrCb?: unknown,
351
- cb?: unknown,
352
- ): boolean => {
353
- if (typeof chunk === 'string' && chunk.startsWith('event: endpoint\ndata:')) {
354
- chunk = `event: endpoint\ndata: ${publicOrigin}${messagePath}?sessionId=${sdkSessionId}\n\n`;
355
- }
356
- if (typeof encodingOrCb === 'function') {
357
- return originalWrite(chunk as string, encodingOrCb as () => void);
358
- }
359
- if (typeof cb === 'function') {
360
- return originalWrite(chunk as string, encodingOrCb as BufferEncoding, cb as () => void);
361
- }
362
- return originalWrite(chunk as string);
363
- };
364
-
365
- this.sseTransports.set(sdkSessionId, transport);
366
-
367
- transport.onclose = () => {
368
- logger.info({ sdkSessionId, sessionId: session.id }, 'SSE transport closed');
369
- clearInterval(heartbeat);
370
- this.sseTransports.delete(sdkSessionId);
371
- sessionManager.closeSession(session.id);
372
- };
373
-
374
- transport.onerror = (err: Error) => {
375
- logger.warn({ sdkSessionId, error: err.message }, 'SSE transport error');
376
- };
377
-
378
- const mcpServer = this.createMcpServer(
379
- request.user?.userId,
380
- request.user?.email,
381
- request.user?.groups,
382
- token,
383
- );
384
-
385
- // connect() calls transport.start() which triggers the intercepted write()
386
- // above — emitting exactly ONE absolute endpoint event to the wire.
387
- await mcpServer.connect(transport);
388
-
389
- const absoluteMessageUrl = `${publicOrigin}${messagePath}?sessionId=${sdkSessionId}`;
390
- logger.info(
391
- { sdkSessionId, absoluteMessageUrl, publicOrigin },
392
- 'SSE stream established — absolute endpoint URL intercepted and sent',
393
- );
394
-
395
- // Handle client disconnect
396
- request.raw.on('close', () => {
397
- clearInterval(heartbeat);
398
- transport.close().catch(() => {/* already logged via onclose */});
399
- });
400
-
401
- } catch (error) {
402
- logger.error({ error }, 'Failed to establish SSE connection');
403
- if (!reply.raw.headersSent) {
404
- reply.code(500).send({ error: 'Internal Server Error', message: 'Failed to establish connection' });
405
- }
406
- }
407
- }
408
-
409
- /**
410
- * POST /message?sessionId=<id> — deliver JSON-RPC message to the correct transport.
411
- * The SDK transport's handlePostMessage handles parsing and routing internally.
412
- */
413
- private async handleMessage(request: FastifyRequest, reply: FastifyReply): Promise<void> {
414
- const sessionId = (request.query as Record<string, string>)['sessionId'];
415
-
416
- if (!sessionId) {
417
- reply.code(400).send({ error: 'Bad Request', message: 'Missing sessionId query parameter' });
418
- return;
419
- }
420
-
421
- const transport = this.sseTransports.get(sessionId);
422
- if (!transport) {
423
- logger.warn({ sessionId }, 'No active transport found for sessionId');
424
- reply.code(404).send({
425
- error: 'Not Found',
426
- message: 'Session not found or expired',
427
- details: { sessionId, suggestion: 'Reconnect via GET /sse' },
428
- });
429
- return;
430
- }
431
-
432
- logger.debug({ sessionId }, 'Forwarding message to SDK transport');
433
-
434
- try {
435
- await transport.handlePostMessage(request.raw, reply.raw, request.body);
436
- } catch (error) {
437
- logger.error({ error, sessionId }, 'Failed to handle message');
438
- if (!reply.raw.headersSent) {
439
- reply.code(500).send({ error: 'Internal Server Error', message: 'Failed to process message' });
440
- }
441
- }
442
- }
443
-
444
- // ─────────────────────────────────────────────────────────────────────────
445
- // Health check
446
- // ─────────────────────────────────────────────────────────────────────────
447
-
448
- private async handleHealth(): Promise<HealthStatus> {
449
- const uptime = Math.floor((Date.now() - this.startTime) / 1000);
450
- const memUsage = process.memoryUsage();
451
-
452
- let servicesHealth: MonitoringHealthStatus | null = null;
453
- if (this.healthChecker) {
454
- try {
455
- servicesHealth = await this.healthChecker.check();
456
- } catch (error) {
457
- logger.error({ error }, 'Health check failed');
458
- }
459
- }
460
-
461
- const health: HealthStatus = {
462
- status: servicesHealth?.status || 'healthy',
463
- uptime,
464
- memory: {
465
- used: Math.round(memUsage.heapUsed / 1024 / 1024),
466
- total: Math.round(memUsage.heapTotal / 1024 / 1024),
467
- percentage: Math.round((memUsage.heapUsed / memUsage.heapTotal) * 100),
468
- },
469
- sessions: {
470
- active: sessionManager.getActiveSessionCount(),
471
- total: sessionManager.getTotalSessionCount(),
472
- },
473
- services: servicesHealth?.services || {
474
- http: 'up',
475
- redis: 'not_configured',
476
- cache: 'down',
477
- },
478
- timestamp: new Date().toISOString(),
479
- };
480
-
481
- if (servicesHealth?.details) {
482
- health.details = servicesHealth.details;
483
- }
484
-
485
- logger.info({ health }, 'Health check requested');
486
- return health;
487
- }
488
-
489
- // ─────────────────────────────────────────────────────────────────────────
490
- // Lifecycle
491
- // ─────────────────────────────────────────────────────────────────────────
492
-
493
- async start(): Promise<void> {
494
- try {
495
- const host = config.http?.host || '0.0.0.0';
496
- const port = config.http?.port || 3000;
497
- const basePath = config.http?.basePath ?? '';
498
-
499
- await this.fastify.listen({ host, port });
500
-
501
- const publicOrigin = config.http?.publicOrigin ?? `http://${host}:${port}`;
502
- logger.info({ host, port, basePath, publicOrigin }, 'HTTP server started');
503
- // Internal listen address (for ops/infra):
504
- logger.info(`Listening on: http://${host}:${port}${basePath}`);
505
- // Public-facing addresses (what Cursor clients will use):
506
- logger.info(`[Public] Health check: ${publicOrigin}${basePath}/health`);
507
- logger.info(`[Public] SSE endpoint: ${publicOrigin}${basePath}/sse`);
508
- logger.info(`[Public] Message endpoint: ${publicOrigin}${basePath}/message?sessionId=<id>`);
509
- } catch (error) {
510
- logger.error({ error }, 'Failed to start HTTP server');
511
- throw error;
512
- }
513
- }
514
-
515
- async stop(): Promise<void> {
516
- try {
517
- logger.info('Stopping HTTP server gracefully...');
518
-
519
- // Close all SDK SSE transports
520
- for (const [id, transport] of this.sseTransports.entries()) {
521
- logger.info({ id }, 'Closing SDK SSE transport');
522
- await transport.close().catch(() => {});
523
- }
524
- this.sseTransports.clear();
525
-
526
- sessionManager.closeAllSessions();
527
-
528
- await new Promise(resolve => setTimeout(resolve, 500));
529
- await this.fastify.close();
530
-
531
- logger.info('HTTP server stopped gracefully');
532
- } catch (error) {
533
- logger.error({ error }, 'Error stopping HTTP server');
534
- throw error;
535
- }
536
- }
537
-
538
- getFastify(): FastifyInstance {
539
- return this.fastify;
540
- }
541
-
542
- setCacheManager(cacheManager: CacheManager): void {
543
- this.healthChecker = new HealthChecker(cacheManager);
544
- logger.info('Health checker initialized with cache manager');
545
- }
546
- }
547
-
548
- // Singleton instance (initialized without cache manager initially)
549
- export const httpServer = new HTTPServer();