@smithery/sdk
Version:
SDK to develop with Smithery
25 lines (24 loc) • 791 B
JavaScript
import { CallToolResultSchema, } from "@modelcontextprotocol/sdk/types.js";
import { patch } from "../../shared/patch.js";
/**
* Wraps each tool call so any errors get sent back to the LLM instead of throwing
*/
export function wrapError(client) {
patch(client, "callTool", (callTool) => async (params, resultSchema = CallToolResultSchema, options) => {
try {
return await callTool(params, resultSchema, options);
}
catch (err) {
return {
content: [
{
type: "text",
text: JSON.stringify(err, Object.getOwnPropertyNames(err)),
},
],
isError: true,
};
}
});
return client;
}