Feature Request: Use alwaysAllow List as Pre-Validation Whitelist to Prevent Invalid MCP Tool Calls #2171
raymelon
started this conversation in
1. Feature requests
Replies: 1 comment
-
UPDATE: I made a PR implementing this: #2175 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Feature Request: Use
alwaysAllow
list as Pre-Validation Whitelist to Prevent guesswork on MCP Tool CallsUPDATE: I made a PR implementing this: #2175
Description
Kilo Code currently attempts MCP tool calls without validating tool existence on
alwaysAllow
list onmcp_settings.json
, leading to wasted time and tokens.An example is Kilo Code using invalid tools like "search" and "query" for deepwiki MCP despite
alwaysAllow
listing the valid tool names: "read_wiki_structure", "read_wiki_contents", "ask_question". Experienced it myself and I have to correct Kilo Code from time to time to use the correct tool names.The existing
alwaysAllow
list can be repurposed as a pre-validation whitelist to prevent this cycle of guesswork.Problem
The AI model attempts to use non-existent MCP tools like "search" and "query" because it can "hallucinate" or infer tool names that seem logical but don't actually exist on connected MCP servers. This leads to wasted time and tokens when these invalid tool calls are made.
Current Behavior
allwaysAllow
listRoot Cause
The issue occurs because the AI learns about available tools through the system prompt, but there's no filtering to prevent it from attempting tools that don't exist. Once the AI has already chosen a non-existent tool name in
useMcpToolTool()
, it's too late to change that choice.Proposed Solution (Updated)
Solution Approach
Filter tools at the system prompt generation level rather than trying to validate after the AI has already made its choice. This prevents the AI from ever knowing about non-existent tools.
Implementation Location
Modify the
getMcpServersSection
function in mcp-servers.ts:4-8 where MCP server information is formatted for the system prompt.What to Change
mcp-servers.ts:19-29
- enhance the existing filter that checksenabledForPrompt
alwaysAllow
validation - prioritize tools in thealwaysAllow
list (assume they exist)alwaysAllow
, validate they exist viafetchToolsList()
before including themKey Benefits of this approach
alwaysAllow
configuration fromMcpHub.ts:873-886
More Benefits
alwaysAllow
) tools via auto-approvalalwaysAllow
infrastructureResult
The AI model will only see and attempt to use MCP tools that are guaranteed to exist, eliminating the "search" and "query" inference problem entirely.
Open for discussion. If this is approved, let me know, so I can submit a PR. Thanks!
Beta Was this translation helpful? Give feedback.
All reactions