Skip to content

Commit 1d97429

Browse files
toggle MCP
1 parent d0cdabe commit 1d97429

File tree

5 files changed

+83
-29
lines changed

5 files changed

+83
-29
lines changed

package.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,16 @@
4646
"activationEvents": [],
4747
"main": "./dist/extension.js",
4848
"contributes": {
49+
"configuration": {
50+
"title": "Cline",
51+
"properties": {
52+
"cline.mcp.includeInPrompt": {
53+
"type": "boolean",
54+
"default": true,
55+
"description": "Include MCP server functionality in AI prompts. When disabled, the AI will not be aware of MCP capabilities. This saves context window tokens."
56+
}
57+
}
58+
},
4959
"viewsContainers": {
5060
"activitybar": [
5161
{

src/core/Cline.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1192,6 +1192,14 @@ export class Cline {
11921192
mcpHub,
11931193
this.browserSettings,
11941194
)
1195+
this.providerRef
1196+
.deref()
1197+
?.log(
1198+
`System prompt length with MCP ${mcpHub.shouldIncludeInPrompt() ? "enabled" : "disabled"}: ${systemPrompt.length} characters`,
1199+
)
1200+
// console.error(
1201+
// `System prompt length with MCP ${mcpHub.shouldIncludeInPrompt() ? "enabled" : "disabled"}: ${systemPrompt.length} characters`,
1202+
// )
11951203
let settingsCustomInstructions = this.customInstructions?.trim()
11961204
const clineRulesFilePath = path.resolve(cwd, GlobalFileNames.clineRules)
11971205
let clineRulesFileInstructions: string | undefined

src/core/prompts/system.ts

Lines changed: 57 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ Usage:
177177
: ""
178178
}
179179
180+
${
181+
mcpHub.shouldIncludeInPrompt()
182+
? `
180183
## use_mcp_tool
181184
Description: Request to use a tool provided by a connected MCP server. Each MCP server can provide multiple tools with different capabilities. Tools have defined input schemas that specify required and optional parameters.
182185
Parameters:
@@ -205,6 +208,9 @@ Usage:
205208
<server_name>server name here</server_name>
206209
<uri>resource URI here</uri>
207210
</access_mcp_resource>
211+
`
212+
: ""
213+
}
208214
209215
## ask_followup_question
210216
Description: Ask the user a question to gather additional information needed to complete the task. This tool should be used when you encounter ambiguities, need clarification, or require more details to proceed effectively. It allows for interactive problem-solving by enabling direct communication with the user. Use this tool judiciously to maintain a balance between gathering necessary information and avoiding excessive back-and-forth.
@@ -238,27 +244,7 @@ Your final result description here
238244
<requires_approval>false</requires_approval>
239245
</execute_command>
240246
241-
## Example 2: Requesting to use an MCP tool
242-
243-
<use_mcp_tool>
244-
<server_name>weather-server</server_name>
245-
<tool_name>get_forecast</tool_name>
246-
<arguments>
247-
{
248-
"city": "San Francisco",
249-
"days": 5
250-
}
251-
</arguments>
252-
</use_mcp_tool>
253-
254-
## Example 3: Requesting to access an MCP resource
255-
256-
<access_mcp_resource>
257-
<server_name>weather-server</server_name>
258-
<uri>weather://san-francisco/current</uri>
259-
</access_mcp_resource>
260-
261-
## Example 4: Requesting to create a new file
247+
## Example 2: Requesting to create a new file
262248
263249
<write_to_file>
264250
<path>src/frontend-config.json</path>
@@ -280,7 +266,7 @@ Your final result description here
280266
</content>
281267
</write_to_file>
282268
283-
## Example 6: Requesting to make targeted edits to a file
269+
## Example 3: Requesting to make targeted edits to a file
284270
285271
<replace_in_file>
286272
<path>src/components/App.tsx</path>
@@ -314,6 +300,31 @@ return (
314300
>>>>>>> REPLACE
315301
</diff>
316302
</replace_in_file>
303+
${
304+
mcpHub.shouldIncludeInPrompt()
305+
? `
306+
307+
## Example 4: Requesting to use an MCP tool
308+
309+
<use_mcp_tool>
310+
<server_name>weather-server</server_name>
311+
<tool_name>get_forecast</tool_name>
312+
<arguments>
313+
{
314+
"city": "San Francisco",
315+
"days": 5
316+
}
317+
</arguments>
318+
</use_mcp_tool>
319+
320+
## Example 5: Requesting to access an MCP resource
321+
322+
<access_mcp_resource>
323+
<server_name>weather-server</server_name>
324+
<uri>weather://san-francisco/current</uri>
325+
</access_mcp_resource>`
326+
: ""
327+
}
317328
318329
# Tool Use Guidelines
319330
@@ -336,6 +347,9 @@ It is crucial to proceed step-by-step, waiting for the user's message after each
336347
337348
By waiting for and carefully considering the user's response after each tool use, you can react accordingly and make informed decisions about how to proceed with the task. This iterative process helps ensure the overall success and accuracy of your work.
338349
350+
${
351+
mcpHub.shouldIncludeInPrompt()
352+
? `
339353
====
340354
341355
MCP SERVERS
@@ -727,11 +741,11 @@ npm run build
727741
## Editing MCP Servers
728742
729743
The user may ask to add tools or resources that may make sense to add to an existing MCP server (listed under 'Connected MCP Servers' above: ${
730-
mcpHub
731-
.getServers()
732-
.map((server) => server.name)
733-
.join(", ") || "(None running currently)"
734-
}, e.g. if it would use the same API. This would be possible if you can locate the MCP server repository on the user's system by looking at the server arguments for a filepath. You might then use list_files and read_file to explore the files in the repository, and use replace_in_file to make changes to the files.
744+
mcpHub
745+
.getServers()
746+
.map((server) => server.name)
747+
.join(", ") || "(None running currently)"
748+
}, e.g. if it would use the same API. This would be possible if you can locate the MCP server repository on the user's system by looking at the server arguments for a filepath. You might then use list_files and read_file to explore the files in the repository, and use replace_in_file to make changes to the files.
735749
736750
However some MCP servers may be running from installed packages rather than a local repository, in which case it may make more sense to create a new MCP server.
737751
@@ -740,7 +754,9 @@ However some MCP servers may be running from installed packages rather than a lo
740754
The user may not always request the use or creation of MCP servers. Instead, they might provide tasks that can be completed with existing tools. While using the MCP SDK to extend your capabilities can be useful, it's important to understand that this is just one specialized type of task you can accomplish. You should only implement MCP servers when the user explicitly requests it (e.g., "add a tool that...").
741755
742756
Remember: The MCP documentation and example provided above are to help you understand and work with existing MCP servers or create new ones when requested by the user. You already have access to tools and capabilities that can be used to accomplish a wide range of tasks.
743-
757+
`
758+
: ""
759+
}
744760
====
745761
746762
EDITING FILES
@@ -832,7 +848,13 @@ CAPABILITIES
832848
? "\n- You can use the browser_action tool to interact with websites (including html files and locally running development servers) through a Puppeteer-controlled browser when you feel it is necessary in accomplishing the user's task. This tool is particularly useful for web development tasks as it allows you to launch a browser, navigate to pages, interact with elements through clicks and keyboard input, and capture the results through screenshots and console logs. This tool may be useful at key stages of web development tasks-such as after implementing new features, making substantial changes, when troubleshooting issues, or to verify the result of your work. You can analyze the provided screenshots to ensure correct rendering or identify errors, and review console logs for runtime issues.\n - For example, if asked to add a component to a react website, you might create the necessary files, use execute_command to run the site locally, then use browser_action to launch the browser, navigate to the local server, and verify the component renders & functions correctly before closing the browser."
833849
: ""
834850
}
851+
${
852+
mcpHub.shouldIncludeInPrompt()
853+
? `
835854
- You have access to MCP servers that may provide additional tools and resources. Each server may provide different capabilities that you can use to accomplish tasks more effectively.
855+
`
856+
: ""
857+
}
836858
837859
====
838860
@@ -861,14 +883,20 @@ RULES
861883
- When presented with images, utilize your vision capabilities to thoroughly examine them and extract meaningful information. Incorporate these insights into your thought process as you accomplish the user's task.
862884
- At the end of each user message, you will automatically receive environment_details. This information is not written by the user themselves, but is auto-generated to provide potentially relevant context about the project structure and environment. While this information can be valuable for understanding the project context, do not treat it as a direct part of the user's request or response. Use it to inform your actions and decisions, but don't assume the user is explicitly asking about or referring to this information unless they clearly do so in their message. When using environment_details, explain your actions clearly to ensure the user understands, as they may not be aware of these details.
863885
- Before executing commands, check the "Actively Running Terminals" section in environment_details. If present, consider how these active processes might impact your task. For example, if a local development server is already running, you wouldn't need to start it again. If no active terminals are listed, proceed with command execution as normal.
864-
- MCP operations should be used one at a time, similar to other tool usage. Wait for confirmation of success before proceeding with additional operations.
865886
- When using the replace_in_file tool, you must include complete lines in your SEARCH blocks, not partial lines. The system requires exact line matches and cannot match partial lines. For example, if you want to match a line containing "const x = 5;", your SEARCH block must include the entire line, not just "x = 5" or other fragments.
866887
- When using the replace_in_file tool, if you use multiple SEARCH/REPLACE blocks, list them in the order they appear in the file. For example if you need to make changes to both line 10 and line 50, first include the SEARCH/REPLACE block for line 10, followed by the SEARCH/REPLACE block for line 50.
867888
- It is critical you wait for the user's response after each tool use, in order to confirm the success of the tool use. For example, if asked to make a todo app, you would create a file, wait for the user's response it was created successfully, then create another file if needed, wait for the user's response it was created successfully, etc.${
868889
supportsComputerUse
869890
? " Then if you want to test your work, you might use browser_action to launch the site, wait for the user's response confirming the site was launched along with a screenshot, then perhaps e.g., click a button to test functionality if needed, wait for the user's response confirming the button was clicked along with a screenshot of the new state, before finally closing the browser."
870891
: ""
871892
}
893+
${
894+
mcpHub.shouldIncludeInPrompt()
895+
? `
896+
- MCP operations should be used one at a time, similar to other tool usage. Wait for confirmation of success before proceeding with additional operations.
897+
`
898+
: ""
899+
}
872900
873901
====
874902

src/core/webview/ClineProvider.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,10 @@ export class ClineProvider implements vscode.WebviewViewProvider {
8484
mcpHub?: McpHub
8585
private latestAnnouncementId = "jan-6-2025" // update to some unique identifier when we add a new announcement
8686

87+
public log(message: string) {
88+
this.outputChannel.appendLine(message)
89+
}
90+
8791
constructor(
8892
readonly context: vscode.ExtensionContext,
8993
private readonly outputChannel: vscode.OutputChannel,

src/services/mcp/McpHub.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,10 @@ export class McpHub {
5454
return this.connections.map((conn) => conn.server)
5555
}
5656

57+
shouldIncludeInPrompt(): boolean {
58+
return vscode.workspace.getConfiguration("cline.mcp").get("includeInPrompt") ?? true
59+
}
60+
5761
async getMcpServersPath(): Promise<string> {
5862
const provider = this.providerRef.deref()
5963
if (!provider) {

0 commit comments

Comments
 (0)