Skip to content

Commit

Permalink
Merge pull request cline#1409 from cline/win-mcp-server-directory
Browse files Browse the repository at this point in the history
Fix: MCP Server directory location in Windows
  • Loading branch information
dcbartlett authored Jan 24, 2025
2 parents f915fb2 + c576316 commit 16fbfe1
Showing 1 changed file with 22 additions and 1 deletion.
23 changes: 22 additions & 1 deletion src/core/webview/ClineProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import axios from "axios"
import fs from "fs/promises"
import os from "os"
import crypto from "crypto"
import { execa } from "execa"
import pWaitFor from "p-wait-for"
import * as path from "path"
import * as vscode from "vscode"
Expand Down Expand Up @@ -725,8 +726,28 @@ export class ClineProvider implements vscode.WebviewViewProvider {

// MCP

async getDocumentsPath(): Promise<string> {
if (process.platform === "win32") {
// If the user is running Win 7/Win Server 2008 r2+, we want to get the correct path to their Documents directory.
try {
const { stdout: docsPath } = await execa("powershell", [
"-NoProfile", // Ignore user's PowerShell profile(s)
"-Command",
"[System.Environment]::GetFolderPath([System.Environment+SpecialFolder]::MyDocuments)",
])
return docsPath.trim()
} catch (err) {
console.error("Failed to retrieve Windows Documents path. Falling back to homedir/Documents.")
return path.join(os.homedir(), "Documents")
}
} else {
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)
}
}

async ensureMcpServersDirectoryExists(): Promise<string> {
const mcpServersDir = path.join(os.homedir(), "Documents", "Cline", "MCP")
const userDocumentsPath = await this.getDocumentsPath()
const mcpServersDir = path.join(userDocumentsPath, "Cline", "MCP")
try {
await fs.mkdir(mcpServersDir, { recursive: true })
} catch (error) {
Expand Down

0 comments on commit 16fbfe1

Please sign in to comment.