Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,12 @@
"phpstan/phpstan": "^2.1",
"phpunit/phpunit": "^11.5",
"symfony/console": "^6.4 || ^7.0",
"rector/rector": "^2.0"
"rector/rector": "^2.0",
"psr/cache": "^3.0"
},
"suggest": {
"symfony/console": "To use SymfonyConsoleTransport for STDIO"
"symfony/console": "To use SymfonyConsoleTransport for STDIO",
"psr/cache": "To use CachePoolStore with SSE Transport"
},
"autoload": {
"psr-4": {
Expand Down
3 changes: 3 additions & 0 deletions src/Capability/Tool/MetadataInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,8 @@ public function getName(): string;

public function getDescription(): string;

/**
* @return array<string, mixed>
*/
public function getInputSchema(): array;
}
4 changes: 1 addition & 3 deletions src/Exception/ExceptionInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace PhpLlm\McpSdk\Exception;

use PhpLlm\LlmChain\Exception\ExceptionInterface as BaseExceptionInterface;

interface ExceptionInterface extends BaseExceptionInterface
interface ExceptionInterface
{
}
15 changes: 6 additions & 9 deletions src/Exception/ToolExecutionException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,14 @@

namespace PhpLlm\McpSdk\Exception;

use PhpLlm\LlmChain\Model\Response\ToolCall;
use PhpLlm\McpSdk\Capability\Tool\ToolCall;

final class ToolExecutionException extends \RuntimeException implements ExceptionInterface
{
public ?ToolCall $toolCall = null;

public static function executionFailed(ToolCall $toolCall, \Throwable $previous): self
{
$exception = new self(sprintf('Execution of tool "%s" failed with error: %s', $toolCall->name, $previous->getMessage()), previous: $previous);
$exception->toolCall = $toolCall;

return $exception;
public function __construct(
public readonly ToolCall $toolCall,
?\Throwable $previous = null,
) {
parent::__construct(sprintf('Execution of tool "%s" failed with error: %s', $toolCall->name, $previous->getMessage()), previous: $previous);
}
}
20 changes: 5 additions & 15 deletions src/Exception/ToolNotFoundException.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,13 @@

namespace PhpLlm\McpSdk\Exception;

use PhpLlm\LlmChain\Chain\Toolbox\ExecutionReference;
use PhpLlm\LlmChain\Model\Response\ToolCall;
use PhpLlm\McpSdk\Capability\Tool\ToolCall;

final class ToolNotFoundException extends \RuntimeException implements ExceptionInterface
{
public ?ToolCall $toolCall = null;

public static function notFoundForToolCall(ToolCall $toolCall): self
{
$exception = new self(sprintf('Tool not found for call: %s.', $toolCall->name));
$exception->toolCall = $toolCall;

return $exception;
}

public static function notFoundForReference(ExecutionReference $reference): self
{
return new self(sprintf('Tool not found for reference: %s::%s.', $reference->class, $reference->method));
public function __construct(
public readonly ToolCall $toolCall,
) {
parent::__construct(sprintf('Tool not found for call: %s.', $toolCall->name));
}
}
4 changes: 2 additions & 2 deletions src/Server/RequestHandler/ToolCallHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
final class ToolCallHandler extends BaseRequestHandler
{
public function __construct(
private readonly ToolExecutorInterface $toolbox,
private readonly ToolExecutorInterface $toolExecutor,
) {
}

Expand All @@ -24,7 +24,7 @@ public function createResponse(Request $message): Response|Error
$arguments = $message->params['arguments'] ?? [];

try {
$result = $this->toolbox->execute(new ToolCall(uniqid('', true), $name, $arguments));
$result = $this->toolExecutor->execute(new ToolCall(uniqid('', true), $name, $arguments));
} catch (ExceptionInterface) {
return Error::internalError($message->id, 'Error while executing tool');
}
Expand Down
4 changes: 2 additions & 2 deletions src/Server/RequestHandler/ToolListHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
final class ToolListHandler extends BaseRequestHandler
{
public function __construct(
private readonly ToolCollectionInterface $toolbox,
private readonly ToolCollectionInterface $toolCollection,
) {
}

Expand All @@ -30,7 +30,7 @@ public function createResponse(Request $message): Response
'$schema' => 'http://json-schema.org/draft-07/schema#',
] : $inputSchema,
];
}, $this->toolbox->getMetadata()),
}, $this->toolCollection->getMetadata()),
]);
}

Expand Down