File tree 3 files changed +72
-1
lines changed
3 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " @modelcontextprotocol/sdk" ,
3
- "version" : " 1.3.1 " ,
3
+ "version" : " 1.3.2 " ,
4
4
"description" : " Model Context Protocol implementation for TypeScript" ,
5
5
"license" : " MIT" ,
6
6
"author" : " Anthropic, PBC (https://anthropic.com)" ,
Original file line number Diff line number Diff line change @@ -1283,6 +1283,69 @@ describe("prompt()", () => {
1283
1283
} ) ) ;
1284
1284
} ) ;
1285
1285
1286
+ test ( "should allow registering prompts with arguments" , ( ) => {
1287
+ const mcpServer = new McpServer ( {
1288
+ name : "test server" ,
1289
+ version : "1.0" ,
1290
+ } ) ;
1291
+
1292
+ // This should succeed
1293
+ mcpServer . prompt (
1294
+ "echo" ,
1295
+ { message : z . string ( ) } ,
1296
+ ( { message } ) => ( {
1297
+ messages : [ {
1298
+ role : "user" ,
1299
+ content : {
1300
+ type : "text" ,
1301
+ text : `Please process this message: ${ message } `
1302
+ }
1303
+ } ]
1304
+ } )
1305
+ ) ;
1306
+ } ) ;
1307
+
1308
+ test ( "should allow registering both resources and prompts with completion handlers" , ( ) => {
1309
+ const mcpServer = new McpServer ( {
1310
+ name : "test server" ,
1311
+ version : "1.0" ,
1312
+ } ) ;
1313
+
1314
+ // Register a resource with completion
1315
+ mcpServer . resource (
1316
+ "test" ,
1317
+ new ResourceTemplate ( "test://resource/{category}" , {
1318
+ list : undefined ,
1319
+ complete : {
1320
+ category : ( ) => [ "books" , "movies" , "music" ] ,
1321
+ } ,
1322
+ } ) ,
1323
+ async ( ) => ( {
1324
+ contents : [
1325
+ {
1326
+ uri : "test://resource/test" ,
1327
+ text : "Test content" ,
1328
+ } ,
1329
+ ] ,
1330
+ } ) ,
1331
+ ) ;
1332
+
1333
+ // Register a prompt with completion
1334
+ mcpServer . prompt (
1335
+ "echo" ,
1336
+ { message : completable ( z . string ( ) , ( ) => [ "hello" , "world" ] ) } ,
1337
+ ( { message } ) => ( {
1338
+ messages : [ {
1339
+ role : "user" ,
1340
+ content : {
1341
+ type : "text" ,
1342
+ text : `Please process this message: ${ message } `
1343
+ }
1344
+ } ]
1345
+ } )
1346
+ ) ;
1347
+ } ) ;
1348
+
1286
1349
test ( "should throw McpError for invalid prompt name" , async ( ) => {
1287
1350
const mcpServer = new McpServer ( {
1288
1351
name : "test server" ,
Original file line number Diff line number Diff line change @@ -175,7 +175,13 @@ export class McpServer {
175
175
this . _toolHandlersInitialized = true ;
176
176
}
177
177
178
+ private _completionHandlerInitialized = false ;
179
+
178
180
private setCompletionRequestHandler ( ) {
181
+ if ( this . _completionHandlerInitialized ) {
182
+ return ;
183
+ }
184
+
179
185
this . server . assertCanSetRequestHandler (
180
186
CompleteRequestSchema . shape . method . value ,
181
187
) ;
@@ -198,6 +204,8 @@ export class McpServer {
198
204
}
199
205
} ,
200
206
) ;
207
+
208
+ this . _completionHandlerInitialized = true ;
201
209
}
202
210
203
211
private async handlePromptCompletion (
You can’t perform that action at this time.
0 commit comments