@@ -71,7 +71,7 @@ public McpServer(ITransport transport, McpServerOptions options, ILoggerFactory?
7171
7272 RegisterListChange ( capabilities ? . Tools , NotificationMethods . ToolListChangedNotification ) ;
7373 RegisterListChange ( capabilities ? . Prompts , NotificationMethods . PromptListChangedNotification ) ;
74- RegisterListChange ( capabilities ? . Resources , RequestMethods . ResourcesList ) ;
74+ RegisterListChange ( capabilities ? . Resources , NotificationMethods . ResourceListChangedNotification ) ;
7575
7676 // And initialize the session.
7777 InitializeSession ( transport ) ;
@@ -185,14 +185,9 @@ private void SetResourcesHandler(McpServerOptions options)
185185
186186 var listResourcesHandler = resourcesCapability . ListResourcesHandler ;
187187 var listResourceTemplatesHandler = resourcesCapability . ListResourceTemplatesHandler ;
188+ var readResourceHandler = resourcesCapability . ReadResourceHandler ;
188189 var resourceCollection = resourcesCapability . ResourceCollection ;
189190
190- if ( ( listResourcesHandler is not { } && listResourceTemplatesHandler is not { } ) ||
191- resourcesCapability . ReadResourceHandler is not { } readResourceHandler )
192- {
193- throw new McpException ( "Resources capability was enabled, but ListResources and/or ReadResource handlers were not specified." ) ;
194- }
195-
196191 var originalListResourcesHandler = listResourcesHandler ;
197192 listResourcesHandler = async ( request , cancellationToken ) =>
198193 {
@@ -208,12 +203,19 @@ await originalListResourcesHandler(request, cancellationToken).ConfigureAwait(fa
208203 return result ;
209204 } ;
210205
206+ var isMissingListResourceHandlers = originalListResourcesHandler is not { } && listResourceTemplatesHandler is not { } ;
207+ if ( resourceCollection is not { IsEmpty : false } && ( isMissingListResourceHandlers || readResourceHandler is not { } ) )
208+ {
209+ throw new McpException ( "Resources capability was enabled, but ListResources, ListResourceTemplates, and/or ReadResource handlers were not specified." ) ;
210+ }
211+
211212 RequestHandlers . Set (
212213 RequestMethods . ResourcesList ,
213214 ( request , cancellationToken ) => listResourcesHandler ( new ( this , request ) , cancellationToken ) ,
214215 McpJsonUtilities . JsonContext . Default . ListResourcesRequestParams ,
215216 McpJsonUtilities . JsonContext . Default . ListResourcesResult ) ;
216217
218+ readResourceHandler ??= static ( _ , _ ) => Task . FromResult ( new ReadResourceResult ( ) ) ;
217219 RequestHandlers . Set (
218220 RequestMethods . ResourcesRead ,
219221 ( request , cancellationToken ) => readResourceHandler ( new ( this , request ) , cancellationToken ) ,
0 commit comments