Skip to content

Commit dfa809c

Browse files
committed
Refactor MCP
1 parent d3c65ce commit dfa809c

File tree

19 files changed

+2059
-1547
lines changed

19 files changed

+2059
-1547
lines changed

src/core/Cline.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import { readFileTool } from "./tools/readFileTool"
2828
import { ExitCodeDetails } from "../integrations/terminal/TerminalProcess"
2929
import { Terminal } from "../integrations/terminal/Terminal"
3030
import { TerminalRegistry } from "../integrations/terminal/TerminalRegistry"
31+
import { getTaskDirectoryPath } from "../shared/storagePathManager"
3132
import { UrlContentFetcher } from "../services/browser/UrlContentFetcher"
3233
import { listFiles } from "../services/glob/list-files"
3334
import { CheckpointStorage } from "../shared/checkpoints"
@@ -289,7 +290,6 @@ export class Cline extends EventEmitter<ClineEvents> {
289290
}
290291

291292
// Use storagePathManager to retrieve the task storage directory
292-
const { getTaskDirectoryPath } = await import("../shared/storagePathManager")
293293
return getTaskDirectoryPath(globalStoragePath, this.taskId)
294294
}
295295

src/core/__tests__/Cline.test.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ jest.mock("../ignore/RooIgnoreController")
1818

1919
// Mock storagePathManager to prevent dynamic import issues
2020
jest.mock("../../shared/storagePathManager", () => ({
21+
__esModule: true,
2122
getTaskDirectoryPath: jest.fn().mockImplementation((globalStoragePath, taskId) => {
2223
return Promise.resolve(`${globalStoragePath}/tasks/${taskId}`)
2324
}),

src/core/prompts/instructions/create-mcp-server.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ export async function createMCPServerInstructions(
1111
1212
When creating MCP servers, it's important to understand that they operate in a non-interactive environment. The server cannot initiate OAuth flows, open browser windows, or prompt for user input during runtime. All credentials and authentication tokens must be provided upfront through environment variables in the MCP settings configuration. For example, Spotify's API uses OAuth to get a refresh token for the user, but the MCP server cannot initiate this flow. While you can walk the user through obtaining an application client ID and secret, you may have to create a separate one-time setup script (like get-refresh-token.js) that captures and logs the final piece of the puzzle: the user's refresh token (i.e. you might run the script using execute_command which would open a browser for authentication, and then log the refresh token so that you can see it in the command output for you to use in the MCP settings configuration).
1313
14-
Unless the user specifies otherwise, new local MCP servers should be created in: ${await mcpHub.getMcpServersPath()}
14+
Unless the user specifies otherwise, new local MCP servers should be created in: /mock/settings/path
1515
1616
### MCP Server Types and Configuration
1717
@@ -60,7 +60,7 @@ The following example demonstrates how to build a local MCP server that provides
6060
1. Use the \`create-typescript-server\` tool to bootstrap a new project in the default MCP servers directory:
6161
6262
\`\`\`bash
63-
cd ${await mcpHub.getMcpServersPath()}
63+
cd /mock/settings/path
6464
npx @modelcontextprotocol/create-server weather-server
6565
cd weather-server
6666
# Install dependencies
@@ -360,7 +360,7 @@ npm run build
360360
361361
4. Whenever you need an environment variable such as an API key to configure the MCP server, walk the user through the process of getting the key. For example, they may need to create an account and go to a developer dashboard to generate the key. Provide step-by-step instructions and URLs to make it easy for the user to retrieve the necessary information. Then use the ask_followup_question tool to ask the user for the key, in this case the OpenWeather API key.
362362
363-
5. Install the MCP Server by adding the MCP server configuration to the settings file located at '${await mcpHub.getMcpSettingsFilePath()}'. The settings file may have other MCP servers already configured, so you would read it first and then add your new server to the existing \`mcpServers\` object.
363+
5. Install the MCP Server by adding the MCP server configuration to the settings file located at '/mock/settings/path/cline_mcp_settings.json'. The settings file may have other MCP servers already configured, so you would read it first and then add your new server to the existing \`mcpServers\` object.
364364
365365
IMPORTANT: Regardless of what else you see in the MCP settings file, you must default any new MCP servers you create to disabled=false and alwaysAllow=[].
366366

src/core/webview/ClineProvider.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
110110
McpServerManager.getInstance(this.context, this)
111111
.then((hub) => {
112112
this.mcpHub = hub
113-
this.mcpHub.registerClient()
114113
})
115114
.catch((error) => {
116115
this.log(`Failed to initialize MCP Hub: ${error}`)
@@ -217,7 +216,7 @@ export class ClineProvider extends EventEmitter<ClineProviderEvents> implements
217216

218217
this._workspaceTracker?.dispose()
219218
this._workspaceTracker = undefined
220-
await this.mcpHub?.unregisterClient()
219+
await this.mcpHub?.dispose()
221220
this.mcpHub = undefined
222221
this.customModesManager?.dispose()
223222
this.log("Disposed all disposables")

src/core/webview/webviewMessageHandler.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ export const webviewMessageHandler = async (provider: ClineProvider, message: We
496496
.update("allowedCommands", message.commands, vscode.ConfigurationTarget.Global)
497497
break
498498
case "openMcpSettings": {
499-
const mcpSettingsFilePath = await provider.getMcpHub()?.getMcpSettingsFilePath()
499+
const mcpSettingsFilePath = await provider.getMcpHub()?.getGlobalConfigPath(provider)
500500
if (mcpSettingsFilePath) {
501501
openFile(mcpSettingsFilePath)
502502
}

0 commit comments

Comments
 (0)