File tree Expand file tree Collapse file tree
packages/server/src/server
test/integration/test/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ ---
2+ " @modelcontextprotocol/server " : patch
3+ ---
4+
5+ Fix prompts/get rejecting omitted arguments when all argsSchema fields are optional
Original file line number Diff line number Diff line change @@ -1271,7 +1271,7 @@ function createPromptHandler(
12711271 const typedCallback = callback as ( args : unknown , ctx : ServerContext ) => GetPromptResult | Promise < GetPromptResult > ;
12721272
12731273 return async ( args , ctx ) => {
1274- const parseResult = await validateStandardSchema ( argsSchema , args ) ;
1274+ const parseResult = await validateStandardSchema ( argsSchema , args ?? { } ) ;
12751275 if ( ! parseResult . success ) {
12761276 throw new ProtocolError ( ProtocolErrorCode . InvalidParams , `Invalid arguments for prompt ${ name } : ${ parseResult . error } ` ) ;
12771277 }
Original file line number Diff line number Diff line change @@ -4254,6 +4254,54 @@ describe('Zod v4', () => {
42544254 ] ) ;
42554255 } ) ;
42564256
4257+ /***
4258+ * Test: prompts/get with omitted arguments when all argsSchema fields are optional (#1869)
4259+ */
4260+ test ( 'should accept omitted arguments in prompts/get when all argsSchema fields are optional' , async ( ) => {
4261+ const mcpServer = new McpServer ( {
4262+ name : 'test server' ,
4263+ version : '1.0'
4264+ } ) ;
4265+
4266+ const client = new Client ( {
4267+ name : 'test client' ,
4268+ version : '1.0'
4269+ } ) ;
4270+
4271+ mcpServer . registerPrompt (
4272+ 'echo' ,
4273+ {
4274+ argsSchema : z . object ( {
4275+ context : z . string ( ) . optional ( )
4276+ } )
4277+ } ,
4278+ ( { context } ) => ( {
4279+ messages : [
4280+ {
4281+ role : 'user' as const ,
4282+ content : { type : 'text' as const , text : `context: ${ context ?? 'none' } ` }
4283+ }
4284+ ]
4285+ } )
4286+ ) ;
4287+
4288+ const [ clientTransport , serverTransport ] = InMemoryTransport . createLinkedPair ( ) ;
4289+
4290+ await Promise . all ( [ client . connect ( clientTransport ) , mcpServer . server . connect ( serverTransport ) ] ) ;
4291+
4292+ // Call prompts/get without arguments -- should not throw
4293+ const result = await client . request ( {
4294+ method : 'prompts/get' ,
4295+ params : { name : 'echo' }
4296+ } ) ;
4297+
4298+ expect ( result . messages ) . toHaveLength ( 1 ) ;
4299+ expect ( result . messages [ 0 ] ! . content ) . toEqual ( {
4300+ type : 'text' ,
4301+ text : 'context: none'
4302+ } ) ;
4303+ } ) ;
4304+
42574305 /***
42584306 * Test: Prompt Registration with _meta field
42594307 */
You can’t perform that action at this time.
0 commit comments