File tree Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Expand file tree Collapse file tree 3 files changed +72
-1
lines changed Original file line number Diff line number Diff line change 11{
22 "name" : " @modelcontextprotocol/sdk" ,
3- "version" : " 1.3.1 " ,
3+ "version" : " 1.3.2 " ,
44 "description" : " Model Context Protocol implementation for TypeScript" ,
55 "license" : " MIT" ,
66 "author" : " Anthropic, PBC (https://anthropic.com)" ,
Original file line number Diff line number Diff line change @@ -1283,6 +1283,69 @@ describe("prompt()", () => {
12831283 } ) ) ;
12841284 } ) ;
12851285
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+
12861349 test ( "should throw McpError for invalid prompt name" , async ( ) => {
12871350 const mcpServer = new McpServer ( {
12881351 name : "test server" ,
Original file line number Diff line number Diff line change @@ -175,7 +175,13 @@ export class McpServer {
175175 this . _toolHandlersInitialized = true ;
176176 }
177177
178+ private _completionHandlerInitialized = false ;
179+
178180 private setCompletionRequestHandler ( ) {
181+ if ( this . _completionHandlerInitialized ) {
182+ return ;
183+ }
184+
179185 this . server . assertCanSetRequestHandler (
180186 CompleteRequestSchema . shape . method . value ,
181187 ) ;
@@ -198,6 +204,8 @@ export class McpServer {
198204 }
199205 } ,
200206 ) ;
207+
208+ this . _completionHandlerInitialized = true ;
201209 }
202210
203211 private async handlePromptCompletion (
You can’t perform that action at this time.
0 commit comments