Skip to content

Commit e276e6b

Browse files
chore: apply code style fixes
1 parent 468b9ff commit e276e6b

30 files changed

+252
-136
lines changed

examples/01-discovery-stdio-calculator/server.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
* file that was distributed with this source code.
1111
*/
1212

13-
require_once dirname(__DIR__) . '/bootstrap.php';
13+
require_once dirname(__DIR__).'/bootstrap.php';
1414
chdir(__DIR__);
1515

1616
use Mcp\Server;

examples/10-simple-http-transport/McpElements.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,14 @@
11
<?php
22

3+
/*
4+
* This file is part of the official PHP MCP SDK.
5+
*
6+
* A collaboration between Symfony and the PHP Foundation.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
312
namespace Mcp\Example\HttpTransportExample;
413

514
use Mcp\Capability\Attribute\McpPrompt;
@@ -8,10 +17,12 @@
817

918
class McpElements
1019
{
11-
public function __construct() {}
20+
public function __construct()
21+
{
22+
}
1223

1324
/**
14-
* Get the current server time
25+
* Get the current server time.
1526
*/
1627
#[McpTool(name: 'current_time')]
1728
public function getCurrentTime(string $format = 'Y-m-d H:i:s'): string
@@ -24,7 +35,7 @@ public function getCurrentTime(string $format = 'Y-m-d H:i:s'): string
2435
}
2536

2637
/**
27-
* Calculate simple math operations
38+
* Calculate simple math operations.
2839
*/
2940
#[McpTool(name: 'calculate')]
3041
public function calculate(float $a, float $b, string $operation): float|string
@@ -33,13 +44,13 @@ public function calculate(float $a, float $b, string $operation): float|string
3344
'add', '+' => $a + $b,
3445
'subtract', '-' => $a - $b,
3546
'multiply', '*' => $a * $b,
36-
'divide', '/' => $b != 0 ? $a / $b : 'Error: Division by zero',
37-
default => 'Error: Unknown operation. Use: add, subtract, multiply, divide'
47+
'divide', '/' => 0 != $b ? $a / $b : 'Error: Division by zero',
48+
default => 'Error: Unknown operation. Use: add, subtract, multiply, divide',
3849
};
3950
}
4051

4152
/**
42-
* Server information resource
53+
* Server information resource.
4354
*/
4455
#[McpResource(
4556
uri: 'info://server/status',
@@ -54,12 +65,12 @@ public function getServerStatus(): array
5465
'timestamp' => time(),
5566
'version' => '1.0.0',
5667
'transport' => 'HTTP',
57-
'uptime' => time() - $_SERVER['REQUEST_TIME']
68+
'uptime' => time() - $_SERVER['REQUEST_TIME'],
5869
];
5970
}
6071

6172
/**
62-
* Configuration resource
73+
* Configuration resource.
6374
*/
6475
#[McpResource(
6576
uri: 'config://app/settings',
@@ -73,12 +84,12 @@ public function getAppConfig(): array
7384
'debug' => $_SERVER['DEBUG'] ?? false,
7485
'environment' => $_SERVER['APP_ENV'] ?? 'production',
7586
'timezone' => date_default_timezone_get(),
76-
'locale' => 'en_US'
87+
'locale' => 'en_US',
7788
];
7889
}
7990

8091
/**
81-
* Greeting prompt
92+
* Greeting prompt.
8293
*/
8394
#[McpPrompt(
8495
name: 'greet',
@@ -90,12 +101,12 @@ public function greetPrompt(string $firstName = 'World', string $timeOfDay = 'da
90101
'morning' => 'Good morning',
91102
'afternoon' => 'Good afternoon',
92103
'evening', 'night' => 'Good evening',
93-
default => 'Hello'
104+
default => 'Hello',
94105
};
95106

96107
return [
97108
'role' => 'user',
98-
'content' => "# {$greeting}, {$firstName}!\n\nWelcome to our MCP HTTP Server example. This demonstrates how to use the Model Context Protocol over HTTP transport."
109+
'content' => "# {$greeting}, {$firstName}!\n\nWelcome to our MCP HTTP Server example. This demonstrates how to use the Model Context Protocol over HTTP transport.",
99110
];
100111
}
101112
}

examples/10-simple-http-transport/server.php

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
<?php
22

3-
require_once dirname(__DIR__) . '/bootstrap.php';
3+
/*
4+
* This file is part of the official PHP MCP SDK.
5+
*
6+
* A collaboration between Symfony and the PHP Foundation.
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
require_once dirname(__DIR__).'/bootstrap.php';
413
chdir(__DIR__);
514

15+
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
616
use Mcp\Server;
17+
use Mcp\Server\Session\FileSessionStore;
718
use Mcp\Server\Transport\StreamableHttpTransport;
819
use Nyholm\Psr7\Factory\Psr17Factory;
920
use Nyholm\Psr7Server\ServerRequestCreator;
10-
use Laminas\HttpHandlerRunner\Emitter\SapiEmitter;
11-
use Mcp\Server\Session\FileSessionStore;
1221

1322
$psr17Factory = new Psr17Factory();
1423
$creator = new ServerRequestCreator($psr17Factory, $psr17Factory, $psr17Factory, $psr17Factory);
@@ -18,7 +27,7 @@
1827
$server = Server::make()
1928
->setServerInfo('HTTP MCP Server', '1.0.0', 'MCP Server over HTTP transport')
2029
->setContainer(container())
21-
->setSession(new FileSessionStore(__DIR__ . '/sessions'))
30+
->setSession(new FileSessionStore(__DIR__.'/sessions'))
2231
->setDiscovery(__DIR__, ['.'])
2332
->build();
2433

src/JsonRpc/Handler.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,16 @@
2424
use Mcp\Schema\JsonRpc\Error;
2525
use Mcp\Schema\JsonRpc\HasMethodInterface;
2626
use Mcp\Schema\JsonRpc\Response;
27+
use Mcp\Schema\Request\InitializeRequest;
2728
use Mcp\Server\MethodHandlerInterface;
28-
use Mcp\Server\Session\SessionInterface;
2929
use Mcp\Server\NotificationHandler;
3030
use Mcp\Server\RequestHandler;
3131
use Mcp\Server\Session\SessionFactoryInterface;
32+
use Mcp\Server\Session\SessionInterface;
3233
use Mcp\Server\Session\SessionStoreInterface;
33-
use Mcp\Schema\Request\InitializeRequest;
34-
use Symfony\Component\Uid\Uuid;
3534
use Psr\Log\LoggerInterface;
3635
use Psr\Log\NullLogger;
36+
use Symfony\Component\Uid\Uuid;
3737

3838
/**
3939
* @final
@@ -126,16 +126,18 @@ public function process(string $input, ?Uuid $sessionId): iterable
126126

127127
if ($hasInitializeRequest) {
128128
// Spec: An initialize request must not be part of a batch.
129-
if (count($messages) > 1) {
129+
if (\count($messages) > 1) {
130130
$error = Error::forInvalidRequest('The "initialize" request MUST NOT be part of a batch.');
131131
yield [$this->encodeResponse($error), []];
132+
132133
return;
133134
}
134135

135136
// Spec: An initialize request must not have a session ID.
136137
if ($sessionId) {
137138
$error = Error::forInvalidRequest('A session ID MUST NOT be sent with an "initialize" request.');
138139
yield [$this->encodeResponse($error), []];
140+
139141
return;
140142
}
141143

@@ -144,12 +146,14 @@ public function process(string $input, ?Uuid $sessionId): iterable
144146
if (!$sessionId) {
145147
$error = Error::forInvalidRequest('A valid session id is REQUIRED for non-initialize requests.');
146148
yield [$this->encodeResponse($error), ['status_code' => 400]];
149+
147150
return;
148151
}
149152

150153
if (!$this->sessionStore->exists($sessionId)) {
151154
$error = Error::forInvalidRequest('Session not found or has expired.');
152155
yield [$this->encodeResponse($error), ['status_code' => 404]];
156+
153157
return;
154158
}
155159

@@ -169,8 +173,8 @@ public function process(string $input, ?Uuid $sessionId): iterable
169173
]);
170174

171175
try {
172-
$response = $this->encodeResponse($this->handle($message, $session));
173-
yield [$response, ['session_id' => $session->getId()]];
176+
$response = $this->handle($message, $session);
177+
yield [$this->encodeResponse($response), ['session_id' => $session->getId()]];
174178
} catch (\DomainException) {
175179
yield [null, []];
176180
} catch (NotFoundExceptionInterface $e) {
@@ -268,8 +272,8 @@ private function runGarbageCollection(): void
268272
$deletedSessions = $this->sessionStore->gc();
269273
if (!empty($deletedSessions)) {
270274
$this->logger->debug('Garbage collected expired sessions.', [
271-
'count' => count($deletedSessions),
272-
'session_ids' => array_map(fn(Uuid $id) => $id->toRfc4122(), $deletedSessions),
275+
'count' => \count($deletedSessions),
276+
'session_ids' => array_map(fn (Uuid $id) => $id->toRfc4122(), $deletedSessions),
273277
]);
274278
}
275279
}

src/Server.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ final class Server
2727
public function __construct(
2828
private readonly Handler $jsonRpcHandler,
2929
private readonly LoggerInterface $logger = new NullLogger(),
30-
) {}
30+
) {
31+
}
3132

3233
public static function make(): ServerBuilder
3334
{

src/Server/NativeClock.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,23 @@
22

33
declare(strict_types=1);
44

5+
/*
6+
* This file is part of the official PHP MCP SDK.
7+
*
8+
* A collaboration between Symfony and the PHP Foundation.
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
514
namespace Mcp\Server;
615

716
use Psr\Clock\ClockInterface;
8-
use DateTimeImmutable;
917

1018
class NativeClock implements ClockInterface
1119
{
12-
public function now(): DateTimeImmutable
20+
public function now(): \DateTimeImmutable
1321
{
14-
return new DateTimeImmutable();
22+
return new \DateTimeImmutable();
1523
}
1624
}

src/Server/RequestHandler/CallToolHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ final class CallToolHandler implements MethodHandlerInterface
3131
public function __construct(
3232
private readonly ToolCallerInterface $toolCaller,
3333
private readonly LoggerInterface $logger = new NullLogger(),
34-
) {}
34+
) {
35+
}
3536

3637
public function supports(HasMethodInterface $message): bool
3738
{

src/Server/RequestHandler/GetPromptHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ final class GetPromptHandler implements MethodHandlerInterface
2727
{
2828
public function __construct(
2929
private readonly PromptGetterInterface $promptGetter,
30-
) {}
30+
) {
31+
}
3132

3233
public function supports(HasMethodInterface $message): bool
3334
{

src/Server/RequestHandler/InitializeHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ final class InitializeHandler implements MethodHandlerInterface
2828
public function __construct(
2929
public readonly ?ServerCapabilities $capabilities = new ServerCapabilities(),
3030
public readonly ?Implementation $serverInfo = new Implementation(),
31-
) {}
31+
) {
32+
}
3233

3334
public function supports(HasMethodInterface $message): bool
3435
{

src/Server/RequestHandler/ListPromptsHandler.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,8 @@ final class ListPromptsHandler implements MethodHandlerInterface
2727
public function __construct(
2828
private readonly ReferenceProviderInterface $registry,
2929
private readonly int $pageSize = 20,
30-
) {}
30+
) {
31+
}
3132

3233
public function supports(HasMethodInterface $message): bool
3334
{

0 commit comments

Comments
 (0)