unless $local[0] =~ /\A([-_\w]+?)[+].+\z/;
return $1.'@'.$local[1];
}
sub TO_JSON {
# Instance method for JSON::encode()
# @return [String] The value of "address" accessor
my $self
package MCP::Server;
use Mojo::Base -base, -signatures;
use List::Util qw(first);
use Mojo::JSON qw(false true);
use MCP::Constants qw(INVALID_PARAMS INVALID_REQUEST METHOD_NOT_FOUND PARSE_ER
equest, $context) {
return _jsonrpc_error(PARSE_ERROR, 'Invalid JSON-RPC request') unless ref $request eq 'HASH';
return _jsonrpc_error(INVALID_REQUEST, 'Missing JSON-RPC method') unless my $metho
dle_initialize($request->{params} // {});
return _jsonrpc_response($result, $id);
}
elsif ($method eq 'ping') {
return _jsonrpc_response({}, $id);
}
elsif ($method eq 'prom
[String] type Data format: json, yaml
# @return [String, Undef] Dumped data or Undef if the value of first
# argument is neither "json" nor "yaml"
my $self =
shift;
my $type = shift || 'json';
return undef unless $type =~ /\A(?:json|yaml)\z/;
my $referclass = 'Sisimai::Data::'.uc($type);
my $modulepath = 'Sisimai/Data/'.uc($type).'.pm';
isimai::Address> object generated from the sender address.
When Sisimai::Data object is dumped as JSON, this value converted to an email
address. Sisimai::Address object have the following accessors:
etect an error from Amazon SES
# @param [Hash] mhead Message headers of a bounce email (JSON)
# @param [String] mbody Message body of a bounce email
# @return [Hash] B
//g;
my $p2 = index($sespayload, '"Message"');
if( $p2 > 0 ) {
# The JSON included in the email is a format like the following:
# {
# "Type" : "No
# Load as JSON string and decode
require JSON;
my $jsonobject = undef; eval { $jsonobject = JSON->new->decode($sespayload) };
if( $@ ) {
# Something wrong in decoding JSON
::Transport::Stdio;
use Mojo::Base 'MCP::Server::Transport', -signatures;
use Mojo::JSON qw(decode_json encode_json);
use Mojo::Log;
use Scalar::Util qw(blessed);
sub handle_requests ($self) {
my
TDOUT->autoflush(1);
while (my $input = <>) {
chomp $input;
my $request = eval { decode_json($input) };
next unless my $response = $server->handle($request, {});
if (blessed($respon
}
else { _print_response($response) }
}
}
sub _print_response ($response) { print encode_json($response) . "\n" }
1;
=encoding utf8
=head1 NAME
MCP::Server::Transport::Stdio - Stdio trans
arams{'json_db'} ) {
my $data = do {
local $/;
open my($fh), '<:raw', $params{'json_db'}
or die "could not read file <$params{json_db}>\n";
<$fh>;
};
state $rc = require JSON;
my
$decoded = eval { JSON::decode_json($data) };
die "could not decode JSON from <$params{json_db}>: @_\n" unless defined $decoded;
return $decoded;
}
my $rc = eval { require CPANSA::DB };
if (
he message marks the end of a set of messages, but not the end
of the stream. For example, a huge JSON string sent as multiple chunks can use
this tag to indicate to the application that the string is
jolicious> application. The tool name and
description are used for discovery, and the L<JSON schema|https://json-schema.org> is used to validate the input.
use Mojolicious::Lite -signatures;
use
type requests on the command line.
$ perl examples/echo_stdio.pl
{"jsonrpc":"2.0","id":"1","method":"tools/list"}
{"jsonrpc":"2.0","id":"2","method":"tools/call","params":{"name":"echo","argum
atures;
use Carp qw(croak);
use MCP::Constants qw(PROTOCOL_VERSION);
use Mojo::JSON qw(from_json);
use Mojo::UserAgent;
use Scalar::Util qw(weaken);
has name => 'PerlClient';
has 'sess
+ 1 : 1;
return $request;
}
sub build_notification ($self, $method, $params = {}) {
return {jsonrpc => '2.0', method => $method, params => $params};
}
sub call_tool ($self, $name, $args = {}) {
d_request ($self, $request) {
my $headers = {Accept => 'application/json, text/event-stream', 'Content-Type' => 'application/json'};
if (my $session_id = $self->session_id) { $headers->{'Mcp-Sessi
package MCP::Tool;
use Mojo::Base -base, -signatures;
use JSON::Validator;
use Mojo::JSON qw(false to_json true);
use Mojo::Util qw(b64_encode);
use Scalar::Util qw(blessed);
has code =>
};
}
sub structured_result ($self, $data, $is_error = 0) {
my $result = $self->text_result(to_json($data), $is_error);
$result->{structuredContent} = $data;
return $result;
}
sub text_result
e_input ($self, $args) {
unless ($self->{validator}) {
my $validator = $self->{validator} = JSON::Validator->new;
$validator->schema($self->input_schema);
}
my @errors = $self->{validat
:Base 'MCP::Server::Transport', -signatures;
use Crypt::Misc qw(random_v4uuid);
use Mojo::JSON qw(to_json true);
use Mojo::Util qw(dumper);
use Scalar::Util qw(blessed);
use constant DEBUG => $
hod = $c->req->method;
return $self->_handle_post($c) if $method eq 'POST';
return $c->render(json => {error => 'Method not allowed'}, status => 405);
}
sub _extract_session_id ($self, $c) { retu
;
$c->render(json => $result, status => 200);
}
sub _handle_post ($self, $c) {
my $session_id = $self->_extract_session_id($c);
return $c->render(json => {error => 'Invalid JSON'}, status => 4
sponses
=head4 Status Code: C<200>
OK
=head4 Content Types:
=over 4
=item * C<application/json>
Example (See the L<OpenAI spec for more detail|https://github.com/openai/openai-openapi/blob/ma
sponses
=head4 Status Code: C<200>
OK
=head4 Content Types:
=over 4
=item * C<application/json>
Example (See the L<OpenAI spec for more detail|https://github.com/openai/openai-openapi/blob/ma
be modified.
Type: C<string>
=back
=head3 Request Body
=head3 Content Type: C<application/json>
Example:
{
"tool_resources" : {
"code_interpre
s+/, $attribs{FILES} ;
}
push(@files, qw[$(MAKE_APERL_FILE)
MYMETA.json MYMETA.yml perlmain.c tmon.out mon.out so_locations
blibdirs.ts pm_to_blib pm
et;
Generate the metafile target.
Writes the file META.yml (YAML encoded meta-data) and META.json
(JSON encoded meta-data) about the module in the distdir.
The format follows Module::Build's as clos
e_metajson = $self->stashmeta(
$meta->as_string({version => "2.0"}), 'META_new.json'
);
my $metayml = join("\n\t", @write_metayml);
my $metajson = join("\n\t", @write_metajson);
pe => 'int',
},
json => {
constant => '',
name => 'SQL_UNKNOWN_TYPE',
re => qr/^(json)\b/,
type => 'json',
},
linestring
Object;
my $dbh = DB::Object->connect({
driver => 'mysql',
conf_file => 'db-settings.json',
database => 'webstore',
host => 'localhost',
login => 'store-admin',
debug => 3
> 'strict' ) &&
( $fo->type eq 'jsonb' || $fo->type eq 'json' ) )
{
my $this_json = $self->_encode_json( $value );
$const = $fo->datatype
stant;
$elem->format( sprintf( "$field=%s", $tbl_o->database_object->quote( $this_json, $const ) ) );
}
elsif( $tbl_o->database_object->placeholder->has( $self-
{
foreach my $json_key ( keys( %$value ) )
{
my $json_value = $value->{ $json_key };
# Assu
my $dbh = DB::Object->connect({
driver => 'SQLite',
conf_file => 'db-settings.json',
database => 'webstore',
host => 'localhost',
login => 'store-admin',
a( $elem->fo => 'DB::Object::Fields::Field' ) &&
( $elem->fo->type eq 'jsonb' || $elem->fo->type eq 'json' ) &&
$self->_is_hash( $binded[$i] => 'strict' ) )
{
een}", $binded[$i], "{/} into a JSON string." );
# try-catch
local $@;
my $json = eval
{
$self->new_json->encode( $binded[$i] );
ed( 'DB::Object' ) );
}
else
{
$binded[$i] = $json;
}
}
# If the value provided is a DateTime object without a formatter
mmon;
use Scalar::Util qw( blessed );
use DB::Object::Cache::Tables;
use DBI;
use JSON;
use Module::Generic::File qw( sys_tmpdir );
use Module::Generic::Global qw( :const );
$self->{cache_table} = 0;
$self->{driver} = '';
# Auto-decode json data into perl hash
$self->{auto_decode_json} = 1;
$self->{auto_convert_datetime_to_object} = 0;
$self->{allo
t_scalar( 'auto_convert_datetime_to_object', @_ ) ); }
sub auto_decode_json { return( shift->_set_get_scalar( 'auto_decode_json', @_ ) ); }
sub attribute($;$@)
{
my $self = shift( @_ );
# $h
an hash of constant value and constant name:
# field => { constant => 12, name => PG_JSONB, type => 'jsonb' };
$self->{types_const} = {};
# The table type. It could be table or view
n => { constant => 17, name => 'PG_JSONB', type => 'jsonb' }
This is used to help manage binded value with the right type, or helps when converting an hash into json.
If nothing is found, it returns
},
json => {
constant => '',
is_array => 0,
name => 'PG_JSON',
re => qr/^json\b/,
type => 'json',
},
jsonb => {
me => 'PG_JSONB',
re => qr/^jsonb\b/,
type => 'jsonb',
},
# <https://www.postgresql.org/docs/current/datatype-json.html#DATATYPE-JSONPATH>
jsonpath => {
nstant => '',
is_array => 0,
name => 'PG_JSONPATH',
re => qr/^jsonpath\b/,
type => 'jsonpath',
},
line => {
constant => '',