Skip to content

fix(server): return INVALID_PARAMS for unknown prompt in prompts/get - #955

Open
latent-9 wants to merge 1 commit into
modelcontextprotocol:mainfrom
latent-9:fix/get-prompt-not-found-error-code
Open

fix(server): return INVALID_PARAMS for unknown prompt in prompts/get#955
latent-9 wants to merge 1 commit into
modelcontextprotocol:mainfrom
latent-9:fix/get-prompt-not-found-error-code

Conversation

@latent-9

Copy link
Copy Markdown

Problem

prompts/get for a name that is not registered responds with JSON-RPC -32603 (INTERNAL_ERROR).

handleGetPrompt in Server.kt throws a bare IllegalArgumentException when the prompt is missing. Protocol.respondWithError maps any non-McpException cause to INTERNAL_ERROR, so the client receives -32603 for what is a client-side bad parameter.

The sibling handler handleReadResource in the same file already throws a typed McpException(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, -32603 means the server hit an internal fault. Requesting a prompt name that does not exist is a client error (an invalid name parameter), 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) from handleGetPrompt, consistent with handleReadResource. The message is unchanged.

AbstractPromptIntegrationTest.testNonExistentPrompt asserted -32603; it now asserts INVALID_PARAMS.

If you would prefer a dedicated error code for this case instead of INVALID_PARAMS, I am glad to adjust.

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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant