Package Info

perl-MCP


Connect Perl with AI using MCP (Model Context Protocol)


Unspecified

Connect Perl with AI using the Model Context Protocol (MCP). Currently this module is focused on tool calling, but it will be extended to support other MCP features in the future. At its core, MCP is all about text processing, making it a great fit for Perl.

Streamable HTTP Transport Use the MCP::Server/"to_action" method to add an MCP endpoint to any Mojolicious application. The tool name and description are used for discovery, and the at https://json-schema.org is used to validate the input.

  use Mojolicious::Lite -signatures;

  use MCP::Server;

  my $server = MCP::Server->new;
  $server->tool(
    name         => 'echo',
    description  => 'Echo the input text',
    input_schema => {type => 'object', properties => {msg => {type => 'string'}}, required => ['msg']},
    code         => sub ($tool, $args) {
      return "Echo: $args->{msg}";
    }
  );

  any '/mcp' => $server->to_action;

  app->start;

Authentication can be added by the web application, just like for any
other route. To allow for MCP applications to scale with prefork web
servers, server to client streaming is currentlly avoided when
possible.

Stdio Transport Build local command line applications and use the stdio transport for testing with the MCP::Server/"to_stdio" method.

  use Mojo::Base -strict, -signatures;

  use MCP::Server;

  my $server = MCP::Server->new;
  $server->tool(
    name         => 'echo',
    description  => 'Echo the input text',
    input_schema => {type => 'object', properties => {msg => {type => 'string'}}, required => ['msg']},
    code         => sub ($tool, $args) {
      return "Echo: $args->{msg}";
    }
  );

  $server->to_stdio;

Just run the script and 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","arguments":{"msg":"hello perl"}}}

License: MIT
URL: https://metacpan.org/release/MCP

Categories

Releases

Package Version Update ID Released Package Hub Version Platforms Subpackages
0.40.0-bp156.2.1 info openSUSE-2025-340 2025-09-08 15 SP6 Update
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-MCP
0.40.0-bp160.1.1 info GA Release 2025-08-05 16.0
  • AArch64
  • ppc64le
  • s390x
  • x86-64
  • perl-MCP