@@ -401,8 +401,50 @@ describe('@payloadcms/plugin-mcp', () => {
401401 expect ( json . result . content [ 0 ] . text ) . toContain ( 'Total: 1 documents' )
402402 expect ( json . result . content [ 0 ] . text ) . toContain ( 'Page: 1 of 1' )
403403 expect ( json . result . content [ 0 ] . text ) . toContain ( '```json' )
404- expect ( json . result . content [ 0 ] . text ) . toContain ( '"title ": "Test Post for Finding "' )
404+ expect ( json . result . content [ 0 ] . text ) . toContain ( '"content ": "Content for test post. "' )
405405 expect ( json . result . content [ 1 ] . type ) . toBe ( 'text' )
406406 expect ( json . result . content [ 1 ] . text ) . toContain ( 'Override MCP response for Posts!' )
407407 } )
408+
409+ it ( 'should call operations with the payloadAPI context as MCP' , async ( ) => {
410+ await payload . create ( {
411+ collection : 'posts' ,
412+ data : {
413+ title : 'Test Post for Finding' ,
414+ content : 'Content for test post.' ,
415+ } ,
416+ } )
417+
418+ const apiKey = await getApiKey ( )
419+ const response = await restClient . POST ( '/mcp' , {
420+ headers : {
421+ Authorization : `Bearer ${ apiKey } ` ,
422+ Accept : 'application/json, text/event-stream' ,
423+ 'Content-Type' : 'application/json' ,
424+ } ,
425+ body : JSON . stringify ( {
426+ id : 1 ,
427+ jsonrpc : '2.0' ,
428+ method : 'tools/call' ,
429+ params : {
430+ name : 'findPosts' ,
431+ arguments : {
432+ limit : 1 ,
433+ page : 1 ,
434+ where : '{"title": {"contains": "Test Post for Finding"}}' ,
435+ } ,
436+ } ,
437+ } ) ,
438+ } )
439+
440+ const json = await parseStreamResponse ( response )
441+
442+ expect ( json ) . toBeDefined ( )
443+ expect ( json . result ) . toBeDefined ( )
444+ expect ( json . result . content ) . toHaveLength ( 2 )
445+ expect ( json . result . content [ 0 ] . type ) . toBe ( 'text' )
446+ expect ( json . result . content [ 0 ] . text ) . toContain (
447+ '"title": "Test Post for Finding (MCP Hook Override)"' ,
448+ )
449+ } )
408450} )
0 commit comments