fix: fail tools-list when tools array is empty#177
Draft
lux999 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Draft
fix: fail tools-list when tools array is empty#177lux999 wants to merge 1 commit intomodelcontextprotocol:mainfrom
lux999 wants to merge 1 commit intomodelcontextprotocol:mainfrom
Conversation
An empty array ([]) is truthy in TypeScript, so the tools-list check incorrectly passed even when no tools were returned. Also refactor the nested if/else into a flat if/else-if chain for readability. Co-Authored-By: Claude Sonnet 4.6 <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.
An empty array ([]) is truthy in TypeScript, so the
tools-listcheck incorrectly passed even when no tools were returned. Also refactor the nested if/else into a flat if/else-if chain for readability.Please see Additional Context for the decision.
Motivation and Context
The tools-list scenario incorrectly reported success when a server returned an empty tools array ([]). An empty array is truthy in TypeScript, so !result.tools did not catch it, and forEach on [] was a no-op — resulting in zero errors and a passing test. This masked real failures where a server's initialize handshake failed and it returned no tools.
How Has This Been Tested?
Verified locally with vitest — all 84 tests pass. Confirmed manually that a server returning [] for tools/list now produces a failure, while a server returning valid tools still passes.
Breaking Changes
Servers with legitimately zero tools will now fail the tools-list scenario. These servers should add tools-list to their expected-failures baseline.
Types of changes
Checklist
Additional context
We understand there are two distinct cases where a server returns [] for tools/list:
Three approaches to distinguish these cases were considered:
--min-tools 1passed to the conformance runner) — explicit but adds complexity to the CLI and every baseline file that needs to opt in.We went with option 3 as the right balance of correctness and simplicity. Raising as a draft for team discussion on the edge-case policy before merging.