|
10 | 10 |
|
11 | 11 | class Boost extends Server |
12 | 12 | { |
13 | | - public string $serverName = 'Laravel Boost'; |
| 13 | + /** |
| 14 | + * The MCP server's name. |
| 15 | + */ |
| 16 | + protected string $name = 'Laravel Boost'; |
14 | 17 |
|
15 | | - public string $serverVersion = '0.0.1'; |
| 18 | + /** |
| 19 | + * The MCP server's version. |
| 20 | + */ |
| 21 | + protected string $version = '0.0.1'; |
16 | 22 |
|
17 | | - public string $instructions = 'Laravel ecosystem MCP server offering database schema access, Artisan commands, error logs, Tinker execution, semantic documentation search and more. Boost helps with code generation.'; |
| 23 | + /** |
| 24 | + * The MCP server's instructions for the LLM. |
| 25 | + */ |
| 26 | + protected string $instructions = 'Laravel ecosystem MCP server offering database schema access, Artisan commands, error logs, Tinker execution, semantic documentation search and more. Boost helps with code generation.'; |
18 | 27 |
|
19 | | - public int $defaultPaginationLength = 50; |
| 28 | + /** |
| 29 | + * The tools registered with this MCP server. |
| 30 | + * |
| 31 | + * @var array<int, class-string<\Laravel\Mcp\Server\Tool>> |
| 32 | + */ |
| 33 | + protected array $tools = []; |
20 | 34 |
|
21 | 35 | /** |
22 | | - * @var string[] |
| 36 | + * The resources registered with this MCP server. |
| 37 | + * |
| 38 | + * @var array<int, class-string<\Laravel\Mcp\Server\Resource>> |
23 | 39 | */ |
24 | | - public array $resources = [ |
| 40 | + protected array $resources = [ |
25 | 41 | ApplicationInfo::class, |
26 | 42 | ]; |
27 | 43 |
|
| 44 | + /** |
| 45 | + * The prompts registered with this MCP server. |
| 46 | + * |
| 47 | + * @var array<int, class-string<\Laravel\Mcp\Server\Prompt>> |
| 48 | + */ |
| 49 | + protected array $prompts = []; |
| 50 | + |
28 | 51 | public function boot(): void |
29 | 52 | { |
30 | | - $this->discoverTools(); |
31 | | - $this->discoverResources(); |
32 | | - $this->discoverPrompts(); |
| 53 | + collect($this->discoverTools())->each(fn (string $tool) => $this->tools[] = $tool); |
| 54 | + collect($this->discoverResources())->each(fn (string $resource) => $this->resources[] = $resource); |
| 55 | + collect($this->discoverPrompts())->each(fn (string $prompt) => $this->prompts[] = $prompt); |
33 | 56 |
|
34 | 57 | // Override the tools/call method to use our ToolExecutor |
35 | 58 | $this->methods['tools/call'] = CallToolWithExecutor::class; |
36 | 59 | } |
37 | 60 |
|
38 | 61 | /** |
39 | | - * @return array<string> |
| 62 | + * @return array<int, class-string<\Laravel\Mcp\Server\Tool>> |
40 | 63 | */ |
41 | 64 | protected function discoverTools(): array |
42 | 65 | { |
| 66 | + $tools = []; |
| 67 | + |
43 | 68 | $excludedTools = config('boost.mcp.tools.exclude', []); |
44 | 69 | $toolDir = new \DirectoryIterator(__DIR__.DIRECTORY_SEPARATOR.'Tools'); |
| 70 | + |
45 | 71 | foreach ($toolDir as $toolFile) { |
46 | 72 | if ($toolFile->isFile() && $toolFile->getExtension() === 'php') { |
47 | 73 | $fqdn = 'Laravel\\Boost\\Mcp\\Tools\\'.$toolFile->getBasename('.php'); |
48 | 74 | if (class_exists($fqdn) && ! in_array($fqdn, $excludedTools, true)) { |
49 | | - $this->addTool($fqdn); |
| 75 | + $tools[] = $fqdn; |
50 | 76 | } |
51 | 77 | } |
52 | 78 | } |
53 | 79 |
|
54 | 80 | $extraTools = config('boost.mcp.tools.include', []); |
55 | 81 | foreach ($extraTools as $toolClass) { |
56 | 82 | if (class_exists($toolClass)) { |
57 | | - $this->addTool($toolClass); |
| 83 | + $tools[] = $toolClass; |
58 | 84 | } |
59 | 85 | } |
60 | 86 |
|
61 | | - return $this->registeredTools; |
| 87 | + return $tools; |
62 | 88 | } |
63 | 89 |
|
64 | 90 | /** |
65 | | - * @return array<string> |
| 91 | + * @return array<int, class-string<\Laravel\Mcp\Server\Resource>> |
66 | 92 | */ |
67 | 93 | protected function discoverResources(): array |
68 | 94 | { |
| 95 | + $resources = []; |
| 96 | + |
69 | 97 | $excludedResources = config('boost.mcp.resources.exclude', []); |
70 | 98 | $resourceDir = new \DirectoryIterator(__DIR__.DIRECTORY_SEPARATOR.'Resources'); |
| 99 | + |
71 | 100 | foreach ($resourceDir as $resourceFile) { |
72 | 101 | if ($resourceFile->isFile() && $resourceFile->getExtension() === 'php') { |
73 | | - $fqdn = 'Laravel\\Boost\\Mcp\\Resources\\'.$resourceFile; |
74 | | - if (class_exists($fqdn) && ! in_array($fqdn, $excludedResources, true)) { |
75 | | - $this->addResource($fqdn); |
| 102 | + $fqdn = 'Laravel\\Boost\\Mcp\\Resources\\'.$resourceFile->getBasename('.php'); |
| 103 | + if (class_exists($fqdn) && ! in_array($fqdn, $excludedResources, true) && $fqdn !== ApplicationInfo::class) { |
| 104 | + $resources[] = $fqdn; |
76 | 105 | } |
77 | 106 | } |
78 | 107 | } |
79 | 108 |
|
80 | 109 | $extraResources = config('boost.mcp.resources.include', []); |
81 | 110 | foreach ($extraResources as $resourceClass) { |
82 | 111 | if (class_exists($resourceClass)) { |
83 | | - $this->addResource($resourceClass); |
| 112 | + $resources[] = $resourceClass; |
84 | 113 | } |
85 | 114 | } |
86 | 115 |
|
87 | | - return $this->registeredResources; |
| 116 | + return $resources; |
88 | 117 | } |
89 | 118 |
|
90 | 119 | /** |
91 | | - * @return array<string> |
| 120 | + * @return array<int, class-string<\Laravel\Mcp\Server\Prompt>> |
92 | 121 | */ |
93 | 122 | protected function discoverPrompts(): array |
94 | 123 | { |
| 124 | + $prompts = []; |
| 125 | + |
95 | 126 | $excludedPrompts = config('boost.mcp.prompts.exclude', []); |
96 | 127 | $promptDir = new \DirectoryIterator(__DIR__.DIRECTORY_SEPARATOR.'Prompts'); |
| 128 | + |
97 | 129 | foreach ($promptDir as $promptFile) { |
98 | 130 | if ($promptFile->isFile() && $promptFile->getExtension() === 'php') { |
99 | | - $fqdn = 'Laravel\\Boost\\Mcp\\Prompts\\'.$promptFile; |
| 131 | + $fqdn = 'Laravel\\Boost\\Mcp\\Prompts\\'.$promptFile->getBasename('.php'); |
100 | 132 | if (class_exists($fqdn) && ! in_array($fqdn, $excludedPrompts, true)) { |
101 | | - $this->addPrompt($fqdn); |
| 133 | + $prompts[] = $fqdn; |
102 | 134 | } |
103 | 135 | } |
104 | 136 | } |
105 | 137 |
|
106 | 138 | $extraPrompts = config('boost.mcp.prompts.include', []); |
107 | 139 | foreach ($extraPrompts as $promptClass) { |
108 | 140 | if (class_exists($promptClass)) { |
109 | | - $this->addResource($promptClass); |
| 141 | + $prompts[] = $promptClass; |
110 | 142 | } |
111 | 143 | } |
112 | 144 |
|
113 | | - return $this->registeredPrompts; |
| 145 | + return $prompts; |
114 | 146 | } |
115 | 147 | } |
0 commit comments