File Coverage

blib/lib/MCP/Primitive.pm
Criterion Covered Total %
statement 10 10 100.0
branch 1 2 50.0
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 15 16 93.7


line stmt bran cond sub pod time code
1             package MCP::Primitive;
2 5     5   2664 use Mojo::Base -base, -signatures;
  5         14  
  5         33  
3              
4 5     5   3319 use MCP::Server::Context;
  5         13  
  5         24  
5              
6             has scopes => sub { [] };
7              
8 7 50   7 1 89 sub context ($self) { $self->{context} || MCP::Server::Context->new }
  7         9  
  7         8  
  7         30  
9              
10             1;
11              
12             =encoding utf8
13              
14             =head1 NAME
15              
16             MCP::Primitive - Primitive base class
17              
18             =head1 SYNOPSIS
19              
20             package MyMCPPrimitive;
21             use Mojo::Base 'MCP::Primitive';
22              
23             1;
24              
25             =head1 DESCRIPTION
26              
27             L is a base class for MCP (Model Context Protocol) primitives such as L, L,
28             and L.
29              
30             =head1 ATTRIBUTES
31              
32             L implements the following attributes.
33              
34             =head2 scopes
35              
36             my $scopes = $primitive->scopes;
37             $primitive = $primitive->scopes(['mcp:read', 'mcp:write']);
38              
39             OAuth scopes required to list or call this primitive, as an array reference; all of them must be granted. This is a
40             local authorization policy layered on the HTTP transport's L hook, not wire-level
41             MCP metadata, and is only enforced for requests that supply scopes (so it has no effect over stdio). Defaults to no
42             required scopes.
43              
44             =head1 METHODS
45              
46             L inherits all methods from L and implements the following new ones.
47              
48             =head2 context
49              
50             my $context = $primitive->context;
51              
52             Returns the L for the current request. Capture this before an async boundary to keep using
53             its notification methods from later callbacks.
54              
55             # Get controller for requests using the HTTP transport
56             my $c = $primitive->context->controller;
57              
58             =head1 SEE ALSO
59              
60             L, L, L.
61              
62             =cut