fix(server): return INVALID_PARAMS for unknown prompt in prompts/get - #955
Open
latent-9 wants to merge 1 commit into
Open
fix(server): return INVALID_PARAMS for unknown prompt in prompts/get#955latent-9 wants to merge 1 commit into
latent-9 wants to merge 1 commit into
Conversation
handleGetPrompt threw a bare IllegalArgumentException when the requested prompt was not registered. Protocol.respondWithError maps any non-McpException cause to INTERNAL_ERROR (-32603), so a client requesting an unknown prompt received a server-fault code for what is a client-side bad parameter. The sibling handler handleReadResource already throws a typed McpException (RESOURCE_NOT_FOUND) for the equivalent not-found case. Align prompts/get by throwing McpException(INVALID_PARAMS), and update the integration test that asserted -32603.
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
prompts/getfor a name that is not registered responds with JSON-RPC-32603(INTERNAL_ERROR).handleGetPromptinServer.ktthrows a bareIllegalArgumentExceptionwhen the prompt is missing.Protocol.respondWithErrormaps any non-McpExceptioncause toINTERNAL_ERROR, so the client receives-32603for what is a client-side bad parameter.The sibling handler
handleReadResourcein the same file already throws a typedMcpException(RESOURCE_NOT_FOUND)for the equivalent not-found case, which reaches the client as-32002. The two not-found paths are inconsistent.In JSON-RPC,
-32603means the server hit an internal fault. Requesting a prompt name that does not exist is a client error (an invalidnameparameter), so a client cannot tell "the prompt does not exist" apart from "the server failed" and may retry a request that can never succeed.Change
Throw a typed
McpException(INVALID_PARAMS)fromhandleGetPrompt, consistent withhandleReadResource. The message is unchanged.AbstractPromptIntegrationTest.testNonExistentPromptasserted-32603; it now assertsINVALID_PARAMS.If you would prefer a dedicated error code for this case instead of
INVALID_PARAMS, I am glad to adjust.