Skip to content

Seems Miss function #24

@ClicShopping

Description

@ClicShopping

seems to miss a function inside Protocol.
Let me know if it s correct or not.

public function send(string $request): ?string
    {
        $clientId = 'local'; // Use a dummy client ID for local calls
        $responseToSend = null;
        $parsedMessage = null;
        $messageData = null;

        try {
            $messageData = json_decode($request, true, 512, JSON_THROW_ON_ERROR);
            if (!is_array($messageData)) {
                throw new ProtocolException('Invalid JSON received (not an object/array).');
            }
            $parsedMessage = $this->parseMessageData($messageData);
            if ($parsedMessage === null) {
                throw McpServerException::invalidRequest('Invalid MCP/JSON-RPC message structure.');
            }
            $responseToSend = $this->processor->process($parsedMessage, $clientId);
        } catch (JsonException $e) {
            $responseToSend = Response::error(McpServerException::parseError($e->getMessage())->toJsonRpcError(), null);
        } catch (McpServerException $e) {
            $id = $this->getRequestId($parsedMessage, $messageData);
            $responseToSend = Response::error($e->toJsonRpcError(), $id);
        } catch (Throwable $e) {
            $id = $this->getRequestId($parsedMessage, $messageData);
            $responseToSend = Response::error(McpServerException::internalError()->toJsonRpcError(), $id);
        }

        if ($responseToSend instanceof Response) {
            return $responseToSend->toJson();
        }
        return null;
    }

and Response.php


  public static function fromSuccess(mixed $result, ?string $id = null): self
  {
    $response = new self();
    $response->jsonrpc = '2.0';
    $response->result = $result;
    $response->id = $id;
    return $response;
  }


  public function toJson(): string {
    return json_encode($this);
  }


    public function jsonSerialize(): array {
      return [
      'jsonrpc' => '2.0',
      'result'  => $this->result,
      'id'      => $this->id,
      ];
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions