Skip to content

Commit a41b174

Browse files
authored
Merge pull request #524 from modelcontextprotocol/ihrpr/output-types
Make content in Tool Result required
2 parents 281cf0b + 7636c63 commit a41b174

9 files changed

+96
-340
lines changed

src/examples/client/parallelToolCallsClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ async function main(): Promise<void> {
6161
// Log the results from each tool call
6262
for (const [caller, result] of Object.entries(toolResults)) {
6363
console.log(`\n=== Tool result for ${caller} ===`);
64-
result.content?.forEach((item: { type: string; text?: string; }) => {
64+
result.content.forEach((item: { type: string; text?: string; }) => {
6565
if (item.type === 'text') {
6666
console.log(` ${item.text}`);
6767
} else {

src/examples/client/simpleStreamableHttp.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -264,12 +264,12 @@ async function terminateSession(): Promise<void> {
264264
console.log('Terminating session with ID:', transport.sessionId);
265265
await transport.terminateSession();
266266
console.log('Session terminated successfully');
267-
267+
268268
// Check if sessionId was cleared after termination
269269
if (!transport.sessionId) {
270270
console.log('Session ID has been cleared');
271271
sessionId = undefined;
272-
272+
273273
// Also close the transport and clear client objects
274274
await transport.close();
275275
console.log('Transport closed after session termination');
@@ -341,7 +341,7 @@ async function callTool(name: string, args: Record<string, unknown>): Promise<vo
341341
});
342342

343343
console.log('Tool result:');
344-
result.content?.forEach(item => {
344+
result.content.forEach(item => {
345345
if (item.type === 'text') {
346346
console.log(` ${item.text}`);
347347
} else {
@@ -456,7 +456,7 @@ async function cleanup(): Promise<void> {
456456
console.error('Error terminating session:', error);
457457
}
458458
}
459-
459+
460460
// Then close the transport
461461
await transport.close();
462462
} catch (error) {

src/examples/client/streamableHttpWithSseFallbackClient.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ async function startNotificationTool(client: Client): Promise<void> {
173173
const result = await client.request(request, CallToolResultSchema);
174174

175175
console.log('Tool result:');
176-
result.content?.forEach(item => {
176+
result.content.forEach(item => {
177177
if (item.type === 'text') {
178178
console.log(` ${item.text}`);
179179
} else {

src/examples/client/testOutputSchemaServers.ts

Lines changed: 0 additions & 89 deletions
This file was deleted.

src/examples/server/lowLevelOutputSchema.ts

Lines changed: 0 additions & 116 deletions
This file was deleted.

src/examples/server/mcpServerOutputSchema.ts

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ server.registerTool(
2020
"get_weather",
2121
{
2222
description: "Get weather information for a city",
23-
inputSchema:{
23+
inputSchema: {
2424
city: z.string().describe("City name"),
2525
country: z.string().describe("Country code (e.g., US, UK)")
2626
},
@@ -45,20 +45,26 @@ server.registerTool(
4545
const temp_c = Math.round((Math.random() * 35 - 5) * 10) / 10;
4646
const conditions = ["sunny", "cloudy", "rainy", "stormy", "snowy"][Math.floor(Math.random() * 5)];
4747

48-
return {
49-
structuredContent: {
50-
temperature: {
51-
celsius: temp_c,
52-
fahrenheit: Math.round((temp_c * 9/5 + 32) * 10) / 10
53-
},
54-
conditions,
55-
humidity: Math.round(Math.random() * 100),
56-
wind: {
57-
speed_kmh: Math.round(Math.random() * 50),
58-
direction: ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(Math.random() * 8)]
59-
}
48+
const structuredContent = {
49+
temperature: {
50+
celsius: temp_c,
51+
fahrenheit: Math.round((temp_c * 9 / 5 + 32) * 10) / 10
52+
},
53+
conditions,
54+
humidity: Math.round(Math.random() * 100),
55+
wind: {
56+
speed_kmh: Math.round(Math.random() * 50),
57+
direction: ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(Math.random() * 8)]
6058
}
6159
};
60+
61+
return {
62+
content: [{
63+
type: "text",
64+
text: JSON.stringify(structuredContent, null, 2)
65+
}],
66+
structuredContent
67+
};
6268
}
6369
);
6470

0 commit comments

Comments
 (0)