Skip to content

Commit ec01d9a

Browse files
committed
# This is a combination of 2 commits.
# This is the 1st commit message: feat: Add output schema support to MCP
1 parent 30c1edb commit ec01d9a

File tree

36 files changed

+397
-36
lines changed

36 files changed

+397
-36
lines changed

src/Capability/Registry/ToolReference.php

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,23 @@ public function extractStructuredContent(mixed $toolExecutionResult): ?array
131131
return ['result' => $this->normalizeValue($toolExecutionResult)];
132132
}
133133

134-
if (isset($outputSchema['properties']) || isset($outputSchema['additionalProperties'])) {
134+
if (isset($outputSchema['additionalProperties'])) {
135+
if (\is_array($toolExecutionResult)) {
136+
// Check if it's a numeric array (list)
137+
if (array_is_list($toolExecutionResult)) {
138+
// Wrap list in "object" schema
139+
return ['items' => $toolExecutionResult];
140+
}
141+
142+
return $toolExecutionResult;
143+
}
144+
145+
if (\is_object($toolExecutionResult) && !($toolExecutionResult instanceof Content)) {
146+
return $this->normalizeValue($toolExecutionResult);
147+
}
148+
}
149+
150+
if (isset($outputSchema['properties'])) {
135151
if (\is_array($toolExecutionResult)) {
136152
return $toolExecutionResult;
137153
}

tests/Inspector/Http/snapshots/HttpCombinedRegistrationTest-tools_call-discovered_status_check.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,8 @@
55
"text": "System status: OK (discovered)"
66
}
77
],
8-
"isError": false
8+
"isError": false,
9+
"structuredContent": {
10+
"result": "System status: OK (discovered)"
11+
}
912
}

tests/Inspector/Http/snapshots/HttpCombinedRegistrationTest-tools_list.json

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,18 @@
2222
"inputSchema": {
2323
"type": "object",
2424
"properties": {}
25+
},
26+
"outputSchema": {
27+
"type": "object",
28+
"properties": {
29+
"result": {
30+
"type": "string"
31+
}
32+
},
33+
"required": [
34+
"result"
35+
],
36+
"description": "a status message"
2537
}
2638
}
2739
]

tests/Inspector/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_all_day_reminder.json

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,18 @@
55
"text": "{\n \"success\": true,\n \"message\": \"Event \\\"Project Deadline\\\" scheduled successfully for \\\"2024-12-15\\\".\",\n \"event_details\": {\n \"title\": \"Project Deadline\",\n \"date\": \"2024-12-15\",\n \"type\": \"reminder\",\n \"time\": \"All day\",\n \"priority\": \"Normal\",\n \"attendees\": [],\n \"invites_will_be_sent\": false\n }\n}"
66
}
77
],
8-
"isError": false
8+
"isError": false,
9+
"structuredContent": {
10+
"success": true,
11+
"message": "Event \"Project Deadline\" scheduled successfully for \"2024-12-15\".",
12+
"event_details": {
13+
"title": "Project Deadline",
14+
"date": "2024-12-15",
15+
"type": "reminder",
16+
"time": "All day",
17+
"priority": "Normal",
18+
"attendees": [],
19+
"invites_will_be_sent": false
20+
}
21+
}
922
}

tests/Inspector/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_high_priority.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,20 @@
55
"text": "{\n \"success\": true,\n \"message\": \"Event \\\"Client Call\\\" scheduled successfully for \\\"2024-12-02\\\".\",\n \"event_details\": {\n \"title\": \"Client Call\",\n \"date\": \"2024-12-02\",\n \"type\": \"call\",\n \"time\": \"14:30\",\n \"priority\": \"Normal\",\n \"attendees\": [\n \"[email protected]\"\n ],\n \"invites_will_be_sent\": false\n }\n}"
66
}
77
],
8-
"isError": false
8+
"isError": false,
9+
"structuredContent": {
10+
"success": true,
11+
"message": "Event \"Client Call\" scheduled successfully for \"2024-12-02\".",
12+
"event_details": {
13+
"title": "Client Call",
14+
"date": "2024-12-02",
15+
"type": "call",
16+
"time": "14:30",
17+
"priority": "Normal",
18+
"attendees": [
19+
20+
],
21+
"invites_will_be_sent": false
22+
}
23+
}
924
}

tests/Inspector/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_low_priority.json

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,20 @@
55
"text": "{\n \"success\": true,\n \"message\": \"Event \\\"Office Party\\\" scheduled successfully for \\\"2024-12-20\\\".\",\n \"event_details\": {\n \"title\": \"Office Party\",\n \"date\": \"2024-12-20\",\n \"type\": \"other\",\n \"time\": \"18:00\",\n \"priority\": \"Normal\",\n \"attendees\": [\n \"[email protected]\"\n ],\n \"invites_will_be_sent\": true\n }\n}"
66
}
77
],
8-
"isError": false
8+
"isError": false,
9+
"structuredContent": {
10+
"success": true,
11+
"message": "Event \"Office Party\" scheduled successfully for \"2024-12-20\".",
12+
"event_details": {
13+
"title": "Office Party",
14+
"date": "2024-12-20",
15+
"type": "other",
16+
"time": "18:00",
17+
"priority": "Normal",
18+
"attendees": [
19+
20+
],
21+
"invites_will_be_sent": true
22+
}
23+
}
924
}

tests/Inspector/Http/snapshots/HttpComplexToolSchemaTest-tools_call-schedule_event_meeting_with_time.json

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,21 @@
55
"text": "{\n \"success\": true,\n \"message\": \"Event \\\"Team Standup\\\" scheduled successfully for \\\"2024-12-01\\\".\",\n \"event_details\": {\n \"title\": \"Team Standup\",\n \"date\": \"2024-12-01\",\n \"type\": \"meeting\",\n \"time\": \"09:00\",\n \"priority\": \"Normal\",\n \"attendees\": [\n \"[email protected]\",\n \"[email protected]\"\n ],\n \"invites_will_be_sent\": true\n }\n}"
66
}
77
],
8-
"isError": false
8+
"isError": false,
9+
"structuredContent": {
10+
"success": true,
11+
"message": "Event \"Team Standup\" scheduled successfully for \"2024-12-01\".",
12+
"event_details": {
13+
"title": "Team Standup",
14+
"date": "2024-12-01",
15+
"type": "meeting",
16+
"time": "09:00",
17+
"priority": "Normal",
18+
"attendees": [
19+
20+
21+
],
22+
"invites_will_be_sent": true
23+
}
24+
}
925
}

tests/Inspector/Http/snapshots/HttpComplexToolSchemaTest-tools_list.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
"date",
6262
"type"
6363
]
64+
},
65+
"outputSchema": {
66+
"type": "object",
67+
"additionalProperties": true,
68+
"description": "confirmation of the scheduled event"
6469
}
6570
}
6671
]

tests/Inspector/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-send_welcome.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"text": "{\n \"success\": true,\n \"message_sent\": \"Welcome, Alice! Welcome to our platform!\"\n}"
66
}
77
],
8-
"isError": false
8+
"isError": false,
9+
"structuredContent": {
10+
"success": true,
11+
"message_sent": "Welcome, Alice! Welcome to our platform!"
12+
}
913
}

tests/Inspector/Http/snapshots/HttpDiscoveryUserProfileTest-tools_call-test_tool_without_params.json

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,9 @@
55
"text": "{\n \"success\": true,\n \"message\": \"Test tool without params\"\n}"
66
}
77
],
8-
"isError": false
8+
"isError": false,
9+
"structuredContent": {
10+
"success": true,
11+
"message": "Test tool without params"
12+
}
913
}

0 commit comments

Comments
 (0)