ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/cvsroot/AnyEvent-MCP/lib/AnyEvent/MCP.pm
Revision: 1.16
Committed: Sun Oct 11 01:46:31 2026 UTC (5 weeks, 2 days ago) by root
Branch: MAIN
Changes since 1.15: +6 -374 lines
Log Message:
*** empty log message ***

File Contents

# User Rev Content
1 root 1.1 =head1 NAME
2    
3     AnyEvent::MCP - Model Context Protocol client/server support
4    
5     =head1 SYNOPSIS
6    
7 root 1.15 use AnyEvent::MCP::Server::Simple;
8 root 1.1
9     mcp_tool ...
10 root 1.3 mcp_start;
11 root 1.1
12     or use the object interface directly:
13    
14 root 1.6 use AnyEvent::MCP::Server ();
15 root 1.1
16     my $server = AnyEvent::MCP::Server->new (...);
17    
18     =head1 DESCRIPTION
19    
20     AnyEvent::MCP provides event-driven Model Context Protocol client and server
21     support.
22    
23     The usual way to implement a small MCP server is
24     L<AnyEvent::MCP::Server::Simple>, which provides a function-based interface and
25     creates the underlying server objects when a transport such as stdio or HTTP is
26     started.
27    
28     The lower-level object interfaces are intended for applications that need to
29     manage MCP connections, servers or reusable tool registries directly.
30    
31     =head2 MODULES
32    
33 root 1.7 =over
34 root 1.1
35     =item L<AnyEvent::MCP::Server::Simple>
36    
37     Function-based interface for implementing ordinary MCP servers.
38    
39     =item L<AnyEvent::MCP::Server>
40    
41     Object-oriented MCP server interface.
42    
43     =item L<AnyEvent::MCP::Client>
44    
45     Object-oriented MCP client interface.
46    
47     =item L<AnyEvent::MCP::Server::Toolset>
48    
49     Reusable registry of MCP tool declarations.
50    
51     =item L<AnyEvent::MCP::Server::Permissions>
52    
53     Permission and capability handling for MCP servers.
54    
55     =back
56    
57 root 1.4 C<mcp-multibroker> combines downstream HTTP and stdio servers under tool-name
58     prefixes. It uses the same client, server and permission helper facilities,
59     including modern input forwarding and local permission prompts for legacy
60     callers. Run C<mcp-multibroker --help> for command-line syntax; its manual
61     describes authentication and configuration.
62    
63 root 1.16 The interfaces are still being designed. L<AnyEvent::MCP::Intro> explains
64     the installed programs; module-specific POD describes their Perl APIs.
65 root 1.9
66 root 1.16 =head1 TUTORIAL
67 root 1.9
68 root 1.16 For installing and running the bundled servers, authenticating clients,
69     and writing permission rules, see L<AnyEvent::MCP::Intro>.
70 root 1.9
71 root 1.1
72 root 1.2 =head1 GLOBAL CONFIGURATION
73    
74     The shared per-user configuration is C<$XDG_CONFIG_HOME/anyevent-mcp/global.ini>,
75     or C<$HOME/.config/anyevent-mcp/global.ini> when XDG_CONFIG_HOME is unset.
76     L<AnyEvent::MCP::Config> loads and holds it; loading this module does not access
77     configuration files.
78    
79     The file is UTF-8 and uses sections with single-line C<key = value> pairs.
80     Values are unquoted strings. Blank lines and whole-line comments beginning
81     with C<#> or C<;> are ignored; inline comment characters remain part of the
82     value. Later occurrences of a key replace earlier ones in the same section.
83    
84     [global]
85     secret = ...128 hexadecimal digits...
86    
87     [server example]
88 root 1.11 bind = 127.0.0.1:31740
89 root 1.13 tokens = first-token,second-token
90 root 1.2
91     [mcp-fs]
92     utility = /path/to/utility
93    
94     Section names are unrestricted. Application-specific sections, including
95     exports, utility paths and user settings, are documented by their applications.
96    
97     C<[global]> holds C<secret>, a 64-byte master key encoded as 128 hexadecimal
98     digits. The file must be owned by the current user, with no group or other
99     permissions. A missing secret is generated automatically on first configuration
100     access and saved when possible. Existing secrets are never replaced implicitly.
101     An invalid secret is an error.
102    
103     If saving fails, Config warns and retains the secret in memory. Credentials
104     then remain stable only for that process; other processes cannot derive the
105     same credentials. If randomness is unavailable, supply a securely generated
106     secret in the file.
107    
108 root 1.13 C<[server NAME]> holds named-server settings.
109 root 1.11 HTTP-capable executables use C<--name NAME> to select these settings, with
110     the executable basename as the default name. Names consist of an ASCII
111     letter or underscore followed by ASCII letters, digits, underscores or
112     hyphens. Their C<--bind ADDRESS[:PORT]> overrides the configured C<bind>.
113     The default bind address is IPv4 loopback with a port derived from the name
114     and master secret in the range 16384..32767; C<:0> requests an ephemeral
115 root 1.12 port. C<--print-url> prints the URL using the first accepted token without
116     listening. Named server settings also include C<path>, C<url_host>,
117     C<url_scheme> and C<tokens>. C<tokens> is a comma-separated list of
118     URL-safe strings. Repeated C<--token TOKEN> options override this list.
119     All accepted tokens work in the URL path or Authorization bearer header.
120     Without configured tokens, one server-specific token is derived.
121 root 1.11
122 root 1.12 C<mcp_start> resolves named settings and requires the selected token for
123     HTTP requests. Explicit tokens replace the derived default.
124 root 1.11 The low-level HTTP transport does not resolve configuration itself.
125     Stdio startup does not access global HTTP configuration. Browser origins
126     are permitted by default, but must still pass MCP authentication.
127 root 1.3
128 root 1.12 C<[client NAME]> supplies HTTP client defaults: C<url>, C<bearer> and
129     C<timeout>. Clients consult it only when explicitly given a C<name>.
130     An unnamed client or HTTP server does not read global configuration.
131 root 1.3 Explicit constructor arguments take precedence over named defaults.
132    
133     =head1 ENVIRONMENT
134    
135     Project-specific environment variables use the C<PERL_ANYEVENT_MCP_> prefix.
136     C<PERL_ANYEVENT_MCP_MULTIBROKER_PROTOCOL=stdio> selects stdio in Simple.
137 root 1.11 C<PERL_ANYEVENT_MCP_MULTIBROKER_ALIAS> names a multibroker routing prefix;
138     it does not change the service-instance name.
139 root 1.3 C<PERL_ANYEVENT_MCP_PERMISSION_HELPER> selects the external asking executable.
140     Standard C<HOME> and C<XDG_CONFIG_HOME> keep their standard names.
141 root 1.2
142     =head1 FUNCTIONS
143    
144 root 1.6 =over
145    
146 root 1.10 =item $class = AnyEvent::MCP::json_class
147    
148     Returns C<JSON::XS> if available, otherwise C<JSON::PP>. The caller
149     configures a new coder instance as needed.
150    
151 root 1.8 =item $bytes = AnyEvent::MCP::utf8enc $text
152    
153     Return a UTF-8 byte string for C<$text>, leaving the argument unchanged.
154    
155     =item $text = AnyEvent::MCP::utf8dec $bytes
156    
157     Decode a UTF-8 byte string into characters, dying on invalid UTF-8.
158     The argument is left unchanged. For intentional in-place conversions,
159     use Perl's C<utf8::encode> or C<utf8::decode> directly.
160    
161 root 1.6 =item $bytes = AnyEvent::MCP::random_bytes $length
162 root 1.2
163     Returns exactly C<$length> random bytes. Tries C</dev/urandom>, then an external
164     C<openssl rand> command. No additional random-number module is required.
165     Dies if neither source supplies the requested bytes successfully.
166     C<$length> must be a nonnegative integer; zero returns an empty string.
167    
168 root 1.6 =back
169    
170     =head2 PATCH UTILITIES
171    
172 root 1.7 Since applying patches to files is a common task for MCP servers, the
173 root 1.6 following utility functions can be used to ease that job. Together, they
174 root 1.7 define a common patch format (unified diff or a simplified version of it,
175     with fewer requirements to make it easier for the LLM to generate), helpers
176 root 1.6 to apply the patch and a helper to verify if the patch was applied
177     with sufficient precision.
178    
179 root 1.7 Use C<apply_udiff> to normalize, apply and validate a patch in one operation.
180     It writes a separate output file; the caller checks freshness and metadata
181     and commits the result.
182    
183     For an application-specific applier, the workflow is:
184 root 1.6
185     =over
186    
187     =item 1. AnyEvent::MCP::normalize_udiff
188    
189 root 1.7 Returns a unified diff for GNU patch and the permitted hunk offsets.
190    
191     =item 2. Apply the normalized diff
192 root 1.6
193 root 1.7 Run GNU patch with fuzz zero and capture its verbose output.
194 root 1.6
195 root 1.7 =item 3. AnyEvent::MCP::check_patch_output
196    
197     Checks the process status and output against the permitted offsets.
198     C<parse_patch_output> is available separately when only parsing is needed.
199 root 1.5
200 root 1.6 =back
201    
202 root 1.5 =head3 Input format
203    
204 root 1.6 The patch format accepted by normalize_udiff is an extension to the
205     (essentially undocumented) unified diff format.
206    
207 root 1.5 In a hunk header, only the old start C<-N> matters. It is the old-file line
208     of the first hunk body line, including context, not necessarily the first
209     changed line. Counts and the new-file position are ignored and recomputed.
210     Both ordinary headers and the abbreviated form are accepted:
211    
212     @@ -42,99 +123,99 @@
213     @@ -42 @@
214    
215     Optional text after the closing C<@@> is preserved. File headers and other
216     text before the first hunk are preserved; a diff must describe one file.
217    
218     Hunk body lines use the usual prefixes: a space for unchanged context,
219     C<-> for removed lines and C<+> for added lines. The
220     C<\ No newline at end of file> marker is preserved and counts neither side.
221     Trailing empty lines outside the final hunk are discarded.
222    
223 root 1.7 Pure insertion is permitted only at the beginning, using old start C<0>.
224     For example, C<@@ -0 @@> with one added line becomes C<@@ -0,0 +1,1 @@>.
225     An empty old-side range names the line before the insertion: C<-0,0>
226     means before line 1, whereas C<-1,0> would mean after line 1 and is rejected
227     here. Nonempty ranges use one-based line numbers.
228    
229 root 1.5 An insertion elsewhere needs old-side context. Empty hunks are rejected.
230     New positions include the cumulative line-count changes of preceding hunks.
231    
232     =head3 Applying the result
233    
234 root 1.6 The C<normalize_udiff> function does not apply the patch, check file
235     contents or guard against concurrent edits. The caller must supply those
236     checks, if required.
237 root 1.5
238     Context must match exactly: apply with fuzz zero. For each hunk,
239     C<$max_offset> permits relocation by at most the number of distinct old-side
240     lines minus one, or zero for a pure insertion. Repeated old-side lines do
241     not increase this allowance. The applier must enforce these limits; an
242     unrestricted search for matching context can select the wrong occurrence.
243    
244     For live Vim buffers, also require the expected changedtick to match.
245     File-based users need an equivalent check before replacing the file.
246    
247 root 1.6 To work around GNU patch's handling of asymmetric context, the
248     first context line of each hunk is rewritten as an identity
249     removal/addition. The line contents and old/new line counts are
250     unchanged. This is normalization for the patch applier, not a relaxation
251     of context matching.
252 root 1.5
253 root 1.6 =over
254    
255     =item ($diff, $max_offset) = AnyEvent::MCP::normalize_udiff $diff
256    
257     Normalizes a relaxed, single-file unified diff into ordinary unified diff
258     syntax. Returns the normalized C<$diff> and an array reference C<$max_offset>
259     containing the permitted whole-hunk relocation for each hunk, in order.
260     Dies on malformed hunks or when no hunks are found.
261    
262     Here is a suitable description for the diff format, e.g. in a tool
263     definition:
264    
265     Apply a unified diff to one regular file. Hunk counts are recomputed,
266     fuzz is disabled, whole-hunk relocation is limited per hunk by distinct
267     old-side lines. Pure insertion is allowed only at the beginning;
268     elsewhere include old-side context.
269    
270     =item $cv = AnyEvent::MCP::apply_udiff $input, $output, $diff
271    
272     Asynchronously applies the relaxed C<$diff> to the input file C<$input>,
273     writing a separate output file C<$output>. C<$diff> must contain bytes;
274     callers working with characters must encode them for the file themselves.
275    
276     Normalizes the diff, runs GNU patch using C<AnyEvent::Util::run_cmd>, and
277     validates its verbose output with C<check_patch_output>. The command uses
278     batch/forward mode, binary mode and fuzz zero. No shell is involved.
279    
280     C<$output> must not exist. It is reserved with mode 0600; patch runs in its
281     directory so incidental temporary files stay there. Input and output paths
282     are made absolute before starting the command. These must be trusted paths
283     in a directory controlled by the caller.
284    
285     Returns a condition variable. Its C<recv> returns the validated hunk array
286     reference, or throws on command/application failure. Setup failures throw
287     synchronously. Failed or partial output is removed. C<$input> is unchanged.
288    
289     The caller owns committing the successful output and removing it when no
290     longer needed. Freshness checks, metadata preservation, atomic replacement
291     and application-specific permissions also belong to the caller.
292    
293     For your reference, the exact options used are:
294    
295     --verbose --batch --forward --binary --fuzz=0
296     --no-backup-if-mismatch
297     --reject-file=- --output=... -- <inputfile>
298    
299     =item $parsed = AnyEvent::MCP::parse_patch_output $output
300 root 1.5
301     Parses C<LC_ALL=C> GNU patch C<--verbose> output without judging whether
302     the application is acceptable. C<$parsed> has two fields:
303    
304 root 1.6 =over
305 root 1.5
306     =item hunks => [$hunk...]
307    
308     Hunk records in output order. Each record contains C<hunk> (the one-based
309     number), C<success>, C<line> (the reported application line), C<fuzz> and
310     the signed C<offset>. Omitted fuzz and offset are zero. Failed and ignored
311     hunks have false C<success>.
312    
313     =item unparsed => [$line...]
314    
315     Lines not recognized as hunk results or GNU patch's verbose framing.
316     The parser preserves them for callers to interpret or reject.
317    
318     =back
319    
320     Use verbose output: ordinary patch output omits exact-position successes,
321     so it cannot account for every hunk.
322    
323 root 1.6 =item $hunks = AnyEvent::MCP::check_patch_output $status, $output, [$max_offset...]
324 root 1.5
325     Parses C<$output> and validates a complete application. C<$status> is the
326     raw process wait status, as returned by C<waitpid> or
327     C<AnyEvent::Util::run_cmd>, not just the exit code.
328    
329     Requires status zero, no unrecognized output, exactly the expected hunks
330     in numbered order, successful application, fuzz zero and each signed offset
331     within its corresponding absolute limit. C<[$max_offset...]> is the array
332     reference returned by C<normalize_udiff>. At least one hunk is required.
333    
334     Returns the parsed hunk array reference on success; otherwise dies with a
335     diagnostic. This is also suitable for callers running patch inside their
336     own sandbox.
337    
338 root 1.6 =back
339 root 1.5
340 root 1.1 =cut
341    
342     package AnyEvent::MCP;
343    
344     use common::sense;
345     use Digest::SHA ();
346    
347     our $VERSION = '0.0';
348    
349 root 1.10 sub json_class {
350     our $JSON_CLASS ||= eval { require JSON::XS; "JSON::XS" }
351     || do { require JSON::PP; "JSON::PP" };
352     }
353    
354 root 1.8 sub utf8enc($) {
355     my $text = shift;
356    
357     utf8::encode $text;
358     $text
359     }
360    
361     sub utf8dec($) {
362     my $bytes = shift;
363    
364     utf8::decode $bytes
365     or die "invalid UTF-8\n";
366     $bytes
367     }
368    
369 root 1.2 sub random_bytes($) {
370     my ($length) = @_;
371    
372     die "Invalid random byte count\n"
373     unless defined $length && $length =~ /\A[0-9]+\z/;
374     return "" unless $length;
375    
376     my $bytes = "";
377    
378     if (open my $fh, "<", "/dev/urandom") {
379     binmode $fh;
380     while (length $bytes < $length) {
381     read ($fh, $bytes, $length - length ($bytes), length $bytes)
382     or last;
383     }
384     close $fh;
385    
386     return $bytes if length $bytes == $length;
387     }
388    
389     if (open my $fh, "-|", "openssl", "rand", $length) {
390     binmode $fh;
391     local $/;
392     $bytes = <$fh>;
393     my $success = close $fh;
394    
395     return $bytes
396     if $success && defined $bytes && length $bytes == $length;
397     }
398    
399     die "Cannot obtain $length random bytes from /dev/urandom or openssl rand\n";
400     }
401    
402 root 1.1 sub hkdf_sha512_expand($$$) {
403     my ($prk, $info, $l) = @_;
404    
405 root 1.2 64 == length $prk
406     or die "hkdf_sha512_expand: prk length mist be 64 octets";
407    
408 root 1.1 my $t = "";
409     my $okm = "";
410     my $i = 0;
411    
412     do {
413     $t = Digest::SHA::hmac_sha512 $t . $info . chr ++$i, $prk;
414     $okm .= $t;
415     } while $l > length $okm;
416    
417     substr $okm, 0, $l
418     }
419    
420 root 1.5 sub normalize_udiff {
421     my $diff = shift;
422     my @line = split /\n/, $diff, -1;
423     my $delta = 0;
424     my $hunks = 0;
425     my @max_offset;
426    
427     pop @line while @line and !length $line[-1];
428    
429     for (my $i = 0; $i < @line; ++$i) {
430     next unless $line[$i] =~ /^@@ /;
431    
432     $line[$i] =~ /^@@ -(\d+)(?:,\d+)?(?: \+\d+(?:,\d+)?)? @@(.*)$/
433     or die "normalize_udiff: bad hunk header '$line[$i]'\n";
434    
435     my ($old_start, $suffix) = ($1, $2);
436     my ($old_count, $new_count) = (0, 0);
437     my %old_line;
438     my $j = $i + 1;
439    
440     # GNU patch mishandles hunks with more prefix than suffix context.
441     # Make the first context line an identity change without losing it.
442     # see https://unix.stackexchange.com/questions/414542/does-patch-work-with-asymmetric-context
443     splice @line, $i + 1, 1, "-$1", "+$1"
444     if $line[$i + 1] =~ /^ (.*)\z/;
445    
446     for (; $j < @line; ++$j) {
447     last if $line[$j] =~ /^@@ /;
448    
449     my $tag = substr $line[$j], 0, 1;
450    
451     if ($tag eq " ") {
452     ++$old_count;
453     ++$new_count;
454     $old_line{substr $line[$j], 1} = 1;
455     } elsif ($tag eq "-") {
456     ++$old_count;
457     $old_line{substr $line[$j], 1} = 1;
458     } elsif ($tag eq "+") {
459     ++$new_count;
460     } elsif ($line[$j] eq "\\ No newline at end of file") {
461     # Marker belongs to the preceding body line and counts neither side.
462     } else {
463     die "normalize_udiff: bad hunk line '$line[$j]'\n";
464     }
465     }
466    
467     $old_count or $new_count
468     or die "normalize_udiff: empty hunk at old line $old_start\n";
469    
470     $old_count or !$old_start
471     or die "normalize_udiff: hunk " . ($hunks + 1)
472     . " needs old-side context for insertion after old line $old_start\n";
473    
474     my $new_start = $old_start + $delta;
475     ++$new_start unless $old_count;
476     --$new_start unless $new_count;
477    
478     $new_start >= 0
479     or die "normalize_udiff: invalid new line $new_start\n";
480    
481     $line[$i] = sprintf "@@ -%d,%d +%d,%d @@%s",
482     $old_start, $old_count, $new_start, $new_count, $suffix;
483    
484     $delta += $new_count - $old_count;
485     ++$hunks;
486     my $max_offset = keys %old_line;
487     --$max_offset
488     if $max_offset;
489     push @max_offset, $max_offset;
490     $i = $j - 1;
491     }
492    
493     $hunks
494     or die "normalize_udiff: no hunks\n";
495    
496     (join ("\n", @line, ""), \@max_offset)
497     }
498    
499     sub parse_patch_output {
500     my ($output) = @_;
501     my (@hunks, @unparsed);
502    
503     for (split /\n/, $output) {
504     if (/^Hunk #(\d+) (succeeded|FAILED|ignored) at (-?\d+)(?: with fuzz (\d+))?(?: \(offset (-?\d+) lines?\))?\.\z/) {
505     push @hunks, {
506     hunk => 0 + $1,
507     success => $2 eq "succeeded",
508     line => 0 + $3,
509     fuzz => 0 + $4,
510     offset => 0 + $5,
511     };
512     } elsif (!length
513     || /^Hmm\.\.\. +Looks like a unified diff to me\.\.\.\z/
514     || /^The text leading up to this was:\z/
515     || /^-+\z/ || /^\|/
516     || /^patching file / || /^checking file /
517     || /^Using Plan [AB]\.\.\.\z/ || /^done\z/) {
518     # GNU patch --verbose framing, not hunk results.
519     } else {
520     push @unparsed, $_;
521     }
522     }
523    
524     { hunks => \@hunks, unparsed => \@unparsed }
525     }
526    
527     sub check_patch_output {
528     my ($status, $output, $max_offset) = @_;
529     my $parsed = parse_patch_output $output;
530     my $hunks = $parsed->{hunks};
531    
532     die "patch failed (wait status $status):\n$output"
533     if $status;
534     die "patch: unrecognized output:\n" . (join "\n", @{$parsed->{unparsed}}) . "\n"
535     if @{$parsed->{unparsed}};
536     die "patch: expected " . @$max_offset . " hunks, got " . @$hunks . "\n"
537     unless @$hunks == @$max_offset && @$hunks;
538    
539     for my $i (0 .. $#$hunks) {
540     my $hunk = $hunks->[$i];
541    
542     die "patch: unexpected hunk number $hunk->{hunk}\n"
543     unless $hunk->{hunk} == $i + 1;
544     die "patch: hunk $hunk->{hunk} failed\n"
545     unless $hunk->{success};
546     die "patch: hunk $hunk->{hunk} used fuzz $hunk->{fuzz}\n"
547     if $hunk->{fuzz};
548     die "patch: hunk $hunk->{hunk} offset $hunk->{offset} exceeds $max_offset->[$i]\n"
549     if abs $hunk->{offset} > $max_offset->[$i];
550     }
551    
552     $hunks
553     }
554    
555     sub apply_udiff {
556     my ($input, $output, $diff) = @_;
557     my ($normalized, $max_offset) = normalize_udiff $diff;
558    
559     require AnyEvent::Util;
560     require File::Spec;
561     require File::Basename;
562     require Fcntl;
563    
564     $input = File::Spec->rel2abs ($input);
565     $output = File::Spec->rel2abs ($output);
566     my $directory = File::Basename::dirname ($output);
567    
568     sysopen my $fh, $output, Fcntl::O_WRONLY () | Fcntl::O_CREAT () | Fcntl::O_EXCL (), 0600
569     or die "$output: $!\n";
570     close $fh or do { my $error = $!; unlink $output; die "$output: $error\n" };
571    
572     my $cv = AE::cv ();
573     my $log;
574     my $process = eval {
575     AnyEvent::Util::run_cmd ([
576     "patch", "--verbose", "--batch", "--forward", "--binary", "--fuzz=0",
577     "--no-backup-if-mismatch", "--reject-file=-", "--output=$output", "--", $input,
578     ],
579     "<" => \$normalized,
580     ">" => \$log,
581     close_all => 1,
582     on_prepare => sub {
583     $ENV{LC_ALL} = "C";
584     chdir $directory or die "$directory: $!\n";
585     defined POSIX::dup2 (1, 2) or die "dup2: $!\n";
586     },
587     );
588     };
589    
590     if ($@) {
591     my $error = $@;
592     unlink $output;
593     die $error;
594     }
595    
596     $process->cb (sub {
597     my $hunks;
598     eval { $hunks = check_patch_output $_[0]->recv, $log, $max_offset; 1 } or do {
599     my $error = $@;
600     unlink $output;
601     $cv->croak ($error);
602     return;
603     };
604    
605     $cv->send ($hunks);
606     });
607    
608     $cv
609     }
610    
611 root 1.1 sub _clean_text($) {
612     my ($text) = @_;
613    
614     my ($prefix) = (join "\n", grep /\S/, split /\n/, $text)
615     =~ /\A([ \t]*)[^\n]*(?:\n\1[^\n]*)*\z/;
616    
617     $text =~ s/^\Q$prefix\E//mg;
618     $text =~ s/\A\s+//;
619     $text =~ s/\s+\z//;
620     $text
621     }
622    
623     package AnyEvent::MCP::Base;
624    
625     sub new {
626     my ($class, %kv) = @_;
627     bless \%kv, $class
628     }
629    
630     sub event {
631     my ($self, $event, @args) = @_;
632     ($self->{"on_$event"} or return)->($self, @args)
633     }
634    
635     =head1 SEE ALSO
636    
637 root 1.16 L<AnyEvent::MCP::Intro>, L<AnyEvent::MCP::Server::Simple>,
638 root 1.1 L<AnyEvent>, L<https://modelcontextprotocol.io/>
639    
640     =head1 AUTHOR
641    
642     The main author of this module is OpenAI ChatGPT.
643    
644     Additional guidance received by:
645    
646     Marc Lehmann <schmorp@schmorp.de>
647     http://home.schmorp.de/
648    
649     =cut
650    
651     1
652