Skip to content

Commit e47dc45

Browse files
klapaudiusgithub-actions[bot]
authored andcommitted
Fix styling
1 parent 40fd414 commit e47dc45

22 files changed

+225
-222
lines changed

src/Command/MigrateToolSchemaCommand.php

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ protected function configure(): void
2525
$this
2626
->addArgument('class', InputArgument::REQUIRED, 'The fully qualified class name of the tool to migrate')
2727
->addOption('dry-run', null, InputOption::VALUE_NONE, 'Show what would be changed without modifying files')
28-
->addOption('backup', null, InputOption::VALUE_NONE, 'Create a backup of the original file')
29-
;
28+
->addOption('backup', null, InputOption::VALUE_NONE, 'Create a backup of the original file');
3029
}
3130

3231
protected function execute(InputInterface $input, OutputInterface $output): int
@@ -38,14 +37,14 @@ protected function execute(InputInterface $input, OutputInterface $output): int
3837
$backup = $input->getOption('backup');
3938

4039
// Validate class exists
41-
if (!class_exists($className)) {
40+
if (! class_exists($className)) {
4241
throw new Exception(sprintf('Class "%s" not found', $className));
4342
}
4443

4544
$reflection = new \ReflectionClass($className);
4645
$filePath = $reflection->getFileName();
4746

48-
if (!$filePath) {
47+
if (! $filePath) {
4948
throw new Exception('Could not determine file path for class');
5049
}
5150

@@ -71,7 +70,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
7170
$instance = $reflection->newInstance();
7271
$currentSchema = $instance->getInputSchema();
7372

74-
if (!is_array($currentSchema)) {
73+
if (! is_array($currentSchema)) {
7574
throw new Exception('getInputSchema does not return an array. Already migrated?');
7675
}
7776

@@ -88,12 +87,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int
8887

8988
if ($dryRun) {
9089
$io->success('Dry run completed. No files were modified.');
90+
9191
return Command::SUCCESS;
9292
}
9393

9494
// Create backup if requested
9595
if ($backup) {
96-
$backupPath = $filePath . '.bak';
96+
$backupPath = $filePath.'.bak';
9797
copy($filePath, $backupPath);
9898
$io->text(sprintf('Backup created: %s', $backupPath));
9999
}
@@ -114,6 +114,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
114114
return Command::SUCCESS;
115115
} catch (\Throwable $e) {
116116
$io->error($e->getMessage());
117+
117118
return Command::FAILURE;
118119
}
119120
}
@@ -134,7 +135,7 @@ private function generateStructuredSchemaMethod(array $schema): string
134135

135136
$code .= implode(",\n", $propertyLines);
136137
$code .= "\n );\n";
137-
$code .= " }";
138+
$code .= ' }';
138139

139140
return $code;
140141
}
@@ -158,7 +159,7 @@ private function generateSchemaProperty(string $name, array $config, bool $requi
158159
}
159160

160161
$code .= sprintf(" required: %s\n", $required ? 'true' : 'false');
161-
$code .= " )";
162+
$code .= ' )';
162163

163164
return $code;
164165
}
@@ -177,13 +178,13 @@ private function generateUseStatements(string $content): string
177178
$statements = [];
178179

179180
// Check if these use statements already exist
180-
if (!str_contains($content, 'use KLP\KlpMcpServer\Services\ToolService\Schema\StructuredSchema;')) {
181+
if (! str_contains($content, 'use KLP\KlpMcpServer\Services\ToolService\Schema\StructuredSchema;')) {
181182
$statements[] = 'use KLP\KlpMcpServer\Services\ToolService\Schema\StructuredSchema;';
182183
}
183-
if (!str_contains($content, 'use KLP\KlpMcpServer\Services\ToolService\Schema\SchemaProperty;')) {
184+
if (! str_contains($content, 'use KLP\KlpMcpServer\Services\ToolService\Schema\SchemaProperty;')) {
184185
$statements[] = 'use KLP\KlpMcpServer\Services\ToolService\Schema\SchemaProperty;';
185186
}
186-
if (!str_contains($content, 'use KLP\KlpMcpServer\Services\ToolService\Schema\PropertyType;')) {
187+
if (! str_contains($content, 'use KLP\KlpMcpServer\Services\ToolService\Schema\PropertyType;')) {
187188
$statements[] = 'use KLP\KlpMcpServer\Services\ToolService\Schema\PropertyType;';
188189
}
189190

@@ -195,16 +196,17 @@ private function migrateContent(string $content, string $useStatements, string $
195196
// Add use statements after namespace
196197
if ($useStatements) {
197198
$pattern = '/(namespace [^;]+;)/';
198-
$replacement = "$1\n\n" . $useStatements;
199+
$replacement = "$1\n\n".$useStatements;
199200
$content = preg_replace($pattern, $replacement, $content, 1);
200201
}
201202

202203
// Replace the getInputSchema method
203204
$pattern = '/public function getInputSchema\(\):\s*array\s*\{[^}]*\}(\s*\})?/s';
204-
$content = preg_replace_callback($pattern, function($matches) use ($newMethod) {
205+
$content = preg_replace_callback($pattern, function ($matches) use ($newMethod) {
205206
// Check if we matched a nested closing brace
206207
$extraBrace = isset($matches[1]) ? $matches[1] : '';
207-
return $newMethod . $extraBrace;
208+
209+
return $newMethod.$extraBrace;
208210
}, $content);
209211

210212
// Update the return type hint in interface implementations

src/Controllers/StreamableHttpController.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,10 @@ public function postHandle(Request $request): StreamedResponse|JsonResponse
5454

5555
try {
5656
$input = json_decode($request->getContent(), true, flags: JSON_THROW_ON_ERROR);
57-
$this->logger?->debug('Received message from clientId:' . $clientId, ['message' => $input]);
57+
$this->logger?->debug('Received message from clientId:'.$clientId, ['message' => $input]);
5858

5959
// Batch request MUST NOT be handled unless the protocol version is 2025-03-26
60-
if ( $mcpProtocolVersion === MCPProtocolInterface::PROTOCOL_SECOND_VERSION ) {
60+
if ($mcpProtocolVersion === MCPProtocolInterface::PROTOCOL_SECOND_VERSION) {
6161
return $this->handleBatchableInput($clientId, $input);
6262
} else {
6363
return $this->handleInput($clientId, $input);
@@ -67,14 +67,14 @@ public function postHandle(Request $request): StreamedResponse|JsonResponse
6767

6868
return new JsonResponse(['jsonrpc' => 2.0, 'error' => ['code' => -32700, 'message' => $message]], 400);
6969
}
70-
}catch (InvalidArgumentException $e) {
70+
} catch (InvalidArgumentException $e) {
7171
return new JsonResponse(['jsonrpc' => 2.0, 'error' => ['code' => -32600, 'message' => $e->getMessage()]], 400);
7272
}
7373
}
7474

7575
private function handleBatchableInput(string $clientId, mixed $input): StreamedResponse
7676
{
77-
$willStream = !isset($input['jsonrpc']) && isset($input[0]['jsonrpc']);
77+
$willStream = ! isset($input['jsonrpc']) && isset($input[0]['jsonrpc']);
7878
$messages = $willStream ? $input : [$input];
7979

8080
return new StreamedResponse(function () use ($clientId, $messages) {

src/Protocol/MCPProtocol.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,8 @@ public function setProtocolVersion(string $version): void
334334
* Configures the appropriate transport instance based on the provided version
335335
* and assigns handlers for messages, requests, and notifications.
336336
*
337-
* @param string $version The version identifier used to initialize the transport.
337+
* @param string $version The version identifier used to initialize the transport.
338+
*
338339
* @throws \InvalidArgumentException If the protocol version is not supported.
339340
*/
340341
private function initTransport(string $version)

src/Protocol/MCPProtocolInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
*/
1717
interface MCPProtocolInterface
1818
{
19-
2019
public const PROTOCOL_FIRST_VERSION = '2024-11-05';
20+
2121
public const PROTOCOL_SECOND_VERSION = '2025-03-26';
22+
2223
public const PROTOCOL_THIRD_VERSION = '2025-06-18';
2324

2425
/**
@@ -32,7 +33,6 @@ interface MCPProtocolInterface
3233
public const PROTOCOL_VERSION_STREAMABE_HTTP = self::PROTOCOL_SECOND_VERSION;
3334

3435
/**
35-
* @param string $version
3636
* @throws \InvalidArgumentException If the protocol version is not supported.
3737
*/
3838
public function setProtocolVersion(string $version): void;

src/Server/MCPServer.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,6 @@ public function getClientId(): string
299299
}
300300

301301
/**
302-
* @param string $protocolVersion
303302
* @throws \InvalidArgumentException If the protocol version is not supported.
304303
*/
305304
public function setProtocolVersion(string $protocolVersion): void

src/Services/ToolService/BaseToolInterface.php

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,15 @@ public function getDescription(): string;
3636
* for validation and to provide type hints to LLM clients.
3737
*
3838
* @return StructuredSchema|array The JSON Schema as an associative array. Common structure:
39-
* [
40-
* 'type' => 'object',
41-
* 'properties' => [
42-
* 'param' => ['type' => 'string', 'description' => '...'],
43-
* ],
44-
* 'required' => ['param'],
45-
* ]
46-
* For tools with no parameters, use ['type' => 'object', 'properties' => new \stdClass].
39+
* [
40+
* 'type' => 'object',
41+
* 'properties' => [
42+
* 'param' => ['type' => 'string', 'description' => '...'],
43+
* ],
44+
* 'required' => ['param'],
45+
* ]
46+
* For tools with no parameters, use ['type' => 'object', 'properties' => new \stdClass].
47+
*
4748
* @todo Remove the array type hint on v2.0.0.
4849
*/
4950
public function getInputSchema(): StructuredSchema|array;
@@ -58,7 +59,9 @@ public function getInputSchema(): StructuredSchema|array;
5859
* @return StructuredSchema|null The JSON Schema for the tool's output, or null if the tool
5960
* doesn't provide a structured output schema. When provided,
6061
* this schema helps with type safety and output validation.
62+
*
6163
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools
64+
*
6265
* @todo Uncomment the new method on v2.0.0.
6366
*/
6467
// public function getOutputSchema(): ?StructuredSchema;
@@ -74,6 +77,7 @@ public function getInputSchema(): StructuredSchema|array;
7477
* - destructiveHint: true if the tool may perform destructive updates
7578
* - idempotentHint: true if repeated calls have no additional effect
7679
* - openWorldHint: true if the tool may interact with external entities
80+
*
7781
* @see https://modelcontextprotocol.io/specification/2025-06-18/server/tools
7882
*/
7983
public function getAnnotations(): ToolAnnotation;

src/Services/ToolService/Examples/VersionCheckTool.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
use KLP\KlpMcpServer\Services\ProgressService\ProgressNotifierInterface;
66
use KLP\KlpMcpServer\Services\ToolService\Annotation\ToolAnnotation;
77
use KLP\KlpMcpServer\Services\ToolService\Result\StructuredToolResult;
8-
use KLP\KlpMcpServer\Services\ToolService\Result\TextToolResult;
98
use KLP\KlpMcpServer\Services\ToolService\Result\ToolResultInterface;
109
use KLP\KlpMcpServer\Services\ToolService\Schema\PropertyType;
1110
use KLP\KlpMcpServer\Services\ToolService\Schema\SchemaProperty;
1211
use KLP\KlpMcpServer\Services\ToolService\Schema\StructuredSchema;
1312
use KLP\KlpMcpServer\Services\ToolService\StreamableToolInterface;
14-
use stdClass;
1513
use Symfony\Component\HttpKernel\Kernel;
1614

1715
class VersionCheckTool implements StreamableToolInterface
@@ -60,7 +58,7 @@ public function execute(array $arguments): ToolResultInterface
6058
{
6159
return new StructuredToolResult([
6260
'version' => Kernel::VERSION,
63-
'date' => (new \DateTime('now'))->format('Y-m-d H:i:s')
61+
'date' => (new \DateTime('now'))->format('Y-m-d H:i:s'),
6462
]);
6563
}
6664

src/Services/ToolService/Result/StructuredToolResult.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,8 @@
1010
*/
1111
final class StructuredToolResult extends AbstractToolResult
1212
{
13-
1413
/**
1514
* The structured value to be returned.
16-
*
17-
* @var array
1815
*/
1916
private array $structuredValue;
2017

src/Services/ToolService/Schema/SchemaProperty.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,20 @@
1313
readonly class SchemaProperty
1414
{
1515
/**
16-
* @param string $name The property name as it will appear in the JSON Schema
17-
* @param PropertyType $type The JSON Schema type
18-
* @param string $description A human-readable description of the property
19-
* @param array $enum An array of allowed values for this property
20-
* @param string $default The default value for this property
21-
* @param bool $required Whether this property is required in the input schema
16+
* @param string $name The property name as it will appear in the JSON Schema
17+
* @param PropertyType $type The JSON Schema type
18+
* @param string $description A human-readable description of the property
19+
* @param array $enum An array of allowed values for this property
20+
* @param string $default The default value for this property
21+
* @param bool $required Whether this property is required in the input schema
2222
*/
2323
public function __construct(
24-
private string $name,
24+
private string $name,
2525
private PropertyType $type,
26-
private string $description = '',
27-
private array $enum = [],
28-
private string $default = '',
29-
private bool $required = false
26+
private string $description = '',
27+
private array $enum = [],
28+
private string $default = '',
29+
private bool $required = false
3030
) {}
3131

3232
/**
@@ -42,7 +42,7 @@ public function getName(): string
4242
/**
4343
* Gets the property type.
4444
*
45-
* @return PropertyType The JSON Schema type for this property
45+
* @return PropertyType The JSON Schema type for this property
4646
*/
4747
public function getType(): PropertyType
4848
{

src/Services/ToolService/Schema/StructuredSchema.php

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,10 @@ class StructuredSchema
2424
private array $properties;
2525

2626
/**
27-
* @param SchemaProperty ...$properties Variable number of schema properties that define the tool's input structure
27+
* @param SchemaProperty ...$properties Variable number of schema properties that define the tool's input structure
2828
*/
29-
public function __construct(SchemaProperty ...$properties) {
29+
public function __construct(SchemaProperty ...$properties)
30+
{
3031
$this->properties = $properties;
3132
}
3233

@@ -56,7 +57,7 @@ public function asArray(): array
5657
foreach ($this->properties as $property) {
5758
$properties[$property->getName()] = [
5859
'type' => $this->getPropertyType($property),
59-
'description' => $property->getDescription()
60+
'description' => $property->getDescription(),
6061
];
6162

6263
if ($property->isRequired()) {
@@ -66,8 +67,8 @@ public function asArray(): array
6667

6768
return [
6869
'type' => 'object',
69-
'properties' => $properties ?: new stdClass(),
70-
'required' => $required
70+
'properties' => $properties ?: new stdClass,
71+
'required' => $required,
7172
];
7273
}
7374

0 commit comments

Comments
 (0)