use strict;
use warnings;
use JSON::PP;

$| = 1;
my $json = JSON::PP->new;
while (my $line = <STDIN>) {
    my $request = decode_json($line);
    my ($id, $method) = @$request{qw(id method)};
    my $result =
        $method eq 'initialize' ? {
            api_version => '0.1',
            commands    => [],
            tools       => [{
                name        => 'hello',
                description => 'Say hello to someone',
                parameters  => {
                    type                 => 'object',
                    properties           => { name => { type => 'string' } },
                    required             => ['name'],
                    additionalProperties => JSON::PP::false,
                },
            }],
        }
      : $method eq 'tool/call' ? {
            content  => "Hello, $request->{params}{arguments}{name}!",
            is_error => JSON::PP::false,
        }
      : {};
    print $json->encode({ jsonrpc => '2.0', id => $id, result => $result }), "\n" if defined $id;
    last if $method eq 'shutdown';
}
