@@ -6,36 +6,12 @@ export function registerClientsCommand(program: Command) {
66 program
77 . command ( 'clients' )
88 . description ( 'Show all connected MCP clients' )
9- . option ( '--port <port>' , 'Gateway port (default: 9095)' , '9095' )
10- . option ( '--host <host>' , 'Gateway host (default: localhost)' , 'localhost' )
11- . action ( async ( options ) => {
12- await showConnectedClients ( options ) ;
9+ . action ( async ( ) => {
10+ await showConnectedClients ( ) ;
1311 } ) ;
1412}
1513
16- interface ClientConnection {
17- id : string ;
18- type : 'SSE' | 'Streamable HTTP' ;
19- clientInfo ?: {
20- name : string ;
21- version : string ;
22- } ;
23- createdAt : number ;
24- lastActivity : number ;
25- uptime : number ;
26- requestCount : number ;
27- errorCount : number ;
28- mcpInitialized : boolean ;
29- }
30-
31- interface ClientStatus {
32- totalConnections : number ;
33- sseConnections : number ;
34- streamableHttpConnections : number ;
35- clients : ClientConnection [ ] ;
36- }
37-
38- async function showConnectedClients ( options : { port : string ; host : string } ) : Promise < void > {
14+ async function showConnectedClients ( ) : Promise < void > {
3915 try {
4016 const clientCache = new ClientStateCacheService ( ) ;
4117
@@ -148,104 +124,3 @@ function formatUptime(milliseconds: number): string {
148124 return `${ seconds } s` ;
149125 }
150126}
151-
152- /**
153- * Fetch gateway status via HTTP
154- */
155- async function fetchGatewayStatus ( gatewayUrl : string ) : Promise < any > {
156- const fetch = ( await import ( 'node-fetch' ) ) . default ;
157-
158- // Create AbortController for timeout
159- const controller = new AbortController ( ) ;
160- const timeoutId = setTimeout ( ( ) => controller . abort ( ) , 5000 ) ;
161-
162- try {
163- const response = await fetch ( `${ gatewayUrl } /status` , {
164- signal : controller . signal
165- } ) ;
166-
167- clearTimeout ( timeoutId ) ;
168-
169- if ( ! response . ok ) {
170- throw new Error ( `HTTP ${ response . status } ` ) ;
171- }
172-
173- return await response . json ( ) ;
174- } catch ( error ) {
175- clearTimeout ( timeoutId ) ;
176- throw error ;
177- }
178- }
179-
180- /**
181- * Extract client status from gateway status response
182- */
183- function extractClientStatus ( gatewayStatus : any ) : ClientStatus {
184- const clients : ClientConnection [ ] = [ ] ;
185- const now = Date . now ( ) ;
186-
187- // Extract SSE sessions
188- if ( gatewayStatus . clients ?. sse ?. sessions ) {
189- for ( const session of gatewayStatus . clients . sse . sessions ) {
190- clients . push ( {
191- id : session . id ,
192- type : 'SSE' ,
193- clientInfo : session . clientInfo ,
194- createdAt : session . createdAt ,
195- lastActivity : session . lastActivity ,
196- uptime : session . uptime ,
197- requestCount : session . requestCount ,
198- errorCount : session . errorCount ,
199- mcpInitialized : session . mcpInitialized
200- } ) ;
201- }
202- }
203-
204- // Extract Streamable HTTP sessions
205- if ( gatewayStatus . clients ?. streamableHttp ?. sessions ) {
206- for ( const session of gatewayStatus . clients . streamableHttp . sessions ) {
207- clients . push ( {
208- id : session . id ,
209- type : 'Streamable HTTP' ,
210- clientInfo : session . clientInfo ,
211- createdAt : session . createdAt ,
212- lastActivity : session . lastActivity ,
213- uptime : session . uptime ,
214- requestCount : session . requestCount ,
215- errorCount : session . errorCount ,
216- mcpInitialized : session . mcpInitialized
217- } ) ;
218- }
219- }
220-
221- // Sort by creation time (newest first)
222- clients . sort ( ( a , b ) => b . createdAt - a . createdAt ) ;
223-
224- return {
225- totalConnections : clients . length ,
226- sseConnections : gatewayStatus . clients ?. sse ?. activeCount || 0 ,
227- streamableHttpConnections : gatewayStatus . clients ?. streamableHttp ?. activeSessionCount || 0 ,
228- clients
229- } ;
230- }
231-
232- /**
233- * Calculate summary statistics
234- */
235- function calculateSummary ( status : ClientStatus ) : {
236- total : number ;
237- sse : number ;
238- streamableHttp : number ;
239- initialized : number ;
240- active : number ;
241- } {
242- const fiveMinutesAgo = Date . now ( ) - ( 5 * 60 * 1000 ) ;
243-
244- return {
245- total : status . totalConnections ,
246- sse : status . sseConnections ,
247- streamableHttp : status . streamableHttpConnections ,
248- initialized : status . clients . filter ( c => c . mcpInitialized ) . length ,
249- active : status . clients . filter ( c => c . lastActivity > fiveMinutesAgo ) . length
250- } ;
251- }
0 commit comments