Skip to content

Commit c576316

Browse files
committed
Fix: MCP Server directory location in Windows (updated)
1 parent 7191b0a commit c576316

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/core/webview/ClineProvider.ts

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import axios from "axios"
33
import fs from "fs/promises"
44
import os from "os"
55
import crypto from "crypto"
6+
import { execa } from "execa"
67
import pWaitFor from "p-wait-for"
78
import * as path from "path"
89
import * as vscode from "vscode"
@@ -725,8 +726,28 @@ export class ClineProvider implements vscode.WebviewViewProvider {
725726

726727
// MCP
727728

729+
async getDocumentsPath(): Promise<string> {
730+
if (process.platform === "win32") {
731+
// If the user is running Win 7/Win Server 2008 r2+, we want to get the correct path to their Documents directory.
732+
try {
733+
const { stdout: docsPath } = await execa("powershell", [
734+
"-NoProfile", // Ignore user's PowerShell profile(s)
735+
"-Command",
736+
"[System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments)",
737+
])
738+
return docsPath.trim()
739+
} catch (err) {
740+
console.error("Failed to retrieve Windows Documents path. Falling back to homedir/Documents.")
741+
return path.join(os.homedir(), "Documents")
742+
}
743+
} else {
744+
return path.join(os.homedir(), "Documents") // On POSIX (macOS, Linux, etc.), assume ~/Documents by default (existing behavior, but may want to implement similar logic here)
745+
}
746+
}
747+
728748
async ensureMcpServersDirectoryExists(): Promise<string> {
729-
const mcpServersDir = path.join(os.homedir(), "Documents", "Cline", "MCP")
749+
const userDocumentsPath = await this.getDocumentsPath()
750+
const mcpServersDir = path.join(userDocumentsPath, "Cline", "MCP")
730751
try {
731752
await fs.mkdir(mcpServersDir, { recursive: true })
732753
} catch (error) {

0 commit comments

Comments
 (0)