Skip to content

Make content in Tool Result required #524

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/examples/client/parallelToolCallsClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function main(): Promise<void> {
// Log the results from each tool call
for (const [caller, result] of Object.entries(toolResults)) {
console.log(`\n=== Tool result for ${caller} ===`);
result.content?.forEach((item: { type: string; text?: string; }) => {
result.content.forEach((item: { type: string; text?: string; }) => {
if (item.type === 'text') {
console.log(` ${item.text}`);
} else {
Expand Down
8 changes: 4 additions & 4 deletions src/examples/client/simpleStreamableHttp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,12 +264,12 @@ async function terminateSession(): Promise<void> {
console.log('Terminating session with ID:', transport.sessionId);
await transport.terminateSession();
console.log('Session terminated successfully');

// Check if sessionId was cleared after termination
if (!transport.sessionId) {
console.log('Session ID has been cleared');
sessionId = undefined;

// Also close the transport and clear client objects
await transport.close();
console.log('Transport closed after session termination');
Expand Down Expand Up @@ -341,7 +341,7 @@ async function callTool(name: string, args: Record<string, unknown>): Promise<vo
});

console.log('Tool result:');
result.content?.forEach(item => {
result.content.forEach(item => {
if (item.type === 'text') {
console.log(` ${item.text}`);
} else {
Expand Down Expand Up @@ -456,7 +456,7 @@ async function cleanup(): Promise<void> {
console.error('Error terminating session:', error);
}
}

// Then close the transport
await transport.close();
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion src/examples/client/streamableHttpWithSseFallbackClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ async function startNotificationTool(client: Client): Promise<void> {
const result = await client.request(request, CallToolResultSchema);

console.log('Tool result:');
result.content?.forEach(item => {
result.content.forEach(item => {
if (item.type === 'text') {
console.log(` ${item.text}`);
} else {
Expand Down
89 changes: 0 additions & 89 deletions src/examples/client/testOutputSchemaServers.ts

This file was deleted.

116 changes: 0 additions & 116 deletions src/examples/server/lowLevelOutputSchema.ts

This file was deleted.

32 changes: 19 additions & 13 deletions src/examples/server/mcpServerOutputSchema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ server.registerTool(
"get_weather",
{
description: "Get weather information for a city",
inputSchema:{
inputSchema: {
city: z.string().describe("City name"),
country: z.string().describe("Country code (e.g., US, UK)")
},
Expand All @@ -45,20 +45,26 @@ server.registerTool(
const temp_c = Math.round((Math.random() * 35 - 5) * 10) / 10;
const conditions = ["sunny", "cloudy", "rainy", "stormy", "snowy"][Math.floor(Math.random() * 5)];

return {
structuredContent: {
temperature: {
celsius: temp_c,
fahrenheit: Math.round((temp_c * 9/5 + 32) * 10) / 10
},
conditions,
humidity: Math.round(Math.random() * 100),
wind: {
speed_kmh: Math.round(Math.random() * 50),
direction: ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(Math.random() * 8)]
}
const structuredContent = {
temperature: {
celsius: temp_c,
fahrenheit: Math.round((temp_c * 9 / 5 + 32) * 10) / 10
},
conditions,
humidity: Math.round(Math.random() * 100),
wind: {
speed_kmh: Math.round(Math.random() * 50),
direction: ["N", "NE", "E", "SE", "S", "SW", "W", "NW"][Math.floor(Math.random() * 8)]
}
};

return {
content: [{
type: "text",
text: JSON.stringify(structuredContent, null, 2)
}],
structuredContent
};
}
);

Expand Down
Loading