@@ -39,8 +39,7 @@ type RenderApi = {
39
39
prompt : McpServer [ "prompt" ] ;
40
40
} ;
41
41
42
- type McpServerOptions < T extends Record < string , any > = Record < string , any > > =
43
- ServerOptions & {
42
+ type McpServerOptions < T > = ServerOptions & {
44
43
render ?: ( api : RenderApi , args : T ) => void | Promise < void > ;
45
44
} ;
46
45
@@ -49,7 +48,7 @@ type McpServerOptions<T extends Record<string, any> = Record<string, any>> =
49
48
* For advanced usage (like sending notifications or setting custom request handlers), use the underlying
50
49
* Server instance available via the `server` property.
51
50
*/
52
- export class McpServer < RenderArgs extends Record < string , any > = Record < string , any > > {
51
+ export class McpServer < RenderArgs extends Record < string , unknown > | undefined = undefined > {
53
52
/**
54
53
* The underlying Server instance, useful for advanced operations like sending notifications.
55
54
*/
@@ -67,7 +66,7 @@ export class McpServer<RenderArgs extends Record<string, any> = Record<string, a
67
66
args : RenderArgs ,
68
67
) => void | Promise < void > ;
69
68
private readonly _locked : boolean ;
70
- private _isFirstRender : boolean = true ;
69
+ private _isConnected : boolean = true ;
71
70
72
71
constructor ( serverInfo : Implementation , options ?: McpServerOptions < RenderArgs > ) {
73
72
this . server = new Server ( serverInfo , options ) ;
@@ -81,6 +80,7 @@ export class McpServer<RenderArgs extends Record<string, any> = Record<string, a
81
80
* The `server` object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
82
81
*/
83
82
async connect ( transport : Transport ) : Promise < void > {
83
+ this . _isConnected = true
84
84
return await this . server . connect ( transport ) ;
85
85
}
86
86
@@ -529,15 +529,12 @@ export class McpServer<RenderArgs extends Record<string, any> = Record<string, a
529
529
this . setPromptRequestHandlers ( ) ;
530
530
this . setResourceRequestHandlers ( ) ;
531
531
532
- // Emit change events only if state *actually* changed and it's not the first render
533
- if ( ! this . _isFirstRender ) {
532
+ // Emit change events if we have a transport to emit to
533
+ if ( ! this . _isConnected ) {
534
534
if ( toolsChanged ) this . server . sendToolListChanged ( )
535
535
if ( promptsChanged ) this . server . sendPromptListChanged ( )
536
536
if ( resourcesChanged ) this . server . sendResourceListChanged ( )
537
537
}
538
-
539
- // --- 6. Mark first render as complete ---
540
- this . _isFirstRender = false ;
541
538
}
542
539
543
540
/**
0 commit comments