Skip to content

Commit 2660665

Browse files
committed
Merge branch 'master' of github.com:opgginc/laravel-mcp-server
2 parents 93e2ac7 + ec96234 commit 2660665

File tree

3 files changed

+25
-26
lines changed

3 files changed

+25
-26
lines changed

src/Console/Commands/MakeMcpToolCommand.php

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ class MakeMcpToolCommand extends Command
3232
/**
3333
* Create a new command instance.
3434
*
35-
* @param \Illuminate\Filesystem\Filesystem $files
3635
* @return void
3736
*/
3837
public function __construct(Filesystem $files)
@@ -55,6 +54,7 @@ public function handle()
5554
// Check if file already exists
5655
if ($this->files->exists($path)) {
5756
$this->error("MCP tool {$className} already exists!");
57+
5858
return 1;
5959
}
6060

@@ -69,15 +69,15 @@ public function handle()
6969
$fullClassName = "\\App\\MCP\\Tools\\{$className}";
7070

7171
// Ask if they want to automatically register the tool
72-
if ($this->confirm("Would you like to automatically register this tool in config/mcp-server.php?", true)) {
72+
if ($this->confirm('Would you like to automatically register this tool in config/mcp-server.php?', true)) {
7373
$this->registerToolInConfig($fullClassName);
7474
} else {
7575
$this->info("Don't forget to register your tool in config/mcp-server.php:");
76-
$this->comment(" // config/mcp-server.php");
76+
$this->comment(' // config/mcp-server.php');
7777
$this->comment(" 'tools' => [");
78-
$this->comment(" // other tools...");
78+
$this->comment(' // other tools...');
7979
$this->comment(" {$fullClassName}::class,");
80-
$this->comment(" ],");
80+
$this->comment(' ],');
8181
}
8282

8383
// Display testing instructions
@@ -107,7 +107,7 @@ protected function getClassName()
107107
$name = Str::studly($name);
108108

109109
// Ensure the class name ends with "Tool" if not already
110-
if (!Str::endsWith($name, 'Tool')) {
110+
if (! Str::endsWith($name, 'Tool')) {
111111
$name .= 'Tool';
112112
}
113113

@@ -117,7 +117,6 @@ protected function getClassName()
117117
/**
118118
* Get the destination file path.
119119
*
120-
* @param string $className
121120
* @return string
122121
*/
123122
protected function getPath(string $className)
@@ -136,7 +135,7 @@ protected function makeDirectory($path)
136135
{
137136
$directory = dirname($path);
138137

139-
if (!$this->files->isDirectory($directory)) {
138+
if (! $this->files->isDirectory($directory)) {
140139
$this->files->makeDirectory($directory, 0755, true, true);
141140
}
142141

@@ -146,7 +145,6 @@ protected function makeDirectory($path)
146145
/**
147146
* Build the class with the given name.
148147
*
149-
* @param string $className
150148
* @return string
151149
*/
152150
protected function buildClass(string $className)
@@ -163,8 +161,8 @@ protected function buildClass(string $className)
163161
$toolName = preg_replace('/\-+/', '-', $toolName);
164162

165163
// Ensure it starts with a letter
166-
if (!preg_match('/^[a-z]/', $toolName)) {
167-
$toolName = 'tool-' . $toolName;
164+
if (! preg_match('/^[a-z]/', $toolName)) {
165+
$toolName = 'tool-'.$toolName;
168166
}
169167

170168
return $this->replaceStubPlaceholders($stub, $className, $toolName);
@@ -177,15 +175,12 @@ protected function buildClass(string $className)
177175
*/
178176
protected function getStubPath()
179177
{
180-
return __DIR__ . '/../../stubs/tool.stub';
178+
return __DIR__.'/../../stubs/tool.stub';
181179
}
182180

183181
/**
184182
* Replace the stub placeholders with actual values.
185183
*
186-
* @param string $stub
187-
* @param string $className
188-
* @param string $toolName
189184
* @return string
190185
*/
191186
protected function replaceStubPlaceholders(string $stub, string $className, string $toolName)
@@ -200,23 +195,25 @@ protected function replaceStubPlaceholders(string $stub, string $className, stri
200195
/**
201196
* Register the tool in the MCP server configuration file.
202197
*
203-
* @param string $toolClassName Fully qualified class name of the tool
198+
* @param string $toolClassName Fully qualified class name of the tool
204199
* @return bool Whether registration was successful
205200
*/
206201
protected function registerToolInConfig(string $toolClassName): bool
207202
{
208203
$configPath = config_path('mcp-server.php');
209204

210-
if (!file_exists($configPath)) {
205+
if (! file_exists($configPath)) {
211206
$this->error("Config file not found: {$configPath}");
207+
212208
return false;
213209
}
214210

215211
$content = file_get_contents($configPath);
216212

217213
// Find the tools array in the config file
218-
if (!preg_match('/[\'"]tools[\'"]\s*=>\s*\[(.*?)\s*\],/s', $content, $matches)) {
219-
$this->error("Could not locate tools array in config file.");
214+
if (! preg_match('/[\'"]tools[\'"]\s*=>\s*\[(.*?)\s*\],/s', $content, $matches)) {
215+
$this->error('Could not locate tools array in config file.');
216+
220217
return false;
221218
}
222219

@@ -225,20 +222,23 @@ protected function registerToolInConfig(string $toolClassName): bool
225222

226223
// Check if the tool is already registered
227224
if (strpos($toolsArrayContent, $toolClassName) !== false) {
228-
$this->info("Tool is already registered in config file.");
225+
$this->info('Tool is already registered in config file.');
226+
229227
return true;
230228
}
231229

232230
// Add the new tool to the tools array
233-
$newToolsArrayContent = $toolsArrayContent . $fullEntry;
231+
$newToolsArrayContent = $toolsArrayContent.$fullEntry;
234232
$newContent = str_replace($toolsArrayContent, $newToolsArrayContent, $content);
235233

236234
// Write the updated content back to the config file
237235
if (file_put_contents($configPath, $newContent)) {
238-
$this->info("Tool registered successfully in config/mcp-server.php");
236+
$this->info('Tool registered successfully in config/mcp-server.php');
237+
239238
return true;
240239
} else {
241-
$this->error("Failed to update config file. Please manually register the tool.");
240+
$this->error('Failed to update config file. Please manually register the tool.');
241+
242242
return false;
243243
}
244244
}

src/LaravelMcpServerServiceProvider.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44

55
use Illuminate\Support\Facades\Config;
66
use Illuminate\Support\Facades\Route;
7+
use OPGG\LaravelMcpServer\Console\Commands\MakeMcpToolCommand;
78
use OPGG\LaravelMcpServer\Http\Controllers\MessageController;
89
use OPGG\LaravelMcpServer\Http\Controllers\SseController;
910
use OPGG\LaravelMcpServer\Providers\SseServiceProvider;
1011
use OPGG\LaravelMcpServer\Server\MCPServer;
1112
use OPGG\LaravelMcpServer\Console\Commands\MakeMcpCommandCommand;
12-
use OPGG\LaravelMcpServer\Console\Commands\MakeMcpToolCommand;
1313
use OPGG\LaravelMcpServer\Console\Commands\TestMcpToolCommand;
1414
use Spatie\LaravelPackageTools\Package;
1515
use Spatie\LaravelPackageTools\PackageServiceProvider;
@@ -54,7 +54,7 @@ protected function registerRoutes(): void
5454
if (!Config::get('mcp-server.enabled', true)) {
5555
return;
5656
}
57-
57+
5858
// Skip route registration if MCPServer instance doesn't exist
5959
if (!app()->has(MCPServer::class)) {
6060
return;

src/Providers/SseServiceProvider.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use OPGG\LaravelMcpServer\Protocol\MCPProtocol;
88
use OPGG\LaravelMcpServer\Server\MCPServer;
99
use OPGG\LaravelMcpServer\Server\ServerCapabilities;
10-
use OPGG\LaravelMcpServer\Services\CommandService\CommandRepository;
1110
use OPGG\LaravelMcpServer\Services\SseAdapterFactory;
1211
use OPGG\LaravelMcpServer\Services\ToolService\ToolRepository;
1312
use OPGG\LaravelMcpServer\Transports\SseTransport;

0 commit comments

Comments
 (0)