-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathCachedCalculatorElements.php
More file actions
52 lines (44 loc) · 1.22 KB
/
CachedCalculatorElements.php
File metadata and controls
52 lines (44 loc) · 1.22 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/*
* This file is part of the official PHP MCP SDK.
*
* A collaboration between Symfony and the PHP Foundation.
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Mcp\Example\Server\CachedDiscovery;
use Mcp\Capability\Attribute\McpTool;
use Mcp\Exception\ToolCallException;
/**
* Example MCP elements for demonstrating cached discovery.
*
* This class contains simple calculator tools that will be discovered
* and cached for improved performance on subsequent server starts.
*/
class CachedCalculatorElements
{
#[McpTool(name: 'add_numbers')]
public function add(int $a, int $b): int
{
return $a + $b;
}
#[McpTool(name: 'multiply_numbers')]
public function multiply(int $a, int $b): int
{
return $a * $b;
}
#[McpTool(name: 'divide_numbers')]
public function divide(int $a, int $b): float
{
if (0 === $b) {
throw new ToolCallException('Division by zero is not allowed');
}
return $a / $b;
}
#[McpTool(name: 'power')]
public function power(int $base, int $exponent): int
{
return (int) $base ** $exponent;
}
}