Make invoke_tool self-correcting on argument mismatch#29
Merged
Conversation
When a consumer invokes a downstream tool off list_services alone (which returns only tool name + description, not inputSchema), it can guess wrong parameter names from the description prose. Downstream SDKs sanitize the binding error to a generic message, so the model had no way to recover without a separate get_service_details call. ToolProxyHandler now checks the supplied arguments against the downstream tool's cached input schema when a call returns an error, and appends a corrective hint (naming the missing/unknown keys and the full schema) only when there is an actual mismatch. Schema-valid calls that fail for genuine tool-side reasons are left untouched, and schema lookup is guarded so it can never break the proxy. Bump version to 0.3.1. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Problem
Claude Desktop (via this aggregator) repeatedly failed calling the downstream
csla-mcpsearch/fetchtools withmissing required parameter 'message'/'fileName'. The downstream server, its API key, and its embedding model were all healthy — a directtools/callwith the correct keys works.Root cause:
list_servicesreturns only each tool's name + description, not itsinputSchema(ServiceIndex.ToolSummary). When a consumer invokes offlist_servicesalone, it guesses parameter names from the description prose (e.g.csla-mcp'smessageparameter is described with the word "query," steering the guess toquery/name). The downstream SDK then sanitizes the binding error to a generic"An error occurred invoking '<tool>'", so the model has no way to recover without separately callingget_service_details.Fix
ToolProxyHandler.InvokeAsyncis now self-correcting. When a downstream call returns an error, it compares the supplied arguments against the tool's cached input schema and — only when there's a real mismatch (missing required or unknown keys) — appends a corrective block to the error result naming the specific bad keys and the full schema. The model can then retry correctly without a separateget_service_detailsround-trip.ToolIndexcache and is fully guarded, so it can never break the proxy.Example of the enriched error a caller now receives:
Verification
dotnet buildclean (0 warnings/errors); SDK types matched.JsonFilePersistenceparallel-IO test, which passes in isolation and is unrelated to this change.Version bumped
0.3.0→0.3.1.Follow-up (not in this PR)
Optionally add compact param hints (required parameter names) to
list_servicesitself, so the wrong guess is prevented at the source as well.🤖 Generated with Claude Code