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.

insufficient_scope

  my $needed = $context->insufficient_scope;
  $context   = $context->insufficient_scope(['mcp:write']);

Array reference of scopes a denied request was missing, set by the server so the HTTP transport can emit an "insufficient_scope" challenge. "undef" when no scope check failed.

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.

scopes

  my $scopes = $context->scopes;
  $context   = $context->scopes(['mcp:read', 'mcp:write']);

OAuth scopes granted to the current request, as an array reference, populated from the "auth" hook of the HTTP transport. "undef" (the default) imposes no scope restriction, so scopes are only enforced for authenticated requests that provide them.

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.

has_scope

  my $bool = $context->has_scope('mcp:write');
  my $bool = $context->has_scope('mcp:read', 'mcp:write');

Returns true if every given scope is present in "scopes", or if "scopes" is "undef" (no restriction).

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-06-29 perl v5.44.0