Skip to content

Commit d7fdb6c

Browse files
author
CodeBuddy Attribution Bot
committed
fix(attribution): uploadFiles MCP 工具 cloudPath 参数行为不明确且缺少部署状态反馈,导致静态托管部署验证失败 (issue_mojhcq5h_2u7mxc)
1 parent e2ca73f commit d7fdb6c

1 file changed

Lines changed: 23 additions & 6 deletions

File tree

mcp/src/tools/hosting.ts

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ export function registerHostingTools(server: ExtendedMcpServer) {
261261
description: "上传文件到静态网站托管,仅用于 Web 站点部署,不用于云存储对象上传。部署前请先完成构建;如果站点会部署到子路径,请检查构建配置中的 publicPath、base、assetPrefix 等是否使用相对路径,避免静态资源加载失败。若需要上传 COS 云存储文件,请使用 manageStorage。对于本地评测、现有脚手架补全或仅需本地开发服务器验证的任务,通常不需要调用此工具,除非用户明确要求部署站点。",
262262
inputSchema: {
263263
localPath: z.string().optional().describe("本地文件或文件夹路径,需要是绝对路径,例如 /tmp/files/data.txt。"),
264-
cloudPath: z.string().optional().describe("静态托管云端文件或文件夹路径,例如 files/data.txt。若部署到子路径,请同时检查构建配置中的 publicPath、base、assetPrefix 等是否为相对路径。云存储对象路径请改用 manageStorage。"),
264+
cloudPath: z.string().optional().describe("静态托管云端文件或文件夹路径,例如 files/data.txt。不要以斜杠开头(如 /files),除非确实需要绝对路径;上传到根目录时可传空字符串或省略此参数。若部署到子路径,请同时检查构建配置中的 publicPath、base、assetPrefix 等是否为相对路径。云存储对象路径请改用 manageStorage。"),
265265
files: z.array(z.object({
266266
localPath: z.string(),
267267
cloudPath: z.string()
@@ -276,19 +276,24 @@ export function registerHostingTools(server: ExtendedMcpServer) {
276276
category: "hosting"
277277
}
278278
},
279-
async ({ localPath, cloudPath, files = [], ignore }: {
279+
async ({ localPath, cloudPath: rawCloudPath, files = [], ignore }: {
280280
localPath?: string;
281281
cloudPath?: string;
282282
files?: Array<{ localPath: string; cloudPath: string }>;
283283
ignore?: string | string[]
284284
}) => {
285285
const cloudbase = await getManager()
286+
// Normalize cloudPath: remove leading/trailing slashes to avoid double slashes in uploaded file keys
287+
const cloudPath = rawCloudPath ? rawCloudPath.trim().replace(/^\/+|\/+$/g, '') : '';
286288
let result: unknown;
287289
try {
288290
result = await cloudbase.hosting.uploadFiles({
289291
localPath,
290-
cloudPath,
291-
files,
292+
cloudPath: cloudPath || undefined,
293+
files: files.map(f => ({
294+
localPath: f.localPath,
295+
cloudPath: f.cloudPath.trim().replace(/^\/+|\/+$/g, '')
296+
})),
292297
ignore
293298
});
294299
} catch (error) {
@@ -340,15 +345,27 @@ export function registerHostingTools(server: ExtendedMcpServer) {
340345
// Error is already logged in sendDeployNotification
341346
}
342347

348+
// Build deployment status summary
349+
const uploadedFiles = (uploadResult.files as Array<{ options?: { Key?: string } }>) || [];
350+
const fileCount = uploadedFiles.length;
351+
const deploymentTarget = cloudPath ? `/${cloudPath}/` : '根目录';
352+
343353
return {
344354
content: [
345355
{
346356
type: "text",
347357
text: JSON.stringify({
348358
...uploadResult,
349359
staticDomain,
350-
message: "文件上传成功",
351-
accessUrl: accessUrl
360+
message: `部署成功:已上传 ${fileCount} 个文件到 ${deploymentTarget}`,
361+
accessUrl: accessUrl,
362+
deploymentStatus: {
363+
filesUploaded: fileCount,
364+
targetPath: cloudPath || '/',
365+
staticDomain: staticDomain,
366+
isReady: true,
367+
note: "CDN 缓存可能需要 1-3 分钟生效,如无法立即访问请稍后再试"
368+
}
352369
}, null, 2)
353370
}
354371
]

0 commit comments

Comments
 (0)