Skip to content

Commit 854d101

Browse files
committed
fix: validate MCP tool is not disabled before execution
- Check enabledForPrompt property in validateToolExists function - Reject disabled tools with appropriate error message - Show only enabled tools in error message when tool is disabled Addresses PR feedback about checking for disabled tools
1 parent 326268a commit 854d101

File tree

1 file changed

+20
-3
lines changed

1 file changed

+20
-3
lines changed

src/core/tools/useMcpToolTool.ts

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,9 +134,9 @@ async function validateToolExists(
134134
}
135135

136136
// Check if the requested tool exists
137-
const toolExists = server.tools.some((tool) => tool.name === toolName)
137+
const tool = server.tools.find((tool) => tool.name === toolName)
138138

139-
if (!toolExists) {
139+
if (!tool) {
140140
// Tool not found - provide list of available tools
141141
const availableToolNames = server.tools.map((tool) => tool.name)
142142

@@ -155,7 +155,24 @@ async function validateToolExists(
155155
return { isValid: false, availableTools: availableToolNames }
156156
}
157157

158-
// Tool exists
158+
// Check if the tool is disabled (enabledForPrompt is false)
159+
if (tool.enabledForPrompt === false) {
160+
// Tool is disabled - only show enabled tools
161+
const enabledTools = server.tools.filter((t) => t.enabledForPrompt !== false)
162+
const enabledToolNames = enabledTools.map((t) => t.name)
163+
164+
cline.consecutiveMistakeCount++
165+
cline.recordToolError("use_mcp_tool")
166+
await cline.say(
167+
"error",
168+
`Tool '${toolName}' on server '${serverName}' is disabled. Available enabled tools: ${enabledToolNames.length > 0 ? enabledToolNames.join(", ") : "No enabled tools available"}`,
169+
)
170+
171+
pushToolResult(formatResponse.unknownMcpToolError(serverName, toolName, enabledToolNames))
172+
return { isValid: false, availableTools: enabledToolNames }
173+
}
174+
175+
// Tool exists and is enabled
159176
return { isValid: true, availableTools: server.tools.map((tool) => tool.name) }
160177
} catch (error) {
161178
// If there's an error during validation, log it but don't block the tool execution

0 commit comments

Comments
 (0)