Move examples to server directory (#198)
* move examples to server directory This will prepare for the client implementation in https://github.com/modelcontextprotocol/php-sdk/pull/192 * fix move bootstrap too
This commit is contained in:
parent
c3244fcdd4
commit
6dac6f3b4a
4 changed files with 56 additions and 56 deletions
72
examples/server/complex-tool-schema/McpEventScheduler.php
Normal file
72
examples/server/complex-tool-schema/McpEventScheduler.php
Normal file
|
|
@ -0,0 +1,72 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the official PHP MCP SDK.
|
||||
*
|
||||
* A collaboration between Symfony and the PHP Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mcp\Example\Server\ComplexToolSchema;
|
||||
|
||||
use Mcp\Capability\Attribute\McpTool;
|
||||
use Mcp\Example\Server\ComplexToolSchema\Model\EventPriority;
|
||||
use Mcp\Example\Server\ComplexToolSchema\Model\EventType;
|
||||
use Psr\Log\LoggerInterface;
|
||||
|
||||
final class McpEventScheduler
|
||||
{
|
||||
public function __construct(
|
||||
private readonly LoggerInterface $logger,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Schedules a new event.
|
||||
* The inputSchema for this tool will reflect all parameter types and defaults.
|
||||
*
|
||||
* @param string $title the title of the event
|
||||
* @param string $date the date of the event (YYYY-MM-DD)
|
||||
* @param EventType $type the type of event
|
||||
* @param string|null $time the time of the event (HH:MM), optional
|
||||
* @param EventPriority $priority The priority of the event. Defaults to Normal.
|
||||
* @param string[]|null $attendees an optional list of attendee email addresses
|
||||
* @param bool $sendInvites send calendar invites to attendees? Defaults to true if attendees are provided
|
||||
*
|
||||
* @return array<string, mixed> confirmation of the scheduled event
|
||||
*/
|
||||
#[McpTool(name: 'schedule_event')]
|
||||
public function scheduleEvent(
|
||||
string $title,
|
||||
string $date,
|
||||
EventType $type,
|
||||
?string $time = null,
|
||||
EventPriority $priority = EventPriority::Normal,
|
||||
?array $attendees = null,
|
||||
bool $sendInvites = true,
|
||||
): array {
|
||||
$this->logger->info("Tool 'schedule_event' called", compact('title', 'date', 'type', 'time', 'priority', 'attendees', 'sendInvites'));
|
||||
|
||||
// Simulate scheduling logic
|
||||
$eventDetails = [
|
||||
'title' => $title,
|
||||
'date' => $date,
|
||||
'type' => $type->value, // Use enum value
|
||||
'time' => $time ?? 'All day',
|
||||
'priority' => $priority->name, // Use enum name
|
||||
'attendees' => $attendees ?? [],
|
||||
'invites_will_be_sent' => ($attendees && $sendInvites),
|
||||
];
|
||||
|
||||
// In a real app, this would interact with a calendar service
|
||||
$this->logger->info('Event scheduled', ['details' => $eventDetails]);
|
||||
|
||||
return [
|
||||
'success' => true,
|
||||
'message' => \sprintf('Event "%s" scheduled successfully for "%s".', $title, $date),
|
||||
'event_details' => $eventDetails,
|
||||
];
|
||||
}
|
||||
}
|
||||
19
examples/server/complex-tool-schema/Model/EventPriority.php
Normal file
19
examples/server/complex-tool-schema/Model/EventPriority.php
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the official PHP MCP SDK.
|
||||
*
|
||||
* A collaboration between Symfony and the PHP Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mcp\Example\Server\ComplexToolSchema\Model;
|
||||
|
||||
enum EventPriority: int
|
||||
{
|
||||
case Low = 0;
|
||||
case Normal = 1;
|
||||
case High = 2;
|
||||
}
|
||||
20
examples/server/complex-tool-schema/Model/EventType.php
Normal file
20
examples/server/complex-tool-schema/Model/EventType.php
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the official PHP MCP SDK.
|
||||
*
|
||||
* A collaboration between Symfony and the PHP Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Mcp\Example\Server\ComplexToolSchema\Model;
|
||||
|
||||
enum EventType: string
|
||||
{
|
||||
case Meeting = 'meeting';
|
||||
case Reminder = 'reminder';
|
||||
case Call = 'call';
|
||||
case Other = 'other';
|
||||
}
|
||||
29
examples/server/complex-tool-schema/server.php
Normal file
29
examples/server/complex-tool-schema/server.php
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
#!/usr/bin/env php
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the official PHP MCP SDK.
|
||||
*
|
||||
* A collaboration between Symfony and the PHP Foundation.
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
require_once dirname(__DIR__).'/bootstrap.php';
|
||||
chdir(__DIR__);
|
||||
|
||||
use Mcp\Server;
|
||||
use Mcp\Server\Session\FileSessionStore;
|
||||
|
||||
$server = Server::builder()
|
||||
->setServerInfo('Event Scheduler Server', '1.0.0')
|
||||
->setLogger(logger())
|
||||
->setContainer(container())
|
||||
->setSession(new FileSessionStore(__DIR__.'/sessions'))
|
||||
->setDiscovery(__DIR__)
|
||||
->build();
|
||||
|
||||
$response = $server->run(transport());
|
||||
|
||||
shutdown($response);
|
||||
Loading…
Reference in a new issue