fix: correcting ping method response format

This commit is contained in:
BarryY 2025-05-16 15:53:35 +08:00
parent e393d9bd98
commit 9683996217
1 changed files with 17 additions and 12 deletions

View File

@ -322,10 +322,7 @@ export class StreamableHttpTransport implements MCPTransport {
} }
break; break;
case 'ping':
// Add support for heartbeat ping
result = { pong: true };
break;
case 'tools/call': case 'tools/call':
// Handle new tools/call method format // Handle new tools/call method format
@ -490,14 +487,22 @@ export class StreamableHttpTransport implements MCPTransport {
break; break;
default: default:
return res.status(400).json({ // For method 'ping' and other non-critical methods, just return an empty result
jsonrpc: '2.0', // This ensures MCP compatibility for health checks and probes
error: { if (method === 'ping') {
code: -32601, info(`Returning empty response for ping request`);
message: `Method not found: ${method}`, result = {};
}, } else {
id: req.body?.id || null, // For other unknown methods, return method not found error
}); return res.status(400).json({
jsonrpc: '2.0',
error: {
code: -32601,
message: `Method not found: ${method}`,
},
id: req.body?.id || null,
});
}
} }
info(`Request for ${method} handled successfully`); info(`Request for ${method} handled successfully`);