Skip to content

Commit 21117a5

Browse files
committed
Refactor
1 parent 36e915a commit 21117a5

13 files changed

+279
-469
lines changed

src/Server.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@
3636
*/
3737
abstract class Server
3838
{
39+
public const CAPABILITY_TOOLS = 'tools';
40+
41+
public const CAPABILITY_RESOURCES = 'resources';
42+
43+
public const CAPABILITY_PROMPTS = 'prompts';
44+
45+
public const CAPABILITY_COMPLETTIONS = 'completions';
46+
3947
protected string $name = 'Laravel MCP Server';
4048

4149
protected string $version = '0.0.1';
@@ -58,13 +66,13 @@ abstract class Server
5866
* @var array<string, array<string, bool>|stdClass|string>
5967
*/
6068
protected array $capabilities = [
61-
'tools' => [
69+
self::CAPABILITY_TOOLS => [
6270
'listChanged' => false,
6371
],
64-
'resources' => [
72+
self::CAPABILITY_RESOURCES => [
6573
'listChanged' => false,
6674
],
67-
'prompts' => [
75+
self::CAPABILITY_PROMPTS => [
6876
'listChanged' => false,
6977
],
7078
];

src/Server/Methods/CompletionComplete.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use Illuminate\Container\Container;
88
use Illuminate\Support\Arr;
99
use InvalidArgumentException;
10+
use Laravel\Mcp\Server;
1011
use Laravel\Mcp\Server\Contracts\HasUriTemplate;
1112
use Laravel\Mcp\Server\Contracts\Method;
1213
use Laravel\Mcp\Server\Contracts\SupportsCompletion;
@@ -26,7 +27,7 @@ class CompletionComplete implements Method
2627

2728
public function handle(JsonRpcRequest $request, ServerContext $context): JsonRpcResponse
2829
{
29-
if (! isset($context->serverCapabilities['completions'])) {
30+
if (! $context->hasCapability(Server::CAPABILITY_COMPLETTIONS)) {
3031
throw new JsonRpcException(
3132
'Server does not support completions capability.',
3233
-32601,
@@ -54,13 +55,13 @@ public function handle(JsonRpcRequest $request, ServerContext $context): JsonRpc
5455
if (! $primitive instanceof SupportsCompletion) {
5556
throw new JsonRpcException(
5657
'The referenced primitive does not support completion.',
57-
-32602,
58+
-32601,
5859
$request->id,
5960
);
6061
}
6162

62-
$argumentName = $argument['name'] ?? null;
63-
$argumentValue = $argument['value'] ?? '';
63+
$argumentName = Arr::get($argument, 'name');
64+
$argumentValue = Arr::get($argument, 'value', '');
6465

6566
if (is_null($argumentName)) {
6667
throw new JsonRpcException(

src/Server/Methods/Concerns/ResolvesPrompts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ trait ResolvesPrompts
1212
{
1313
protected function resolvePrompt(?string $name, ServerContext $context): Prompt
1414
{
15-
if (is_null($name)) {
15+
if (! $name) {
1616
throw new InvalidArgumentException('Missing [name] parameter.');
1717
}
1818

src/Server/ServerContext.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,11 @@ public function perPage(?int $requestedPerPage = null): int
8383
return min($requestedPerPage ?? $this->defaultPaginationLength, $this->maxPaginationLength);
8484
}
8585

86+
public function hasCapability(string $capability): bool
87+
{
88+
return array_key_exists($capability, $this->serverCapabilities);
89+
}
90+
8691
/**
8792
* @template T of Primitive
8893
*

0 commit comments

Comments
 (0)