Skip to content

Commit a750197

Browse files
committed
[Examples] Show JSON object arguments in complex-tool-schema
1 parent 4ded5c4 commit a750197

5 files changed

Lines changed: 77 additions & 8 deletions

File tree

‎docs/examples.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ npx @modelcontextprotocol/inspector php examples/server/discovery-calculator/ser
2525
| [`combined-registration`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/combined-registration) | Discovery and manual registration combined, and which wins on conflict | [Registering elements](servers/registration.md) |
2626
| [`cached-discovery`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/cached-discovery) | Caching the discovery scan in a PSR-16 cache | [Server builder](run/server-builder.md#discovery-configuration) |
2727
| [`custom-dependencies`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/custom-dependencies) | Handlers pulling services from a PSR-11 container | [Server builder](run/server-builder.md#service-dependencies) |
28-
| [`complex-tool-schema`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/complex-tool-schema) | Rich input schemas from typed parameters, PHP enums and defaults | [Schema generation](servers/schemas.md) |
28+
| [`complex-tool-schema`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/complex-tool-schema) | Rich input schemas from typed parameters, PHP enums, defaults and JSON objects | [Schema generation](servers/schemas.md) |
2929
| [`schema-showcase`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/schema-showcase) | `#[Schema]` constraint attributes: formats, patterns, ranges | [Schema generation](servers/schemas.md) |
3030
| [`env-variables`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/env-variables) | Configuring a server through environment variables | [Server builder](run/server-builder.md) |
3131
| [`client-communication`](https://github.com/modelcontextprotocol/php-sdk/tree/main/examples/server/client-communication) | Sampling, roots, progress and log messages from inside a handler | [Talking back to the client](handlers/client-communication.md) |

‎examples/server/complex-tool-schema/McpEventScheduler.php‎

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,15 @@ public function __construct(
2727
* Schedules a new event.
2828
* The inputSchema for this tool will reflect all parameter types and defaults.
2929
*
30-
* @param string $title the title of the event
31-
* @param string $date the date of the event (YYYY-MM-DD)
32-
* @param EventType $type the type of event
33-
* @param string|null $time the time of the event (HH:MM), optional
34-
* @param EventPriority $priority The priority of the event. Defaults to Normal.
35-
* @param string[]|null $attendees an optional list of attendee email addresses
36-
* @param bool $sendInvites send calendar invites to attendees? Defaults to true if attendees are provided
30+
* @param string $title the title of the event
31+
* @param string $date the date of the event (YYYY-MM-DD)
32+
* @param EventType $type the type of event
33+
* @param string|null $time the time of the event (HH:MM), optional
34+
* @param EventPriority $priority The priority of the event. Defaults to Normal.
35+
* @param string[]|null $attendees an optional list of attendee email addresses
36+
* @param bool $sendInvites send calendar invites to attendees? Defaults to true if attendees are provided
37+
* @param array<string, string> $labels labels of the event by name
38+
* @param \stdClass|null $metadata free-form data stored with the event, exactly as sent
3739
*
3840
* @return array<string, mixed> confirmation of the scheduled event
3941
*/
@@ -46,6 +48,8 @@ public function scheduleEvent(
4648
EventPriority $priority = EventPriority::Normal,
4749
?array $attendees = null,
4850
bool $sendInvites = true,
51+
array $labels = [],
52+
?\stdClass $metadata = null,
4953
): array {
5054
$this->logger->info("Tool 'schedule_event' called", compact('title', 'date', 'type', 'time', 'priority', 'attendees', 'sendInvites'));
5155

@@ -60,6 +64,14 @@ public function scheduleEvent(
6064
'invites_will_be_sent' => ($attendees && $sendInvites),
6165
];
6266

67+
if ([] !== $labels) {
68+
$eventDetails['labels'] = $labels;
69+
}
70+
71+
if (null !== $metadata) {
72+
$eventDetails['metadata'] = $metadata;
73+
}
74+
6375
// In a real app, this would interact with a calendar service
6476
$this->logger->info('Event scheduled', ['details' => $eventDetails]);
6577

‎tests/Interop/Server/Http/HttpComplexToolSchemaTest.php‎

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,20 @@ public static function provideMethods(): array
7777
],
7878
'testName' => 'schedule_event_low_priority',
7979
],
80+
'Schedule Event (Labels and Metadata)' => [
81+
'method' => 'tools/call',
82+
'options' => [
83+
'toolName' => 'schedule_event',
84+
'toolArgs' => [
85+
'title' => 'Release Planning',
86+
'date' => '2024-12-10',
87+
'type' => 'meeting',
88+
'labels' => ['team' => 'platform'],
89+
'metadata' => ['source' => 'crm', 'tags' => [], 'custom' => new \stdClass()],
90+
],
91+
],
92+
'testName' => 'schedule_event_labels_and_metadata',
93+
],
8094
];
8195
}
8296

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
{
2+
"content": [
3+
{
4+
"type": "text",
5+
"text": "{\n \"success\": true,\n \"message\": \"Event \\\"Release Planning\\\" scheduled successfully for \\\"2024-12-10\\\".\",\n \"event_details\": {\n \"title\": \"Release Planning\",\n \"date\": \"2024-12-10\",\n \"type\": \"meeting\",\n \"time\": \"All day\",\n \"priority\": \"Normal\",\n \"attendees\": [],\n \"invites_will_be_sent\": false,\n \"labels\": {\n \"team\": \"platform\"\n },\n \"metadata\": {\n \"source\": \"crm\",\n \"tags\": [],\n \"custom\": {}\n }\n }\n}"
6+
}
7+
],
8+
"structuredContent": {
9+
"success": true,
10+
"message": "Event \"Release Planning\" scheduled successfully for \"2024-12-10\".",
11+
"event_details": {
12+
"title": "Release Planning",
13+
"date": "2024-12-10",
14+
"type": "meeting",
15+
"time": "All day",
16+
"priority": "Normal",
17+
"attendees": [],
18+
"invites_will_be_sent": false,
19+
"labels": {
20+
"team": "platform"
21+
},
22+
"metadata": {
23+
"source": "crm",
24+
"tags": [],
25+
"custom": {}
26+
}
27+
}
28+
},
29+
"isError": false
30+
}

‎tests/Interop/Server/Http/snapshots/HttpComplexToolSchemaTest-tools_list.json‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,19 @@
5757
"type": "boolean",
5858
"description": "send calendar invites to attendees? Defaults to true if attendees are provided",
5959
"default": true
60+
},
61+
"labels": {
62+
"type": "object",
63+
"description": "labels of the event by name",
64+
"default": {}
65+
},
66+
"metadata": {
67+
"type": [
68+
"null",
69+
"object"
70+
],
71+
"description": "free-form data stored with the event, exactly as sent",
72+
"default": null
6073
}
6174
},
6275
"required": [

0 commit comments

Comments
 (0)