Skip to content

Commit 6af600f

Browse files
refactor: rename RequestHandler to Dispatcher for better semantic clarity
1 parent 4e51bca commit 6af600f

File tree

20 files changed

+132
-125
lines changed

20 files changed

+132
-125
lines changed

examples/02-discovery-http-userprofile/server.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,8 @@ public function log($level, \Stringable|string $message, array $context = []): v
7171

7272
$server->discover(__DIR__, ['.']);
7373

74-
$transport = new HttpServerTransport('127.0.0.1', 8080, 'mcp');
75-
// $transport = new StreamableHttpServerTransport('127.0.0.1', 8080, 'mcp');
74+
// $transport = new HttpServerTransport('127.0.0.1', 8080, 'mcp');
75+
$transport = new StreamableHttpServerTransport('127.0.0.1', 8080, 'mcp');
7676

7777
$server->listen($transport);
7878

src/Attributes/McpResource.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,5 +27,6 @@ public function __construct(
2727
public ?string $mimeType = null,
2828
public ?int $size = null,
2929
public ?Annotations $annotations = null,
30-
) {}
30+
) {
31+
}
3132
}

src/Attributes/McpResourceTemplate.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,6 @@ public function __construct(
2525
public ?string $description = null,
2626
public ?string $mimeType = null,
2727
public ?Annotations $annotations = null,
28-
) {}
28+
) {
29+
}
2930
}

src/Attributes/McpTool.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,6 @@ public function __construct(
1717
public ?string $name = null,
1818
public ?string $description = null,
1919
public ?ToolAnnotations $annotations = null,
20-
) {}
20+
) {
21+
}
2122
}

src/Configuration.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,6 @@ public function __construct(
3737
public readonly ContainerInterface $container,
3838
public readonly int $definitionCacheTtl = 3600,
3939
public readonly int $paginationLimit = 50,
40-
) {}
40+
) {
41+
}
4142
}

src/Support/RequestHandler.php renamed to src/Dispatcher.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
declare(strict_types=1);
44

5-
namespace PhpMcp\Server\Support;
5+
namespace PhpMcp\Server;
66

77
use JsonException;
88
use PhpMcp\Schema\JsonRpc\Request;
@@ -39,12 +39,13 @@
3939
use PhpMcp\Server\Protocol;
4040
use PhpMcp\Server\Registry;
4141
use PhpMcp\Server\Session\SubscriptionManager;
42+
use PhpMcp\Server\Support\SchemaValidator;
4243
use PhpMcp\Server\Traits\ResponseFormatter;
4344
use Psr\Container\ContainerInterface;
4445
use Psr\Log\LoggerInterface;
4546
use Throwable;
4647

47-
class RequestHandler
48+
class Dispatcher
4849
{
4950
use ResponseFormatter;
5051

@@ -159,7 +160,7 @@ public function handleToolCall(CallToolRequest $request): CallToolResult
159160
$toolName = $request->name;
160161
$arguments = $request->arguments;
161162

162-
['tool' => $tool, 'invoker' => $invoker] = $this->registry->getTool($toolName);
163+
['tool' => $tool, 'handler' => $handler] = $this->registry->getTool($toolName);
163164
if (! $tool) {
164165
throw McpServerException::methodNotFound("Tool '{$toolName}' not found.");
165166
}
@@ -187,7 +188,7 @@ public function handleToolCall(CallToolRequest $request): CallToolResult
187188
}
188189

189190
try {
190-
$result = $invoker->invoke($this->container, $arguments);
191+
$result = $handler->handle($this->container, $arguments);
191192
$formattedResult = $this->formatToolResult($result);
192193

193194
return new CallToolResult($formattedResult, false);
@@ -230,15 +231,15 @@ public function handleResourceRead(ReadResourceRequest $request): ReadResourceRe
230231
{
231232
$uri = $request->uri;
232233

233-
['resource' => $resource, 'invoker' => $invoker, 'variables' => $uriVariables] = $this->registry->getResource($uri);
234+
['resource' => $resource, 'handler' => $handler, 'variables' => $uriVariables] = $this->registry->getResource($uri);
234235

235236
if (! $resource) {
236237
throw McpServerException::invalidParams("Resource URI '{$uri}' not found.");
237238
}
238239

239240
try {
240241
$arguments = array_merge($uriVariables, ['uri' => $uri]);
241-
$result = $invoker->invoke($this->container, $arguments);
242+
$result = $handler->handle($this->container, $arguments);
242243
$contents = $this->formatResourceContents($result, $uri, $resource->mimeType);
243244

244245
return new ReadResourceResult($contents);
@@ -281,7 +282,7 @@ public function handlePromptGet(GetPromptRequest $request): GetPromptResult
281282
$promptName = $request->name;
282283
$arguments = $request->arguments;
283284

284-
['prompt' => $prompt, 'invoker' => $invoker] = $this->registry->getPrompt($promptName);
285+
['prompt' => $prompt, 'handler' => $handler] = $this->registry->getPrompt($promptName);
285286
if (! $prompt) {
286287
throw McpServerException::invalidParams("Prompt '{$promptName}' not found.");
287288
}
@@ -295,7 +296,7 @@ public function handlePromptGet(GetPromptRequest $request): GetPromptResult
295296
}
296297

297298
try {
298-
$result = $invoker->invoke($this->container, $arguments);
299+
$result = $handler->handle($this->container, $arguments);
299300
$messages = $this->formatPromptMessages($result);
300301

301302
return new GetPromptResult($messages, $prompt->description);

src/Protocol.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,12 @@ public function __construct(
5151
protected Configuration $configuration,
5252
protected Registry $registry,
5353
protected SessionManager $sessionManager,
54-
protected ?RequestHandler $requestHandler = null,
54+
protected ?Dispatcher $dispatcher = null,
5555
protected ?SubscriptionManager $subscriptionManager = null,
5656
) {
5757
$this->logger = $this->configuration->logger;
5858
$this->subscriptionManager ??= new SubscriptionManager($this->logger);
59-
$this->requestHandler ??= new RequestHandler($this->configuration, $this->registry, $this->subscriptionManager);
59+
$this->dispatcher ??= new Dispatcher($this->configuration, $this->registry, $this->subscriptionManager);
6060

6161
$this->sessionManager->on('session_deleted', function (string $sessionId) {
6262
$this->subscriptionManager->cleanupSession($sessionId);
@@ -174,7 +174,7 @@ private function processRequest(Request $request, SessionInterface $session): Re
174174

175175
$this->assertRequestCapability($request->method);
176176

177-
$result = $this->requestHandler->handleRequest($request, $session);
177+
$result = $this->dispatcher->handleRequest($request, $session);
178178

179179
return Response::make($request->id, $result);
180180
} catch (McpServerException $e) {
@@ -207,7 +207,7 @@ private function processNotification(Notification $notification, SessionInterfac
207207
$params = $notification->params;
208208

209209
try {
210-
$this->requestHandler->handleNotification($notification, $session);
210+
$this->dispatcher->handleNotification($notification, $session);
211211
} catch (Throwable $e) {
212212
$this->logger->error('Error while processing notification', ['method' => $method, 'exception' => $e->getMessage()]);
213213
return;

0 commit comments

Comments
 (0)