Skip to content
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
1 change: 1 addition & 0 deletions src/mcp-sdk/src/Message/Error.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public const INVALID_PARAMS = -32602;
public const INTERNAL_ERROR = -32603;
public const PARSE_ERROR = -32700;
public const RESOURCE_NOT_FOUND = -32002;

public function __construct(
public string|int $id,
Expand Down
2 changes: 1 addition & 1 deletion src/mcp-sdk/src/Message/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

namespace Symfony\AI\McpSdk\Message;

final class Request implements \JsonSerializable, \Stringable
final readonly class Request implements \JsonSerializable, \Stringable
{
/**
* @param array<string, mixed>|null $params
Expand Down
8 changes: 6 additions & 2 deletions src/mcp-sdk/src/Server/JsonRpcHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,15 @@ public function process(string $input): iterable
} catch (NotFoundExceptionInterface $e) {
$this->logger->warning(\sprintf('Failed to create response: %s', $e->getMessage()), ['exception' => $e]);

yield $this->encodeResponse(Error::methodNotFound($message->id ?? 0, $e->getMessage()));
yield $this->encodeResponse(Error::methodNotFound($message->id, $e->getMessage()));
} catch (\InvalidArgumentException $e) {
$this->logger->warning(\sprintf('Invalid argument: %s', $e->getMessage()), ['exception' => $e]);

yield $this->encodeResponse(Error::invalidParams($message->id ?? 0, $e->getMessage()));
yield $this->encodeResponse(Error::invalidParams($message->id, $e->getMessage()));
} catch (\Throwable $e) {
$this->logger->critical(\sprintf('Uncaught exception: %s', $e->getMessage()), ['exception' => $e]);

yield $this->encodeResponse(Error::internalError($message->id, $e->getMessage()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\AI\McpSdk\Capability\Resource\ResourceRead;
use Symfony\AI\McpSdk\Capability\Resource\ResourceReaderInterface;
use Symfony\AI\McpSdk\Exception\ExceptionInterface;
use Symfony\AI\McpSdk\Exception\ResourceNotFoundException;
use Symfony\AI\McpSdk\Message\Error;
use Symfony\AI\McpSdk\Message\Request;
use Symfony\AI\McpSdk\Message\Response;
Expand All @@ -31,6 +32,8 @@ public function createResponse(Request $message): Response|Error

try {
$result = $this->reader->read(new ResourceRead(uniqid('', true), $uri));
} catch (ResourceNotFoundException $e) {
return new Error($message->id, Error::RESOURCE_NOT_FOUND, $e->getMessage());
} catch (ExceptionInterface) {
return Error::internalError($message->id, 'Error while reading resource');
}
Expand Down