cloudflare-mcp-smart-proxy 1.1.0 → 1.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package-personal.json +1 -1
- package/package.json +1 -1
- package/src/router.js +40 -2
package/package-personal.json
CHANGED
package/package.json
CHANGED
package/src/router.js
CHANGED
|
@@ -129,7 +129,24 @@ export class SmartRouter {
|
|
|
129
129
|
const result = await response.json();
|
|
130
130
|
|
|
131
131
|
if (result.error) {
|
|
132
|
-
|
|
132
|
+
// MCP 标准格式:详细错误信息在 data 字段中
|
|
133
|
+
// 如果 data 是对象,尝试提取更多信息
|
|
134
|
+
let errorMessage = result.error.data || result.error.message || 'Cloud tool execution failed';
|
|
135
|
+
|
|
136
|
+
// 如果 data 是对象,尝试提取 message 或格式化整个对象
|
|
137
|
+
if (typeof errorMessage === 'object') {
|
|
138
|
+
errorMessage = errorMessage.message || JSON.stringify(errorMessage, null, 2);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
// 记录详细错误信息用于调试
|
|
142
|
+
console.error(`[SmartRouter] Cloud tool error for ${toolName}:`, {
|
|
143
|
+
code: result.error.code,
|
|
144
|
+
message: result.error.message,
|
|
145
|
+
data: result.error.data,
|
|
146
|
+
fullError: result.error
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
throw new Error(errorMessage);
|
|
133
150
|
}
|
|
134
151
|
|
|
135
152
|
// 提取结果内容
|
|
@@ -137,7 +154,16 @@ export class SmartRouter {
|
|
|
137
154
|
// MCP 标准格式
|
|
138
155
|
const content = result.result.content;
|
|
139
156
|
if (Array.isArray(content) && content.length > 0) {
|
|
140
|
-
|
|
157
|
+
const text = content[0].text;
|
|
158
|
+
// 尝试解析 JSON 字符串,如果失败则返回原始字符串
|
|
159
|
+
try {
|
|
160
|
+
const parsed = JSON.parse(text);
|
|
161
|
+
// 如果解析成功且是对象,返回对象;否则返回原始字符串
|
|
162
|
+
return typeof parsed === 'object' && parsed !== null ? parsed : text;
|
|
163
|
+
} catch {
|
|
164
|
+
// 不是 JSON,直接返回字符串
|
|
165
|
+
return text;
|
|
166
|
+
}
|
|
141
167
|
}
|
|
142
168
|
return content;
|
|
143
169
|
} else if (result.result) {
|
|
@@ -146,6 +172,18 @@ export class SmartRouter {
|
|
|
146
172
|
return result;
|
|
147
173
|
}
|
|
148
174
|
} catch (error) {
|
|
175
|
+
// 记录完整错误信息用于调试
|
|
176
|
+
console.error(`[SmartRouter] Error calling cloud tool ${toolName}:`, {
|
|
177
|
+
error: error.message,
|
|
178
|
+
stack: error.stack,
|
|
179
|
+
params: params
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
// 如果错误信息已经包含 "Cloud tool call failed",直接抛出
|
|
183
|
+
// 否则添加前缀
|
|
184
|
+
if (error.message && error.message.includes('Cloud tool call failed')) {
|
|
185
|
+
throw error;
|
|
186
|
+
}
|
|
149
187
|
throw new Error(`Cloud tool call failed: ${error.message}`);
|
|
150
188
|
}
|
|
151
189
|
}
|