Skip to content

Commit f3c294b

Browse files
author
CodeBuddy Attribution Bot
committed
fix(attribution): uploadFiles MCP 工具 cloudPath 格式不清且缺少部署验证能力,导致静态托管部署后 404 (issue_moj04v8k_rh94tl)
1 parent e2ca73f commit f3c294b

3 files changed

Lines changed: 49 additions & 2 deletions

File tree

config/source/skills/web-development/SKILL.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,27 @@ Use this section only when the Web project needs CloudBase platform features.
132132
- Use hash routing by default when the project lacks server-side route rewrites
133133
- If the user does not specify a root path, avoid deploying directly to the site root by default
134134

135+
### Subdirectory deployment requirements
136+
137+
When deploying to a subdirectory (e.g., `/vite-test`), the `uploadFiles` tool requires specific pre-deployment checks:
138+
139+
1. **cloudPath format**: Relative to hosting root, no leading `/`
140+
- Correct: `cloudPath: 'vite-test'`
141+
- Wrong: `cloudPath: '/vite-test'` or `cloudPath: './vite-test'`
142+
143+
2. **Build configuration**: Must set `base`/`publicPath`/`assetPrefix` to match the deployment path
144+
- For Vite: `base: '/vite-test/'` (absolute path with leading and trailing slashes)
145+
- Forbidden: `base: './'` (causes 404 when URL lacks trailing slash)
146+
- See `frameworks.md` for detailed Vite base configuration guidance
147+
148+
3. **Mandatory pre-deployment checklist**:
149+
- [ ] Build config (`base`/`publicPath`/`assetPrefix`) matches deployment path
150+
- [ ] Build has been re-run after config change
151+
- [ ] Built `index.html` references assets with correct paths (not absolute root `/`)
152+
- [ ] `cloudPath` has no leading `/`
153+
154+
4. **Common 404 cause**: Using `./` relative paths in build config. When accessing `https://env.tcloudbase.com/vite-test` (no trailing slash), relative paths resolve incorrectly.
155+
135156
### CloudBase quick start
136157

137158
```js

config/source/skills/web-development/frameworks.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,32 @@
1919
- Keep environment-specific values in `.env` or the project's existing config pattern instead of hardcoding them into UI files.
2020
- Check route base paths, asset paths, and build output behavior before deployment.
2121

22+
### Vite base configuration for subdirectory deployment
23+
24+
When deploying to a subdirectory (e.g., `https://example.com/vite-test/`), the Vite `base` configuration is critical:
25+
26+
1. **Required format**: Set `base` to an absolute path with leading and trailing slashes, matching the deployment path:
27+
```js
28+
// vite.config.ts
29+
export default defineConfig({
30+
base: '/vite-test/', // Correct: absolute path with leading and trailing slashes
31+
})
32+
```
33+
34+
2. **Forbidden patterns** - These will cause 404 errors when URL lacks trailing slash:
35+
```js
36+
base: './', // WRONG: relative path breaks when URL is /vite-test (no trailing slash)
37+
base: '', // WRONG: empty base means root deployment
38+
base: 'vite-test', // WRONG: missing leading and trailing slashes
39+
```
40+
41+
3. **Why this matters**: When a user accesses `https://example.com/vite-test` (without trailing slash), relative paths like `./assets/index.js` resolve to `https://example.com/assets/index.js` instead of `https://example.com/vite-test/assets/index.js`, causing 404 errors.
42+
43+
4. **Pre-deployment checklist**:
44+
- [ ] `vite.config.ts` has `base: '/your-subdirectory/'` set correctly
45+
- [ ] Build command has been re-run after config change
46+
- [ ] Built `dist/index.html` references assets with correct paths (e.g., `/vite-test/assets/...`)
47+
2248
## Routing and build defaults
2349

2450
- Use the existing router if present; do not switch routing libraries without an explicit requirement.

mcp/src/tools/hosting.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,10 @@ export function registerHostingTools(server: ExtendedMcpServer) {
258258
"uploadFiles",
259259
{
260260
title: "上传静态文件",
261-
description: "上传文件到静态网站托管,仅用于 Web 站点部署,不用于云存储对象上传。部署前请先完成构建;如果站点会部署到子路径,请检查构建配置中的 publicPath、base、assetPrefix 等是否使用相对路径,避免静态资源加载失败。若需要上传 COS 云存储文件,请使用 manageStorage。对于本地评测、现有脚手架补全或仅需本地开发服务器验证的任务,通常不需要调用此工具,除非用户明确要求部署站点。",
261+
description: "上传文件到静态网站托管,仅用于 Web 站点部署,不用于云存储对象上传。部署前请先完成构建;若需要上传 COS 云存储文件,请使用 manageStorage。对于本地评测、现有脚手架补全或仅需本地开发服务器验证的任务,通常不需要调用此工具,除非用户明确要求部署站点。\n\n⚠️ 子目录部署强制二次确认:若部署到子路径(如 /vite-test),调用前必须确认:\n1. 已在构建配置中设置 base/publicPath/assetPrefix(值必须与部署子目录一致,如部署到 /vite-test 则设为 '/vite-test/';禁止使用 './' 等相对路径,否则访问 URL 不带尾部斜杠时会导致资源 404)\n2. 已重新构建(修改配置后必须重新 build)\n3. 已验证构建产物中的资源引用路径已更新(非绝对根路径 '/')\n任何一项未通过时,禁止调用此工具。",
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("静态托管云端路径,相对于托管根目录,不要前导 '/',例如 'vite-test' 而非 '/vite-test'。部署到子路径时请先完成上方强制二次确认。云存储对象路径请改用 manageStorage。"),
265265
files: z.array(z.object({
266266
localPath: z.string(),
267267
cloudPath: z.string()

0 commit comments

Comments
 (0)