@@ -2,7 +2,7 @@ import { Server } from "./index.js";
2
2
import { Client } from "../client/index.js" ;
3
3
import { InMemoryTransport } from "../inMemory.js" ;
4
4
import { z } from "zod" ;
5
- import { McpServer } from "./mcp.js" ;
5
+ import { McpServer , ResourceTemplate } from "./mcp.js" ;
6
6
7
7
describe ( "Title field backwards compatibility" , ( ) => {
8
8
it ( "should work with tools that have title" , async ( ) => {
@@ -169,6 +169,48 @@ describe("Title field backwards compatibility", () => {
169
169
expect ( resources . resources [ 0 ] . mimeType ) . toBe ( "text/plain" ) ;
170
170
} ) ;
171
171
172
+ it ( "should work with dynamic resources using registerResource" , async ( ) => {
173
+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
174
+
175
+ const server = new McpServer (
176
+ { name : "test-server" , version : "1.0.0" } ,
177
+ { capabilities : { } }
178
+ ) ;
179
+
180
+ // Register dynamic resource with title using registerResource
181
+ server . registerResource (
182
+ "user-profile" ,
183
+ new ResourceTemplate ( "users://{userId}/profile" , { list : undefined } ) ,
184
+ {
185
+ title : "User Profile" ,
186
+ description : "User profile information"
187
+ } ,
188
+ async ( uri , { userId } , extra ) => ( {
189
+ contents : [ {
190
+ uri : uri . href ,
191
+ text : `Profile data for user ${ userId } `
192
+ } ]
193
+ } )
194
+ ) ;
195
+
196
+ const client = new Client ( { name : "test-client" , version : "1.0.0" } ) ;
197
+
198
+ await server . server . connect ( serverTransport ) ;
199
+ await client . connect ( clientTransport ) ;
200
+
201
+ const resourceTemplates = await client . listResourceTemplates ( ) ;
202
+ expect ( resourceTemplates . resourceTemplates ) . toHaveLength ( 1 ) ;
203
+ expect ( resourceTemplates . resourceTemplates [ 0 ] . name ) . toBe ( "user-profile" ) ;
204
+ expect ( resourceTemplates . resourceTemplates [ 0 ] . title ) . toBe ( "User Profile" ) ;
205
+ expect ( resourceTemplates . resourceTemplates [ 0 ] . description ) . toBe ( "User profile information" ) ;
206
+ expect ( resourceTemplates . resourceTemplates [ 0 ] . uriTemplate ) . toBe ( "users://{userId}/profile" ) ;
207
+
208
+ // Test reading the resource
209
+ const readResult = await client . readResource ( { uri : "users://123/profile" } ) ;
210
+ expect ( readResult . contents ) . toHaveLength ( 1 ) ;
211
+ expect ( readResult . contents [ 0 ] . text ) . toBe ( "Profile data for user 123" ) ;
212
+ } ) ;
213
+
172
214
it ( "should support serverInfo with title" , async ( ) => {
173
215
const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
174
216
0 commit comments