From c7df85cb09dc55a24726c17f8ffc4ef71bcb0533 Mon Sep 17 00:00:00 2001 From: latent-9 <296084221+latent-9@users.noreply.github.com> Date: Sun, 16 Aug 2026 03:02:39 +1200 Subject: [PATCH] [Server] Return invalid-params for unknown tool in tools/call An unknown tool name is an invalid parameter of the tools/call request, not a missing JSON-RPC method: the tools/call method exists, only its `name` argument does not resolve. Return -32602 (Invalid params) to match the argument-validation path in the same handler, which already reports invalid input for tools/call as -32602. --- src/Server/Handler/Request/CallToolHandler.php | 2 +- tests/Unit/Server/Handler/Request/CallToolHandlerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Server/Handler/Request/CallToolHandler.php b/src/Server/Handler/Request/CallToolHandler.php index 254e8388..0b632d41 100644 --- a/src/Server/Handler/Request/CallToolHandler.php +++ b/src/Server/Handler/Request/CallToolHandler.php @@ -68,7 +68,7 @@ public function handle(Request $request, SessionInterface $session): Response|Er } catch (ToolNotFoundException $e) { $this->logger->error('Tool not found', ['name' => $toolName, 'exception' => $e]); - return new Error($request->getId(), Error::METHOD_NOT_FOUND, $e->getMessage()); + return Error::forInvalidParams($e->getMessage(), $request->getId()); } $inputSchema = $reference->tool->inputSchema; diff --git a/tests/Unit/Server/Handler/Request/CallToolHandlerTest.php b/tests/Unit/Server/Handler/Request/CallToolHandlerTest.php index 87a696be..47351dc0 100644 --- a/tests/Unit/Server/Handler/Request/CallToolHandlerTest.php +++ b/tests/Unit/Server/Handler/Request/CallToolHandlerTest.php @@ -183,7 +183,7 @@ public function testHandleToolNotFoundExceptionReturnsError(): void $this->assertInstanceOf(Error::class, $response); $this->assertEquals($request->getId(), $response->id); - $this->assertEquals(Error::METHOD_NOT_FOUND, $response->code); + $this->assertEquals(Error::INVALID_PARAMS, $response->code); } public function testHandleToolCallExceptionReturnsResponseWithErrorResult(): void