Skip to content

Commit c7df85c

Browse files
committed
[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.
1 parent 43815e3 commit c7df85c

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

src/Server/Handler/Request/CallToolHandler.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public function handle(Request $request, SessionInterface $session): Response|Er
6868
} catch (ToolNotFoundException $e) {
6969
$this->logger->error('Tool not found', ['name' => $toolName, 'exception' => $e]);
7070

71-
return new Error($request->getId(), Error::METHOD_NOT_FOUND, $e->getMessage());
71+
return Error::forInvalidParams($e->getMessage(), $request->getId());
7272
}
7373

7474
$inputSchema = $reference->tool->inputSchema;

tests/Unit/Server/Handler/Request/CallToolHandlerTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function testHandleToolNotFoundExceptionReturnsError(): void
183183

184184
$this->assertInstanceOf(Error::class, $response);
185185
$this->assertEquals($request->getId(), $response->id);
186-
$this->assertEquals(Error::METHOD_NOT_FOUND, $response->code);
186+
$this->assertEquals(Error::INVALID_PARAMS, $response->code);
187187
}
188188

189189
public function testHandleToolCallExceptionReturnsResponseWithErrorResult(): void

0 commit comments

Comments
 (0)