make content required
This commit is contained in:
parent
69dbfac0e4
commit
265ad071f7
4 changed files with 52 additions and 62 deletions
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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');
|
||||
|
|
@ -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 {
|
||||
|
|
@ -456,7 +456,7 @@ async function cleanup(): Promise<void> {
|
|||
console.error('Error terminating session:', error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Then close the transport
|
||||
await transport.close();
|
||||
} catch (error) {
|
||||
|
|
|
|||
|
|
@ -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 {
|
||||
|
|
|
|||
|
|
@ -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)")
|
||||
},
|
||||
|
|
@ -46,10 +46,11 @@ server.registerTool(
|
|||
const conditions = ["sunny", "cloudy", "rainy", "stormy", "snowy"][Math.floor(Math.random() * 5)];
|
||||
|
||||
return {
|
||||
content: [],
|
||||
structuredContent: {
|
||||
temperature: {
|
||||
celsius: temp_c,
|
||||
fahrenheit: Math.round((temp_c * 9/5 + 32) * 10) / 10
|
||||
fahrenheit: Math.round((temp_c * 9 / 5 + 32) * 10) / 10
|
||||
},
|
||||
conditions,
|
||||
humidity: Math.round(Math.random() * 100),
|
||||
|
|
|
|||
Loading…
Reference in a new issue