firewalla-mcp-server
Version:
Model Context Protocol (MCP) server for Firewalla MSP API - Provides real-time network monitoring, security analysis, and firewall management through 28 specialized tools compatible with any MCP client
182 lines • 5.6 kB
TypeScript
/**
* Result Streaming Infrastructure for Firewalla MCP Server
* Provides efficient streaming for large datasets to prevent memory exhaustion
*/
import type { PaginationParams } from './pagination.js';
/**
* Configuration for streaming operations
*/
export interface StreamingConfig {
/** Size of each chunk/batch to stream */
chunkSize: number;
/** Maximum number of chunks to stream (0 = unlimited) */
maxChunks: number;
/** Timeout for streaming session in milliseconds */
sessionTimeoutMs: number;
/** Whether to enable compression for large chunks */
enableCompression: boolean;
/** Maximum memory usage threshold (bytes) */
maxMemoryThreshold: number;
/** Whether to include metadata in each chunk */
includeMetadata: boolean;
/** Threshold for when to use streaming (number of items) */
streamingThreshold: number;
}
/**
* Streaming session information
*/
export interface StreamingSession {
/** Unique session ID */
sessionId: string;
/** Tool name that initiated the streaming */
toolName: string;
/** Current continuation token */
continuationToken?: string;
/** Number of chunks already streamed */
chunksStreamed: number;
/** Total items streamed so far */
itemsStreamed: number;
/** Session start time */
startTime: Date;
/** Last activity time */
lastActivity: Date;
/** Whether the session is complete */
isComplete: boolean;
/** Original query parameters */
originalParams: any;
/** Session configuration */
config: StreamingConfig;
}
/**
* Individual chunk response
*/
export interface StreamingChunk {
/** Unique chunk ID within the session */
chunkId: number;
/** Session ID this chunk belongs to */
sessionId: string;
/** Data items in this chunk */
data: any[];
/** Number of items in this chunk */
count: number;
/** Whether this is the final chunk */
isFinalChunk: boolean;
/** Continuation token for next chunk */
nextContinuationToken?: string | null;
/** Chunk metadata */
metadata: {
chunkIndex: number;
totalItemsInSession: number;
estimatedRemainingItems?: number;
processingTimeMs: number;
memoryUsage?: number;
};
/** Timestamp when chunk was created */
timestamp: string;
}
/**
* Streaming operation function type
*/
export type StreamingOperation<T = any> = (params: PaginationParams & {
continuationToken?: string;
}) => Promise<{
data: T[];
hasMore: boolean;
nextCursor?: string | null;
total?: number;
}>;
/**
* Manager class for handling result streaming
*/
export declare class StreamingManager {
private config;
private activeSessions;
private cleanupTimer?;
constructor(config?: Partial<StreamingConfig>);
/**
* Create a new streaming session
*/
createStreamingSession(toolName: string, originalParams: any, config?: Partial<StreamingConfig>): StreamingSession;
/**
* Get the next chunk of data for a streaming session
*/
getNextChunk<T = any>(sessionId: string, operation: StreamingOperation<T>): Promise<StreamingChunk | null>;
/**
* Start a new streaming operation
*/
startStreaming<T = any>(toolName: string, operation: StreamingOperation<T>, originalParams: any, config?: Partial<StreamingConfig>): Promise<{
sessionId: string;
firstChunk: StreamingChunk;
}>;
/**
* Continue an existing streaming session
*/
continueStreaming<T = any>(sessionId: string, operation: StreamingOperation<T>): Promise<StreamingChunk | null>;
/**
* Get information about an active streaming session
*/
getSessionInfo(sessionId: string): StreamingSession | null;
/**
* List all active streaming sessions
*/
getActiveSessions(): StreamingSession[];
/**
* Complete a streaming session
*/
completeSession(sessionId: string): void;
/**
* Expire a streaming session due to timeout or error
*/
expireSession(sessionId: string): void;
/**
* Cancel a streaming session
*/
cancelSession(sessionId: string): boolean;
/**
* Clean up expired sessions
*/
private startSessionCleanup;
/**
* Stop the streaming manager and clean up resources
*/
shutdown(): void;
/**
* Generate a unique session ID
*/
private generateSessionId;
/**
* Estimate remaining items in the stream
*/
private estimateRemainingItems;
/**
* Get current memory usage (simplified)
*/
private getMemoryUsage;
/**
* Create a streaming configuration optimized for specific tool types
*/
static getConfigForTool(toolName: string): Partial<StreamingConfig>;
/**
* Create a streaming manager optimized for specific tool
*/
static forTool(toolName: string): StreamingManager;
}
/**
* Global streaming manager with default configuration
*/
export declare const globalStreamingManager: StreamingManager;
/**
* Utility function to check if a tool should use streaming
*/
export declare function shouldUseStreaming(toolName: string, requestedLimit: number, estimatedTotal?: number, customThreshold?: number | StreamingConfig): boolean;
/**
* Create a standardized streaming response
*/
export declare function createStreamingResponse(chunk: StreamingChunk, includeMetadata?: boolean): {
content: {
type: string;
text: string;
}[];
isError: boolean;
};
//# sourceMappingURL=streaming-manager.d.ts.map