Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/commands/createNewProject/NewProjectLanguageStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import { DotnetRuntimeStep } from './dotnetSteps/DotnetRuntimeStep';
import { addJavaCreateProjectSteps } from './javaSteps/addJavaCreateProjectSteps';
import { MCPDownloadSnippetsExecuteStep } from './mcpServerSteps/MCPDownloadSnippetsExecuteStep';
import { MCPDownloadSnippetsPromptStep } from './mcpServerSteps/MCPDownloadSnippetsPromptStep';
import { MCPOpenFileStep } from './mcpServerSteps/MCPOpenFileStep';
import { MCPProjectCreateStep } from './mcpServerSteps/MCPProjectCreateStep';
import { MCPServerLanguagePromptStep } from './mcpServerSteps/MCPServerLanguagePromptStep';

Expand Down Expand Up @@ -127,7 +128,7 @@ export class NewProjectLanguageStep extends AzureWizardPromptStep<IProjectWizard
break;
case ProjectLanguage.SelfHostedMCPServer:
promptSteps.push(new MCPServerLanguagePromptStep(), new MCPDownloadSnippetsPromptStep());
executeSteps.push(new MCPDownloadSnippetsExecuteStep(), new MCPProjectCreateStep());
executeSteps.push(new MCPDownloadSnippetsExecuteStep(), new MCPProjectCreateStep(), new MCPOpenFileStep());
break;
default:
executeSteps.push(new ScriptProjectCreateStep());
Expand Down
38 changes: 38 additions & 0 deletions src/commands/createNewProject/mcpServerSteps/MCPOpenFileStep.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { AzExtFsExtra, AzureWizardExecuteStep } from '@microsoft/vscode-azext-utils';
import * as path from 'path';
import { Uri, window, workspace } from 'vscode';
import { type MCPProjectWizardContext } from '../IProjectWizardContext';

export class MCPOpenFileStep extends AzureWizardExecuteStep<MCPProjectWizardContext> {
public priority: number = 240; // Execute before OpenFolderStep (priority 250) but after other project setup

public async execute(context: MCPProjectWizardContext): Promise<void> {
const mcpJsonFilePath: string = path.join(context.projectPath, '.vscode', 'mcp.json');

if (await AzExtFsExtra.pathExists(mcpJsonFilePath)) {
const mcpJsonFile = await workspace.openTextDocument(Uri.file(mcpJsonFilePath));
await window.showTextDocument(mcpJsonFile, { preview: false });
}
}

public shouldExecute(context: MCPProjectWizardContext): boolean {
// Only execute if we're not opening the folder in a way that would reload the window
// If opening in current window or new window, the file open would be lost during reload
const openFolders = workspace.workspaceFolders || [];

// Handle AddToWorkspace: only if there are existing workspace folders
// (OpenFolderStep changes AddToWorkspace to OpenInCurrentWindow if no folders exist)
if (context.openBehavior === 'AddToWorkspace') {
return openFolders.length > 0;
}

// Always execute for these cases
return context.openBehavior === 'AlreadyOpen' ||
context.openBehavior === 'DontOpen';
}
}