ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/AnyEvent-MCP/lib/AnyEvent/MCP.pm
Revision: 1.1
Committed: Wed Oct 7 05:54:01 2026 UTC (3 weeks, 3 days ago) by root
Branch: MAIN
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     use AnyEvent::MCP::Server::Simple;
8    
9     mcp_tool ...
10     mcp_stdio;
11    
12     or use the object interface directly:
13    
14     use AnyEvent::MCP::Server;
15    
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     =over 4
34    
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     The interfaces are still being designed; this documentation is intentionally
58     only an overview for now.
59    
60     =cut
61    
62     package AnyEvent::MCP;
63    
64     use common::sense;
65     use Digest::SHA ();
66    
67     our $VERSION = '0.0';
68    
69     sub hkdf_sha512_expand($$$) {
70     my ($prk, $info, $l) = @_;
71    
72     my $t = "";
73     my $okm = "";
74     my $i = 0;
75    
76     do {
77     $t = Digest::SHA::hmac_sha512 $t . $info . chr ++$i, $prk;
78     $okm .= $t;
79     } while $l > length $okm;
80    
81     substr $okm, 0, $l
82     }
83    
84     sub _clean_text($) {
85     my ($text) = @_;
86    
87     my ($prefix) = (join "\n", grep /\S/, split /\n/, $text)
88     =~ /\A([ \t]*)[^\n]*(?:\n\1[^\n]*)*\z/;
89    
90     $text =~ s/^\Q$prefix\E//mg;
91     $text =~ s/\A\s+//;
92     $text =~ s/\s+\z//;
93     $text
94     }
95    
96     package AnyEvent::MCP::Base;
97    
98     sub new {
99     my ($class, %kv) = @_;
100     bless \%kv, $class
101     }
102    
103     sub event {
104     my ($self, $event, @args) = @_;
105     ($self->{"on_$event"} or return)->($self, @args)
106     }
107    
108     =head1 SEE ALSO
109    
110     L<AnyEvent>, L<https://modelcontextprotocol.io/>
111    
112     =head1 AUTHOR
113    
114     The main author of this module is OpenAI ChatGPT.
115    
116     Additional guidance received by:
117    
118     Marc Lehmann <schmorp@schmorp.de>
119     http://home.schmorp.de/
120    
121     =cut
122    
123     1
124