Skip to content

add --pull=always#35

Open
godronus wants to merge 1 commit intomainfrom
fix/mcp-pull
Open

add --pull=always#35
godronus wants to merge 1 commit intomainfrom
fix/mcp-pull

Conversation

@godronus
Copy link
Copy Markdown
Collaborator

No description provided.

Copilot AI review requested due to automatic review settings April 24, 2026 16:45
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

Updates the generated MCP Docker command to always pull the latest container image, and adjusts mcp.json handling to better preserve existing configuration while avoiding overwriting invalid JSON.

Changes:

  • Add --pull=always to the Docker run invocation for both Windows and macOS/Linux.
  • Read existing .vscode/mcp.json as raw text first, then parse with explicit handling for invalid JSON (stop + show error).
  • Preserve existing top-level mcp.json keys by spreading ...existingMCPJson into the newly generated content.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/commands/mcpJson.ts
Comment on lines 106 to +111
try {
const fileData = await vscode.workspace.fs.readFile(mcpJsonPath);
const mcpJsonContent = Buffer.from(fileData).toString("utf8");
existingMCPJson = JSON.parse(mcpJsonContent);
existingRawContent = Buffer.from(fileData).toString("utf8");
} catch {
/* Do nothing - just means there is not an existing mcp.json */
/* File doesn't exist - OK, we'll create a new one */
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

The readFile() catch currently ignores all errors, but the comment assumes the file doesn't exist. This will also silently ignore cases like permission issues or transient FS errors and then proceed to overwrite/create mcp.json. Consider only swallowing the specific "file not found" error and surfacing other failures to the user (e.g., showErrorMessage and return).

Copilot uses AI. Check for mistakes.
Comment thread src/commands/mcpJson.ts
Comment on lines +113 to +116
if (existingRawContent !== null) {
try {
existingMCPJson = JSON.parse(existingRawContent);
} catch (error: any) {
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

After JSON.parse, the code assumes the parsed value is an object shaped like MCPConfiguration. If the file contains a valid non-object JSON value (array/string/number/null), later code will behave unexpectedly and may generate an invalid config. Add a runtime guard that the parsed value is a non-null plain object (and that servers, if present, is also an object) before treating it as MCPConfiguration; otherwise show an error and return.

Copilot uses AI. Check for mistakes.
Comment thread src/commands/mcpJson.ts
Comment on lines +117 to +123
// File exists but is not valid JSON (e.g., trailing comma, comments).
// Do NOT overwrite — tell the user to fix it manually.
vscode.window.showErrorMessage(
`Existing .vscode/mcp.json could not be parsed as JSON (${error?.message || error}). Please fix or remove the file before running this command.`,
);
return;
}
Copy link

Copilot AI Apr 24, 2026

Choose a reason for hiding this comment

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

This PR is titled "add --pull=always" but it also changes createMCPJson behavior: it now preserves top-level keys via ...existingMCPJson and, more importantly, it stops and shows an error if an existing mcp.json is invalid JSON (previously it would proceed and overwrite). Please update the PR title/description to reflect these additional user-facing behavior changes, or split into separate PRs.

Copilot uses AI. Check for mistakes.
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.

2 participants