[Server] Log failures in CompletionCompleteHandler (#471)
This commit is contained in:
parent
b1c7272761
commit
c882401ee7
2 changed files with 47 additions and 1 deletions
|
|
@ -1079,7 +1079,7 @@ final class Builder
|
|||
|
||||
$requestHandlers = array_merge($this->requestHandlers, [
|
||||
new Handler\Request\CallToolHandler($registry, $referenceHandler, $logger),
|
||||
new Handler\Request\CompletionCompleteHandler($registry, $container),
|
||||
new Handler\Request\CompletionCompleteHandler($registry, $container, $logger),
|
||||
new Handler\Request\GetPromptHandler($registry, $referenceHandler, $logger),
|
||||
new Handler\Request\InitializeHandler($configuration),
|
||||
new Handler\Request\ListPromptsHandler($registry, $this->paginationLimit),
|
||||
|
|
|
|||
|
|
@ -25,6 +25,8 @@ use Mcp\Schema\ResourceReference;
|
|||
use Mcp\Schema\Result\CompletionCompleteResult;
|
||||
use Mcp\Server\Session\SessionInterface;
|
||||
use Psr\Container\ContainerInterface;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Psr\Log\NullLogger;
|
||||
|
||||
/**
|
||||
* Handles completion/complete requests.
|
||||
|
|
@ -38,6 +40,7 @@ final class CompletionCompleteHandler implements RequestHandlerInterface
|
|||
public function __construct(
|
||||
private readonly RegistryInterface $registry,
|
||||
private readonly ?ContainerInterface $container = null,
|
||||
private readonly LoggerInterface $logger = new NullLogger(),
|
||||
) {
|
||||
}
|
||||
|
||||
|
|
@ -87,8 +90,12 @@ final class CompletionCompleteHandler implements RequestHandlerInterface
|
|||
} catch (PromptNotFoundException|ResourceNotFoundException $e) {
|
||||
// The reference names something the server does not have, which is
|
||||
// a bad parameter rather than a missing resource.
|
||||
$this->logger->warning(\sprintf('Completion requested for unknown reference: %s', $e->getMessage()), ['exception' => $e]);
|
||||
|
||||
return Error::forInvalidParams($e->getMessage(), $request->getId());
|
||||
} catch (\Throwable $e) {
|
||||
$this->logger->error(\sprintf('Error while handling completion request: %s', $e->getMessage()), ['exception' => $e]);
|
||||
|
||||
return Error::forInternalError('Error while handling completion request', $request->getId());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue