feat(mcp): filter tools in system prompt to force tool calls only for those listed in alwaysAllow list #2175
+1
−1
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Solution implemented for Feature Request 2171
Commit
Summary
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/devin MCP despite
alwaysAllow
listing the valid tool names: "read_wiki_structure", "read_wiki_contents", "ask_question" already.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.Context
The AI model was attempting to use non-existent MCP tools like "search" and "query" because it could infer logical-sounding tool names that don't actually exist on connected MCP servers. This led to wasted time and tokens when these invalid tool calls were made.
Implementation
Modified the
getMcpServersSection
function mcp-servers.ts:19-29 to filter tools before presenting them to the AI model in the system prompt. The solution:alwaysAllow
tools - assumes tools in the user-configuredalwaysAllow
list existfetchToolsList()
for tools not inalwaysAllow
This prevents the AI from ever knowing about non-existent tools, eliminating the hallucination problem at its source rather than trying to catch invalid calls during execution.
Benefits
alwaysAllow
configuration from MCP settings McpHub.ts:873-875How to Test
alwaysAllow
are still presented and functionalWiki pages you might want to explore: