@@ -313,6 +313,21 @@ private static ResourcesCapability ConfigureResources()
313313
314314 return new ( )
315315 {
316+ ListResourceTemplatesHandler = ( request , cancellationToken ) =>
317+ {
318+
319+ return Task . FromResult ( new ListResourceTemplatesResult ( )
320+ {
321+ ResourceTemplates = [
322+ new ResourceTemplate ( )
323+ {
324+ UriTemplate = "test://dynamic/resource/{id}" ,
325+ Name = "Dynamic Resource" ,
326+ }
327+ ]
328+ } ) ;
329+ } ,
330+
316331 ListResourcesHandler = ( request , cancellationToken ) =>
317332 {
318333 int startIndex = 0 ;
@@ -349,6 +364,27 @@ private static ResourcesCapability ConfigureResources()
349364 {
350365 throw new McpServerException ( "Missing required argument 'uri'" ) ;
351366 }
367+
368+ if ( request . Params . Uri . StartsWith ( "test://dynamic/resource/" ) )
369+ {
370+ var id = request . Params . Uri . Split ( '/' ) . LastOrDefault ( ) ;
371+ if ( string . IsNullOrEmpty ( id ) )
372+ {
373+ throw new McpServerException ( "Invalid resource URI" ) ;
374+ }
375+ return Task . FromResult ( new ReadResourceResult ( )
376+ {
377+ Contents = [
378+ new ResourceContents ( )
379+ {
380+ Uri = request . Params . Uri ,
381+ MimeType = "text/plain" ,
382+ Text = $ "Dynamic resource { id } : This is a plaintext resource"
383+ }
384+ ]
385+ } ) ;
386+ }
387+
352388 ResourceContents contents = resourceContents . FirstOrDefault ( r => r . Uri == request . Params . Uri )
353389 ?? throw new McpServerException ( "Resource not found" ) ;
354390
@@ -364,7 +400,8 @@ private static ResourcesCapability ConfigureResources()
364400 {
365401 throw new McpServerException ( "Missing required argument 'uri'" ) ;
366402 }
367- if ( ! request . Params . Uri . StartsWith ( "test://static/resource/" ) )
403+ if ( ! request . Params . Uri . StartsWith ( "test://static/resource/" )
404+ && ! request . Params . Uri . StartsWith ( "test://dynamic/resource/" ) )
368405 {
369406 throw new McpServerException ( "Invalid resource URI" ) ;
370407 }
@@ -383,7 +420,8 @@ private static ResourcesCapability ConfigureResources()
383420 {
384421 throw new McpServerException ( "Missing required argument 'uri'" ) ;
385422 }
386- if ( ! request . Params . Uri . StartsWith ( "test://static/resource/" ) )
423+ if ( ! request . Params . Uri . StartsWith ( "test://static/resource/" )
424+ && ! request . Params . Uri . StartsWith ( "test://dynamic/resource/" ) )
387425 {
388426 throw new McpServerException ( "Invalid resource URI" ) ;
389427 }
0 commit comments