Skip to content

Open the sample file and the mcp.json in a split editor when creating self-hosted MCP projects#4946

Merged
nturinski merged 4 commits intomainfrom
nat/openMcpSampleFile
Mar 31, 2026
Merged

Open the sample file and the mcp.json in a split editor when creating self-hosted MCP projects#4946
nturinski merged 4 commits intomainfrom
nat/openMcpSampleFile

Conversation

@nturinski
Copy link
Copy Markdown
Member

@nturinski nturinski commented Mar 30, 2026

  • Identify non-deterministic sampleToolFilePath selection issue in MCPDownloadSnippetsExecuteStep.ts
  • Refactor downloadFilesRecursively to collect {itemPath, destPath} tuples and return them (no context mutation during parallel downloads)
  • Add knownToolPaths map for exact entrypoint matching per language (src/index.ts, hello.py, Tools/HelloTool.cs)
  • Add selectSampleToolFile static method: exact known-path match first, lexicographically-sorted extension fallback
  • Set context.sampleToolFilePath once after all downloads complete

@nturinski nturinski requested a review from a team as a code owner March 30, 2026 18:00
Copilot AI review requested due to automatic review settings March 30, 2026 18:00
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR updates the self-hosted MCP server project creation flow to automatically open .vscode/mcp.json and the downloaded sample tool source file side-by-side, improving discoverability and onboarding (per Issue #4882).

Changes:

  • Open .vscode/mcp.json in the editor after project creation.
  • Track a “sample tool file” during snippet download and open it in a split editor alongside mcp.json.
  • Extend the project wizard context to carry the tracked sample tool file path.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
src/commands/createNewProject/mcpServerSteps/MCPOpenFileStep.ts Opens mcp.json and the sample tool file in specific editor columns to create a split view.
src/commands/createNewProject/mcpServerSteps/MCPDownloadSnippetsExecuteStep.ts Tracks a candidate “sample tool file” path while downloading snippets (and returns destination paths from downloads).
src/commands/createNewProject/IProjectWizardContext.ts Adds sampleToolFilePath to the MCP wizard context.

Comment on lines +47 to +61
private async downloadFilesRecursively(context: MCPProjectWizardContext, items: GitHubFileMetadata[], basePath: string): Promise<void> {
const sourceExt = context.serverLanguage ? MCPDownloadSnippetsExecuteStep.languageExtensions[context.serverLanguage] : undefined;
// Download all files and directories at this level in parallel
await Promise.all(items.map(async (item) => {
if (item.type === 'file') {
await MCPDownloadSnippetsExecuteStep.downloadSingleFile({
const destPath = await MCPDownloadSnippetsExecuteStep.downloadSingleFile({
context, item,
destDirPath: basePath,
serverLanguage: context.serverLanguage,
projectName: path.basename(context.projectPath)
});
// Track the first source file matching the server language as the sample tool file
if (!context.sampleToolFilePath && sourceExt && destPath.endsWith(sourceExt)) {
context.sampleToolFilePath = destPath;
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sampleToolFilePath is set inside a Promise.all over downloads. Because the downloads resolve in nondeterministic order, the "first" matching file picked here is effectively whichever finishes first (and can even be overwritten if multiple resolves hit before the flag is observed). Consider collecting candidate paths during the traversal and selecting deterministically after the parallel work completes (e.g., prefer known tool paths per language using item.path, or pick by stable sort order) rather than mutating context from concurrent tasks.

Copilot uses AI. Check for mistakes.
Comment on lines +58 to +61
// Track the first source file matching the server language as the sample tool file
if (!context.sampleToolFilePath && sourceExt && destPath.endsWith(sourceExt)) {
context.sampleToolFilePath = destPath;
}
Copy link

Copilot AI Mar 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using destPath.endsWith(sourceExt) to identify the tool file is fairly loose and can select the wrong file as soon as the sample repo contains more than one source file for that language (and it also ignores the known expected paths from the issue, e.g. src/index.ts, hello.py, Tools/HelloTool.cs). Prefer matching on item.path against those known relative paths (with a fallback strategy) to make the file that opens predictable and aligned with the intended entrypoint.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Applied in commit 5856acf. The changes:

  • Refactored downloadFilesRecursively to collect {itemPath, destPath} tuples and return them instead of mutating context inside a concurrent Promise.all
  • Added a knownToolPaths map with the exact repo-relative entrypoints (src/index.ts, hello.py, Tools/HelloTool.cs)
  • Added a selectSampleToolFile static method that first matches on item.path against the known paths, then falls back to a lexicographically-sorted extension-based search for determinism
  • context.sampleToolFilePath is now assigned once after all downloads complete

Comment thread src/commands/createNewProject/mcpServerSteps/MCPOpenFileStep.ts Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@nturinski nturinski merged commit 710b226 into main Mar 31, 2026
2 checks passed
@nturinski nturinski deleted the nat/openMcpSampleFile branch March 31, 2026 16:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants