Skip to content
Open
Changes from all 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
23 changes: 19 additions & 4 deletions src/commands/mcpJson.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ function getPlatformDockerCommand(): { command: string; args: string[] } {
"run",
"--rm",
"-i",
"--pull=always",
"-v",
"${workspaceFolder}:/workspace",
"-e",
Expand All @@ -38,7 +39,7 @@ function getPlatformDockerCommand(): { command: string; args: string[] } {
command: "bash",
args: [
"-c",
'docker run --rm -i -v "${workspaceFolder}:/workspace" -e "WORKSPACE_ROOT=/workspace" -e "FASTEDGE_API_KEY=$FASTEDGE_API_KEY" -e "FASTEDGE_API_URL=$FASTEDGE_API_URL" ghcr.io/g-core/fastedge-mcp-server:latest',
'docker run --rm -i --pull=always -v "${workspaceFolder}:/workspace" -e "WORKSPACE_ROOT=/workspace" -e "FASTEDGE_API_KEY=$FASTEDGE_API_KEY" -e "FASTEDGE_API_URL=$FASTEDGE_API_URL" ghcr.io/g-core/fastedge-mcp-server:latest',
],
};
}
Expand Down Expand Up @@ -101,12 +102,25 @@ async function createMCPJson(context?: vscode.ExtensionContext) {
);

let existingMCPJson = {} as MCPConfiguration;
let existingRawContent: string | null = null;
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 */
}
Comment on lines 106 to +111
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.

if (existingRawContent !== null) {
try {
existingMCPJson = JSON.parse(existingRawContent);
} catch (error: any) {
Comment on lines +113 to +116
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.
// 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;
}
Comment on lines +117 to +123
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.
}

if (
Expand Down Expand Up @@ -257,6 +271,7 @@ async function createMCPJson(context?: vscode.ExtensionContext) {
: "Linux";

const mcpJsonContent = {
...existingMCPJson,
servers: {
...existingMCPJson.servers,
"fastedge-assistant": {
Expand Down
Loading