@@ -35,19 +35,68 @@ export class MCPDownloadSnippetsExecuteStep extends AzureWizardExecuteStepWithAc
3535 progress . report ( { message : localize ( 'downloadingSampleCodeExecute' , 'Downloading sample server code...' ) } ) ;
3636 const sampleMcpRepoUrl : string = nonNullProp ( context , 'sampleMcpRepoUrl' ) ;
3737 const sampleFiles : GitHubFileMetadata [ ] = await feedUtils . getJsonFeed ( context , sampleMcpRepoUrl ) ;
38- await this . downloadFilesRecursively ( context , sampleFiles , context . projectPath ) ;
38+ const downloadedFiles = await this . downloadFilesRecursively ( context , sampleFiles , context . projectPath ) ;
39+ context . sampleToolFilePath = MCPDownloadSnippetsExecuteStep . selectSampleToolFile ( context . serverLanguage , downloadedFiles ) ;
3940 }
4041
41- private async downloadFilesRecursively ( context : MCPProjectWizardContext , items : GitHubFileMetadata [ ] , basePath : string ) : Promise < void > {
42+ // Known entrypoint paths relative to the root of each language's sample GitHub repository
43+ private static readonly knownToolPaths : Partial < Record < ProjectLanguage , string > > = {
44+ [ ProjectLanguage . TypeScript ] : 'src/index.ts' ,
45+ [ ProjectLanguage . Python ] : 'hello.py' ,
46+ [ ProjectLanguage . CSharp ] : 'Tools/HelloTool.cs' ,
47+ } ;
48+
49+ private static readonly languageExtensions : Partial < Record < ProjectLanguage , string > > = {
50+ [ ProjectLanguage . TypeScript ] : '.ts' ,
51+ [ ProjectLanguage . Python ] : '.py' ,
52+ [ ProjectLanguage . CSharp ] : '.cs' ,
53+ } ;
54+
55+ private static selectSampleToolFile (
56+ language : ProjectLanguage | undefined ,
57+ files : { itemPath : string ; destPath : string } [ ]
58+ ) : string | undefined {
59+ if ( ! language ) {
60+ return undefined ;
61+ }
62+
63+ // Prefer the known entrypoint path for the language
64+ const knownPath = MCPDownloadSnippetsExecuteStep . knownToolPaths [ language ] ;
65+ if ( knownPath ) {
66+ const match = files . find ( f => f . itemPath === knownPath ) ;
67+ if ( match ) {
68+ return match . destPath ;
69+ }
70+ }
71+
72+ // Fallback: any file with the right extension, sorted for determinism
73+ const sourceExt = MCPDownloadSnippetsExecuteStep . languageExtensions [ language ] ;
74+ if ( sourceExt ) {
75+ const candidates = files
76+ . filter ( f => f . destPath . endsWith ( sourceExt ) )
77+ . sort ( ( a , b ) => a . itemPath . localeCompare ( b . itemPath ) ) ;
78+ return candidates [ 0 ] ?. destPath ;
79+ }
80+
81+ return undefined ;
82+ }
83+
84+ private async downloadFilesRecursively (
85+ context : MCPProjectWizardContext ,
86+ items : GitHubFileMetadata [ ] ,
87+ basePath : string
88+ ) : Promise < { itemPath : string ; destPath : string } [ ] > {
89+ const downloadedFiles : { itemPath : string ; destPath : string } [ ] = [ ] ;
4290 // Download all files and directories at this level in parallel
4391 await Promise . all ( items . map ( async ( item ) => {
4492 if ( item . type === 'file' ) {
45- await MCPDownloadSnippetsExecuteStep . downloadSingleFile ( {
93+ const destPath = await MCPDownloadSnippetsExecuteStep . downloadSingleFile ( {
4694 context, item,
4795 destDirPath : basePath ,
4896 serverLanguage : context . serverLanguage ,
4997 projectName : path . basename ( context . projectPath )
5098 } ) ;
99+ downloadedFiles . push ( { itemPath : item . path , destPath } ) ;
51100 } else if ( item . type === 'dir' ) {
52101 // Create directory
53102 const dirPath : string = path . join ( basePath , item . name ) ;
@@ -58,9 +107,11 @@ export class MCPDownloadSnippetsExecuteStep extends AzureWizardExecuteStepWithAc
58107 const dirContents : GitHubFileMetadata [ ] = parseJson < GitHubFileMetadata [ ] > ( nonNullProp ( response , 'bodyAsText' ) ) ;
59108
60109 // Recursively download directory contents
61- await this . downloadFilesRecursively ( context , dirContents , dirPath ) ;
110+ const subFiles = await this . downloadFilesRecursively ( context , dirContents , dirPath ) ;
111+ downloadedFiles . push ( ...subFiles ) ;
62112 }
63113 } ) ) ;
114+ return downloadedFiles ;
64115 }
65116
66117 public shouldExecute ( context : MCPProjectWizardContext ) : boolean {
@@ -73,7 +124,7 @@ export class MCPDownloadSnippetsExecuteStep extends AzureWizardExecuteStepWithAc
73124 destDirPath : string ,
74125 projectName : string
75126 serverLanguage ?: ProjectLanguage ,
76- } ) : Promise < void > {
127+ } ) : Promise < string > {
77128 const { context, item, destDirPath, serverLanguage, projectName } = options ;
78129 const fileUrl : string = item . download_url ;
79130 let destinationPath : string = path . join ( destDirPath , item . name ) ;
@@ -92,5 +143,6 @@ export class MCPDownloadSnippetsExecuteStep extends AzureWizardExecuteStepWithAc
92143 }
93144 }
94145 await AzExtFsExtra . writeFile ( destinationPath , fileContent ?? '' ) ;
146+ return destinationPath ;
95147 }
96148}
0 commit comments