UNPKG

mira-app-server

Version:

Mira Server - standalone server application using mira-app-core

39 lines 1.1 kB
"use strict"; /** * MCP 工具结果构造辅助函数 * * 工具 handler 返回 CallToolResult:成功把数据 JSON 化为 text;失败标记 isError。 */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ok = ok; exports.err = err; exports.run = run; /** 成功结果:把任意可序列化数据 JSON 化 */ function ok(data) { return { content: [{ type: 'text', text: typeof data === 'string' ? data : JSON.stringify(data, null, 2) }], }; } /** 错误结果 */ function err(message) { return { isError: true, content: [{ type: 'text', text: message }], }; } /** * 包装一个异步工具体:自动 try/catch,把 Error.message 转成 isError 结果。 * 同时把 SDK 抛出的 ErrorResponse(含 message 字段)也正确提取。 */ async function run(fn) { try { const result = await fn(); return ok(result); } catch (e) { const message = e?.message || (typeof e === 'string' ? e : '未知错误'); return err(message); } } //# sourceMappingURL=helpers.js.map