@@ -747,6 +747,128 @@ describe('api-extractor', () => {
747747 // Revision filtered out — writeResource should not be called for it
748748 expect ( result . revisions ) . toHaveLength ( 0 ) ;
749749 } ) ;
750+
751+ it ( 'should skip specification export for MCP APIs without calling the client' , async ( ) => {
752+ const getApiSpecification = vi . fn ( ) ;
753+ const client = createMockClient ( {
754+ getApiSpecification,
755+ getResource : vi . fn ( ) . mockResolvedValue ( undefined ) ,
756+ } ) ;
757+ const store = createMockStore ( ) ;
758+
759+ const result = await extractApiResources (
760+ client , store , testContext ,
761+ { type : ResourceType . Api , nameParts : [ 'mcp-api' ] } ,
762+ { name : 'mcp-api' , properties : { type : 'mcp' } } ,
763+ '/output'
764+ ) ;
765+
766+ expect ( result . specification ) . toBe ( false ) ;
767+ expect ( getApiSpecification ) . not . toHaveBeenCalled ( ) ;
768+ expect ( store . writeContent ) . not . toHaveBeenCalledWith (
769+ expect . anything ( ) , expect . anything ( ) , expect . anything ( ) , 'specification' , expect . anything ( )
770+ ) ;
771+ } ) ;
772+
773+ it ( 'should skip specification export for MCP APIs regardless of type casing' , async ( ) => {
774+ const getApiSpecification = vi . fn ( ) ;
775+ const client = createMockClient ( {
776+ getApiSpecification,
777+ getResource : vi . fn ( ) . mockResolvedValue ( undefined ) ,
778+ } ) ;
779+ const store = createMockStore ( ) ;
780+
781+ const result = await extractApiResources (
782+ client , store , testContext ,
783+ { type : ResourceType . Api , nameParts : [ 'mcp-api' ] } ,
784+ { name : 'mcp-api' , properties : { type : 'MCP' } } ,
785+ '/output'
786+ ) ;
787+
788+ expect ( result . specification ) . toBe ( false ) ;
789+ expect ( getApiSpecification ) . not . toHaveBeenCalled ( ) ;
790+ } ) ;
791+
792+ it ( 'should extract MCP server configuration when present' , async ( ) => {
793+ const mcpJson = {
794+ name : 'default' ,
795+ properties : {
796+ modelContextProtocol : { enabled : true , endpoint : 'https://apim.azure-api.net/my-api/mcp' } ,
797+ } ,
798+ } ;
799+ const client = createMockClient ( {
800+ getApiSpecification : vi . fn ( ) . mockResolvedValue ( undefined ) ,
801+ getResource : vi . fn ( ) . mockImplementation ( async ( _ctx : unknown , desc : ResourceDescriptor ) => {
802+ if ( desc . type === ResourceType . McpServer ) {
803+ return mcpJson ;
804+ }
805+ return undefined ;
806+ } ) ,
807+ } ) ;
808+ const store = createMockStore ( ) ;
809+ const apiDescriptor : ResourceDescriptor = {
810+ type : ResourceType . Api ,
811+ nameParts : [ 'my-api' ] ,
812+ } ;
813+
814+ const result = await extractApiResources (
815+ client , store , testContext , apiDescriptor ,
816+ { name : 'my-api' } ,
817+ '/output'
818+ ) ;
819+
820+ expect ( result . mcpServer ) . toBe ( true ) ;
821+ expect ( store . writeResource ) . toHaveBeenCalledWith (
822+ '/output' ,
823+ expect . objectContaining ( { type : ResourceType . McpServer , nameParts : [ 'my-api' ] } ) ,
824+ mcpJson
825+ ) ;
826+ } ) ;
827+
828+ it ( 'should return mcpServer=false and not throw when MCP server getResource returns undefined' , async ( ) => {
829+ const client = createMockClient ( {
830+ getApiSpecification : vi . fn ( ) . mockResolvedValue ( undefined ) ,
831+ getResource : vi . fn ( ) . mockResolvedValue ( undefined ) ,
832+ } ) ;
833+ const store = createMockStore ( ) ;
834+ const apiDescriptor : ResourceDescriptor = {
835+ type : ResourceType . Api ,
836+ nameParts : [ 'my-api' ] ,
837+ } ;
838+
839+ const result = await extractApiResources (
840+ client , store , testContext , apiDescriptor ,
841+ { name : 'my-api' } ,
842+ '/output'
843+ ) ;
844+
845+ expect ( result . mcpServer ) . toBe ( false ) ;
846+ } ) ;
847+
848+ it ( 'should return mcpServer=false and not throw when getResource throws for McpServer' , async ( ) => {
849+ const client = createMockClient ( {
850+ getApiSpecification : vi . fn ( ) . mockResolvedValue ( undefined ) ,
851+ getResource : vi . fn ( ) . mockImplementation ( async ( _ctx : unknown , desc : ResourceDescriptor ) => {
852+ if ( desc . type === ResourceType . McpServer ) {
853+ throw new Error ( '404 Not Found' ) ;
854+ }
855+ return undefined ;
856+ } ) ,
857+ } ) ;
858+ const store = createMockStore ( ) ;
859+ const apiDescriptor : ResourceDescriptor = {
860+ type : ResourceType . Api ,
861+ nameParts : [ 'my-api' ] ,
862+ } ;
863+
864+ const result = await extractApiResources (
865+ client , store , testContext , apiDescriptor ,
866+ { name : 'my-api' } ,
867+ '/output'
868+ ) ;
869+
870+ expect ( result . mcpServer ) . toBe ( false ) ;
871+ } ) ;
750872 } ) ;
751873} ) ;
752874
0 commit comments