Scroll to navigation

MCP::Server::Context(3) User Contributed Perl Documentation MCP::Server::Context(3)

NAME

MCP::Server::Context - Request context container

SYNOPSIS

  use MCP::Server::Context;
  my $context = MCP::Server::Context->new;
  $context->notify_progress(1, 2, 'halfway');

DESCRIPTION

MCP::Server::Context is a container for per-invocation request context.

ATTRIBUTES

MCP::Server::Context implements the following attributes.

controller

  my $c    = $context->controller;
  $context = $context->controller(Mojolicious::Controller->new);

The Mojolicious::Controller serving the current request, when the HTTP transport is in use.

progress_token

  my $token = $context->progress_token;
  $context  = $context->progress_token('tok-1');

The progress token provided by the client in "_meta.progressToken", or "undef" if none was sent.

session_id

  my $id   = $context->session_id;
  $context = $context->session_id('12345');

Identifier of the session this request belongs to.

transport

  my $transport = $context->transport;
  $context      = $context->transport(MCP::Server::Transport::HTTP->new);

The transport handling the current request.

METHODS

MCP::Server::Context inherits all methods from Mojo::Base and implements the following new ones.

notify

  my $bool = $context->notify($method);
  my $bool = $context->notify($method, {foo => 'bar'});

Send a JSON-RPC notification to the client associated with the current request. Returns true on success, or "undef" if no notification could be delivered.

notify_progress

  my $bool = $context->notify_progress($progress);
  my $bool = $context->notify_progress($progress, $total);
  my $bool = $context->notify_progress($progress, $total, $message);

Send a "notifications/progress" JSON-RPC notification for the progress token associated with the current request. Returns true on success, or "undef" if no progress token was provided by the client.

SEE ALSO

MCP, <https://mojolicious.org>, <https://modelcontextprotocol.io>.

2026-05-07 perl v5.42.1