ossput 0.0.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/.cursor/skills/ossput/SKILL.md +87 -0
- package/.cursor/skills/ossput/examples.md +59 -0
- package/.cursor/skills/ossput/reference.md +78 -0
- package/.ossput.json.example +3 -0
- package/AGENTS.md +16 -0
- package/CHANGELOG.md +25 -0
- package/LICENSE +21 -0
- package/README.md +173 -0
- package/config.index.example.json +8 -0
- package/dist/batch-upload.d.ts +28 -0
- package/dist/batch-upload.js +34 -0
- package/dist/cli.d.ts +1 -0
- package/dist/cli.js +253 -0
- package/dist/config-profiles.d.ts +45 -0
- package/dist/config-profiles.js +282 -0
- package/dist/config.d.ts +14 -0
- package/dist/config.js +81 -0
- package/dist/constants.d.ts +5 -0
- package/dist/constants.js +5 -0
- package/dist/delete-object.d.ts +6 -0
- package/dist/delete-object.js +26 -0
- package/dist/doctor.d.ts +9 -0
- package/dist/doctor.js +128 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +21 -0
- package/dist/key-builder.d.ts +1 -0
- package/dist/key-builder.js +13 -0
- package/dist/list-directories.d.ts +11 -0
- package/dist/list-directories.js +64 -0
- package/dist/list-format.d.ts +6 -0
- package/dist/list-format.js +57 -0
- package/dist/list-objects.d.ts +7 -0
- package/dist/list-objects.js +47 -0
- package/dist/mcp-annotations.d.ts +16 -0
- package/dist/mcp-annotations.js +16 -0
- package/dist/mcp-result.d.ts +14 -0
- package/dist/mcp-result.js +57 -0
- package/dist/mcp.d.ts +4 -0
- package/dist/mcp.js +244 -0
- package/dist/object-key.d.ts +10 -0
- package/dist/object-key.js +46 -0
- package/dist/oss-client.d.ts +4 -0
- package/dist/oss-client.js +24 -0
- package/dist/profile-cli.d.ts +16 -0
- package/dist/profile-cli.js +191 -0
- package/dist/setup/connectivity.d.ts +2 -0
- package/dist/setup/connectivity.js +5 -0
- package/dist/setup/logo.d.ts +1 -0
- package/dist/setup/logo.js +30 -0
- package/dist/setup/mcp-registry.d.ts +17 -0
- package/dist/setup/mcp-registry.js +128 -0
- package/dist/setup/prompts.d.ts +24 -0
- package/dist/setup/prompts.js +410 -0
- package/dist/setup/run-setup.d.ts +9 -0
- package/dist/setup/run-setup.js +156 -0
- package/dist/setup/skill-install.d.ts +19 -0
- package/dist/setup/skill-install.js +85 -0
- package/dist/setup/ui.d.ts +49 -0
- package/dist/setup/ui.js +164 -0
- package/dist/setup/write-config.d.ts +5 -0
- package/dist/setup/write-config.js +5 -0
- package/dist/skill-cli.d.ts +6 -0
- package/dist/skill-cli.js +34 -0
- package/dist/types.d.ts +82 -0
- package/dist/types.js +1 -0
- package/dist/upload-pipeline.d.ts +7 -0
- package/dist/upload-pipeline.js +96 -0
- package/dist/validators.d.ts +10 -0
- package/dist/validators.js +77 -0
- package/docs/ram-policy.example.json +31 -0
- package/package.json +59 -0
- package/profiles.example/default.json +21 -0
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ossput
|
|
3
|
+
description: >-
|
|
4
|
+
Uploads local files to Aliyun OSS via the ossput MCP server (presigned PUT),
|
|
5
|
+
lists objects and directory prefixes, and resolves multi-account profiles.
|
|
6
|
+
Use when the user mentions OSS, Aliyun upload, 阿里云, 图床, object storage,
|
|
7
|
+
ossput, or wants to put images/files on their bucket and get a public URL.
|
|
8
|
+
---
|
|
9
|
+
|
|
10
|
+
# ossput — 阿里云 OSS 直传
|
|
11
|
+
|
|
12
|
+
## 前置条件
|
|
13
|
+
|
|
14
|
+
1. 用户本机已安装 Node.js 18+。
|
|
15
|
+
2. 终端已执行 `npx ossput setup`(注册 MCP,并将本 Skill 链接到 `~/.cursor/skills/ossput` 与 `~/.claude/skills/ossput`,**无需**复制到项目目录)。
|
|
16
|
+
3. Cursor / Claude Desktop 的 `mcp.json` 已包含 **ossput**;凭证在 `~/.config/ossput/profiles/`,**禁止**在对话中向用户索要 AccessKey。
|
|
17
|
+
|
|
18
|
+
未配置时:请用户在**终端**执行 `npx ossput setup`,然后重启 IDE / 新开 Agent 会话。可调用 `get_setup_status` 检查;用户本机可运行 `npx ossput doctor` 做完整诊断。
|
|
19
|
+
|
|
20
|
+
## 选用哪个 profile
|
|
21
|
+
|
|
22
|
+
解析顺序(高 → 低):工具参数 `profile` → 环境变量 `OSSPUT_PROFILE` → 项目根 `.ossput.json` → 全局 `defaultProfile`。
|
|
23
|
+
|
|
24
|
+
不确定时先调用 `list_profiles`,查看 `activeProfile` 与 `projectFile`。
|
|
25
|
+
|
|
26
|
+
## 工具选用(默认路径)
|
|
27
|
+
|
|
28
|
+
| 用户意图 | 工具 | 备注 |
|
|
29
|
+
|----------|------|------|
|
|
30
|
+
| 上传单个本地文件 | `upload_file` | 传 `localPath`;可选 `subdir` |
|
|
31
|
+
| 上传多个本地文件 | `batch_upload_file` | `localPaths` 数组,单次最多 20 个 |
|
|
32
|
+
| 看桶里有什么文件 | `list_objects` | 图片预览用 `format=markdown` |
|
|
33
|
+
| 删除误传对象 | `delete_object` | **见下文「删除安全」**;默认关闭 |
|
|
34
|
+
| 看有哪些目录前缀 | `list_directories` | 树形用 `format=markdown` |
|
|
35
|
+
| 检查配置 / MCP | `get_setup_status` | |
|
|
36
|
+
| 列出所有账号 | `list_profiles` | |
|
|
37
|
+
| 高级:自管 PUT | `prepare_upload` → HTTP PUT → `confirm_upload` | 一般不必 |
|
|
38
|
+
|
|
39
|
+
所有工具均可选 `profile` 覆盖当前项目绑定。
|
|
40
|
+
|
|
41
|
+
## 对象路径规则(重要)
|
|
42
|
+
|
|
43
|
+
最终 Key 形如:
|
|
44
|
+
|
|
45
|
+
```text
|
|
46
|
+
{profile.prefix}{subdir}{YYYY}/{MM}/{uuid}.{ext}
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
- `prefix`:profile 里配置的对象前缀,`/` 表示 Bucket 根目录。
|
|
50
|
+
- `subdir`:上传/列表时传入的子目录,如 `ossput_test` → 实际为 `ossput_test/`。
|
|
51
|
+
- 文件名默认 **UUID**,不是原文件名;会在 `subdir` 下再按 **UTC 年/月** 分子目录。
|
|
52
|
+
|
|
53
|
+
向用户说明 URL 时,以工具返回的 `objectUrl` / `objectKey` 为准。
|
|
54
|
+
|
|
55
|
+
## 安全与限制
|
|
56
|
+
|
|
57
|
+
- 勿上传:`.env`、密钥文件、含 `credentials`/`secret` 等敏感路径(工具会拒绝)。
|
|
58
|
+
- 单文件 ≤ **100MB**;仅支持单次 Presigned PUT(无分片)。
|
|
59
|
+
- 使用 RAM 子账号,权限收窄到目标 Bucket 与前缀。
|
|
60
|
+
|
|
61
|
+
## 删除安全(delete_object)
|
|
62
|
+
|
|
63
|
+
删除为**破坏性操作**,须同时满足:
|
|
64
|
+
|
|
65
|
+
1. Profile 中 **`allowDelete: true`**(默认 `false`,在 `~/.config/ossput/profiles/<name>.json` 手动开启)。
|
|
66
|
+
2. 工具参数 **`confirm: true`** — 仅在用户**明确确认**要删该 `objectKey` 后传入。
|
|
67
|
+
3. **`objectKey` 必须完整且准确** — 优先从 `list_objects` 或上传返回值复制,不要猜路径。
|
|
68
|
+
4. **Key scoped 到 profile 的 `prefix`** — 不能删除前缀外的对象;若 `prefix` 为桶根,还须至少 `子目录/文件名` 两段路径。
|
|
69
|
+
|
|
70
|
+
**Agent 流程:** `list_objects` 展示 Key → 向用户确认 → 再 `delete_object`。若 `allowDelete` 为 false,提示用户在终端编辑 profile 开启(勿在对话中要 AK)。
|
|
71
|
+
|
|
72
|
+
RAM 策略仅授予 `DeleteObject` 到必要前缀,与 `PutObject` 同级收窄。
|
|
73
|
+
|
|
74
|
+
## 常见问题
|
|
75
|
+
|
|
76
|
+
| 现象 | 处理 |
|
|
77
|
+
|------|------|
|
|
78
|
+
| MCP 工具不可用 | 用户执行 `npx ossput status`;重启 IDE;确认 `mcp.json` 指向有效 `dist/index.js` |
|
|
79
|
+
| `not configured` | 终端 `npx ossput setup` |
|
|
80
|
+
| 路径与预期不符 | 见上文「对象路径规则」;`list_objects` 用相同 `subdir` 查询 |
|
|
81
|
+
| 多账号 | `profile add` / `profile use`;或工具传 `profile` |
|
|
82
|
+
|
|
83
|
+
## 更多说明
|
|
84
|
+
|
|
85
|
+
- 配置结构、CLI 命令:见仓库 [README.md](../../../README.md)
|
|
86
|
+
- 工具参数:见 [reference.md](reference.md)
|
|
87
|
+
- 对话示例与反模式:见 [examples.md](examples.md)
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# ossput 示例对话
|
|
2
|
+
|
|
3
|
+
## 1. 上传本地截图到 `ossput_test`
|
|
4
|
+
|
|
5
|
+
**用户**:把这张截图传到 OSS 的 ossput_test 目录。
|
|
6
|
+
|
|
7
|
+
**Agent 步骤**:
|
|
8
|
+
|
|
9
|
+
1. `get_setup_status` — 确认 `configured: true`
|
|
10
|
+
2. `upload_file` — `localPath=/Users/me/Desktop/shot.png`,`subdir=ossput_test`
|
|
11
|
+
3. 回复用户工具返回的 `objectUrl`(Key 形如 `ossput_test/2026/05/<uuid>.png`)
|
|
12
|
+
|
|
13
|
+
---
|
|
14
|
+
|
|
15
|
+
## 2. 浏览已上传图片
|
|
16
|
+
|
|
17
|
+
**用户**:看看 ossput_test 里有哪些图。
|
|
18
|
+
|
|
19
|
+
**Agent**:`list_objects`,`subdir=ossput_test`,`format=markdown`,`imagesOnly=true`
|
|
20
|
+
|
|
21
|
+
将返回的 Markdown(含图片预览)直接展示给用户。
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## 3. 多账号项目
|
|
26
|
+
|
|
27
|
+
**用户**:这个项目要用客户 A 的桶上传。
|
|
28
|
+
|
|
29
|
+
**Agent**:
|
|
30
|
+
|
|
31
|
+
1. `list_profiles` — 看是否有 `client-a`
|
|
32
|
+
2. `upload_file` — `profile=client-a`,`localPath=...`,`subdir=deliverables/`
|
|
33
|
+
|
|
34
|
+
若项目根有 `.ossput.json` 且已绑定 `client-a`,可省略 `profile` 参数。
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## 4. 删除误传文件(需开启 allowDelete)
|
|
39
|
+
|
|
40
|
+
**用户**:删掉刚才传错的那张图。
|
|
41
|
+
|
|
42
|
+
**Agent**:
|
|
43
|
+
|
|
44
|
+
1. `get_setup_status` — 确认 `allowDelete: true`,否则请用户在 profile JSON 中开启
|
|
45
|
+
2. `list_objects` — 找到目标 `objectKey`,**向用户展示并确认**
|
|
46
|
+
3. `delete_object` — `objectKey=...`,`confirm=true`(仅用户同意后)
|
|
47
|
+
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
## 反模式
|
|
51
|
+
|
|
52
|
+
| 不要 | 原因 |
|
|
53
|
+
|------|------|
|
|
54
|
+
| 在对话里要 AccessKey | 应让用户终端执行 `npx ossput setup` |
|
|
55
|
+
| 用 `prepare_upload` 做普通上传 | 优先 `upload_file` |
|
|
56
|
+
| 上传后 list 用不同 `subdir` | 会与上传路径不一致,列不出文件 |
|
|
57
|
+
| 假设 URL 含原文件名 | 默认为 UUID 文件名 |
|
|
58
|
+
| 未确认就 `delete_object` | 必须先展示 objectKey 并取得用户同意,且 `confirm: true` |
|
|
59
|
+
| 未开 `allowDelete` 仍尝试删除 | 提示编辑 profile,不要反复调用 |
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
# ossput 参考
|
|
2
|
+
|
|
3
|
+
## 配置文件
|
|
4
|
+
|
|
5
|
+
| 路径 | 内容 |
|
|
6
|
+
|------|------|
|
|
7
|
+
| `~/.config/ossput/config.json` | 索引:`defaultProfile`、`profiles` 列表(无密钥) |
|
|
8
|
+
| `~/.config/ossput/profiles/{name}.json` | 单账号:region、bucket、prefix、AK(`chmod 600`);可选 `publicBaseUrl`、`allowDelete`(默认 false) |
|
|
9
|
+
| `{repo}/.ossput.json` | `{ "profile": "default" }`,可提交 Git |
|
|
10
|
+
|
|
11
|
+
## MCP 工具参数摘要
|
|
12
|
+
|
|
13
|
+
### upload_file
|
|
14
|
+
|
|
15
|
+
- `localPath`(必填):本机绝对或相对路径
|
|
16
|
+
- `subdir`(可选):逻辑子目录,如 `demo/`、`ossput_test`
|
|
17
|
+
- `contentType`(可选):不传则按扩展名推断
|
|
18
|
+
- `profile`(可选)
|
|
19
|
+
|
|
20
|
+
返回 JSON:`objectKey`、`objectUrl`、`size`、`exists` 等。
|
|
21
|
+
|
|
22
|
+
### batch_upload_file
|
|
23
|
+
|
|
24
|
+
- `localPaths`(必填):本机路径数组,**最多 20 个**
|
|
25
|
+
- `subdir`、`contentType`、`profile`(可选)
|
|
26
|
+
- `stopOnError`(可选):`true` 时遇错停止,默认继续其余文件
|
|
27
|
+
|
|
28
|
+
返回:`succeeded` / `failed` 计数及每个文件的 `ok` + `result` 或 `error`。
|
|
29
|
+
|
|
30
|
+
### delete_object
|
|
31
|
+
|
|
32
|
+
- `objectKey`(必填):完整对象 Key
|
|
33
|
+
- `confirm`(必填):**必须为 `true`**(表示用户已确认)
|
|
34
|
+
- `profile`(可选)
|
|
35
|
+
|
|
36
|
+
前置:profile 中 `allowDelete: true`。Key 须落在 profile `prefix` 下。删除前会 `head` 确认对象存在。
|
|
37
|
+
|
|
38
|
+
### list_objects
|
|
39
|
+
|
|
40
|
+
- `subdir`:列出该前缀下对象
|
|
41
|
+
- `format`: `json` | `markdown`(图片预览用 markdown)
|
|
42
|
+
- `imagesOnly`: `true` 仅图片
|
|
43
|
+
- `maxKeys`:默认 100,最大 1000
|
|
44
|
+
- `previewMax`:markdown 模式下最多预览张数
|
|
45
|
+
|
|
46
|
+
### list_directories
|
|
47
|
+
|
|
48
|
+
- `subdir`:从该前缀下列「子目录」
|
|
49
|
+
- `format`: `json` | `markdown`
|
|
50
|
+
|
|
51
|
+
### prepare_upload / confirm_upload
|
|
52
|
+
|
|
53
|
+
用于自定义上传流程;`overwrite: true` 时保留原文件名(仍带年月目录)。常规场景用 `upload_file` 即可。
|
|
54
|
+
|
|
55
|
+
## CLI(用户在终端执行)
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npx ossput setup
|
|
59
|
+
npx ossput profile list|add|show|use|default|rm
|
|
60
|
+
npx ossput status
|
|
61
|
+
npx ossput put <file> [file2 …] [--subdir name] [--stop-on-error]
|
|
62
|
+
npx ossput rm <objectKey> --confirm
|
|
63
|
+
npx ossput ls [subdir] [--markdown] [--images]
|
|
64
|
+
npx ossput dirs [subdir] [--markdown]
|
|
65
|
+
npx ossput --profile <name> <command>
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
## 示例对话流
|
|
69
|
+
|
|
70
|
+
**上传一张本地图到 `ossput_test`:**
|
|
71
|
+
|
|
72
|
+
1. `get_setup_status` 或 `list_profiles` 确认已配置
|
|
73
|
+
2. `upload_file`:`localPath=/path/to/photo.jpg`,`subdir=ossput_test`
|
|
74
|
+
3. 把返回的 `objectUrl` 给用户
|
|
75
|
+
|
|
76
|
+
**浏览已上传图片:**
|
|
77
|
+
|
|
78
|
+
`list_objects`:`subdir=ossput_test`,`format=markdown`,`imagesOnly=true`
|
package/AGENTS.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# Agent 说明(ossput)
|
|
2
|
+
|
|
3
|
+
本仓库提供 **ossput**:阿里云 OSS Presigned 直传的 MCP 服务 + CLI。
|
|
4
|
+
|
|
5
|
+
## 上传到 OSS 时
|
|
6
|
+
|
|
7
|
+
1. 确认 **ossput** MCP 已连接;未配置则让用户在终端运行 `npx ossput setup`(**不要**在对话里要 AccessKey)。`setup` 会把 Skill 装到 `~/.cursor/skills/ossput`(无需复制到项目目录)。
|
|
8
|
+
2. 遵循用户级 Skill(`~/.cursor/skills/ossput/SKILL.md`,或本仓库开发版 [.cursor/skills/ossput/SKILL.md](.cursor/skills/ossput/SKILL.md)):
|
|
9
|
+
- 优先 `upload_file`
|
|
10
|
+
- 先 `list_profiles` / 读 `.ossput.json` 确定 profile
|
|
11
|
+
- 注意 `subdir` 下会自动加 `年/月/UUID` 路径
|
|
12
|
+
|
|
13
|
+
## 文档
|
|
14
|
+
|
|
15
|
+
- 人类用户:[README.md](README.md)
|
|
16
|
+
- Agent 细则:`.cursor/skills/ossput/SKILL.md`、`reference.md`
|
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## Unreleased
|
|
4
|
+
|
|
5
|
+
## 0.0.1
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
|
|
9
|
+
- MCP:`upload_file`、`batch_upload_file`、`delete_object`、`list_objects`、`list_directories`、`list_profiles`、`get_setup_status`、`prepare_upload`、`confirm_upload`
|
|
10
|
+
- CLI:`setup`、`status`、`put`(多文件)、`rm --confirm`、`ls`、`dirs`、`profile`、`doctor`、`skill install`
|
|
11
|
+
- 多账号:`~/.config/ossput/profiles/` + 项目 `.ossput.json`;环境变量 `OSSPUT_PROFILE`、`OSSPUT_MCP`
|
|
12
|
+
- Setup 向导:MCP 注册(Cursor / Claude Code)、连通性检测、可选 `publicBaseUrl` / `allowDelete`
|
|
13
|
+
- Agent Skill:`.cursor/skills/ossput/`;`setup` 自动安装到用户目录(符号链接)
|
|
14
|
+
- `docs/ram-policy.example.json`:RAM 最小权限策略示例
|
|
15
|
+
- CI:Ubuntu(Node 18/20/22)+ Windows 冒烟
|
|
16
|
+
|
|
17
|
+
### Changed
|
|
18
|
+
|
|
19
|
+
- 上传使用 Node 内置 `fetch`(Node 18+),不依赖系统 `curl`
|
|
20
|
+
- MCP 工具 `annotations`;失败返回 `isError` 与可执行提示
|
|
21
|
+
|
|
22
|
+
### Notes
|
|
23
|
+
|
|
24
|
+
- 上传对象 Key:`{prefix}{subdir}{YYYY}/{MM}/{uuid}.{ext}`
|
|
25
|
+
- 单文件上限 100MB;删除需在 profile 开启 `allowDelete` 且 MCP/CLI 显式确认
|
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 ossput contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
# ossput
|
|
2
|
+
|
|
3
|
+
[](https://github.com/devoink/ossput/actions/workflows/ci.yml)
|
|
4
|
+
|
|
5
|
+
Aliyun OSS direct upload for AI agents — MCP server + CLI. Presigned PUT via Node `fetch` (Node 18+). **Credentials live in `~/.config/ossput/profiles/`**, not in `mcp.json`.
|
|
6
|
+
|
|
7
|
+
## Quick start
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npx -y ossput setup
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
向导会:创建第一个 **profile**(账号)→ 检测连通性 → 注册 MCP → 可选写入项目 `.ossput.json`。
|
|
14
|
+
|
|
15
|
+
完成后 **重启 IDE**,确认 **ossput** MCP 已连接。
|
|
16
|
+
|
|
17
|
+
```bash
|
|
18
|
+
ossput put ./photo.png --subdir demo/2026-05
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
## AI Agent:MCP 与 Skill
|
|
22
|
+
|
|
23
|
+
| 能力 | 作用 | 如何启用 |
|
|
24
|
+
|------|------|----------|
|
|
25
|
+
| **MCP** | `upload_file` 等工具 | `npx ossput setup` 注册到 Cursor / Claude Desktop,重启 IDE |
|
|
26
|
+
| **Skill** | 教 Agent 何时用 MCP、路径规则 | **`setup` 会自动安装到本机用户目录**(无需复制到项目) |
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
npx ossput setup # OSS 配置 + MCP + Skill(用户级)
|
|
30
|
+
npx ossput skill install # 仅重装 Skill(升级 npm 包后可选)
|
|
31
|
+
npx ossput setup --skip-skill # 不要安装 Skill
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
安装位置(符号链接指向 npm 包内 Skill,升级包后链接仍有效):
|
|
35
|
+
|
|
36
|
+
- Cursor:`~/.cursor/skills/ossput/`
|
|
37
|
+
- Claude Code:`~/.claude/skills/ossput/`(可用 `/ossput` 调用)
|
|
38
|
+
|
|
39
|
+
**不需要**把 `SKILL.md` 复制进每个项目的 `.cursor/skills/`。仓库内的 `.cursor/skills/ossput/` 仅用于开发与 npm 打包。
|
|
40
|
+
|
|
41
|
+
Agent 细则见 [AGENTS.md](./AGENTS.md)。
|
|
42
|
+
|
|
43
|
+
### Claude Code 的 MCP
|
|
44
|
+
|
|
45
|
+
`ossput setup` 可将 MCP 写入 **`~/.claude.json`**(与 Cursor 的 `~/.cursor/mcp.json` 并列)。向导中勾选 **Claude Code** 即可;也可事后重新运行 `npx ossput setup` 仅注册 MCP。
|
|
46
|
+
|
|
47
|
+
若未自动注册,可手动在 `~/.claude.json` 的 `mcpServers` 中加入与 Cursor 相同的 `node` + `dist/index.js` 条目。
|
|
48
|
+
|
|
49
|
+
### Agent 须知(摘要)
|
|
50
|
+
|
|
51
|
+
- 未配置 → 终端 `npx ossput setup`,**勿在对话中索要 AccessKey**
|
|
52
|
+
- 上传 → MCP `upload_file`;看图 → `list_objects`(`format=markdown`)
|
|
53
|
+
- 对象 Key:`{prefix}{subdir}{年}/{月}/{uuid}.ext`
|
|
54
|
+
|
|
55
|
+
## 多账号 / 多项目
|
|
56
|
+
|
|
57
|
+
| 文件 | 说明 |
|
|
58
|
+
|------|------|
|
|
59
|
+
| `~/.config/ossput/config.json` | 索引:`defaultProfile` + profile 列表(无密钥) |
|
|
60
|
+
| `~/.config/ossput/profiles/{name}.json` | 单账号 OSS 配置(chmod 600) |
|
|
61
|
+
| `{repo}/.ossput.json` | 项目绑定:`{ "profile": "default" }`(可提交 Git) |
|
|
62
|
+
|
|
63
|
+
**解析优先级:** CLI/MCP 的 `profile` 参数 → `OSSPUT_PROFILE` → 项目 `.ossput.json` → 全局 `defaultProfile`
|
|
64
|
+
|
|
65
|
+
```bash
|
|
66
|
+
ossput profile add client-a # 新增账号
|
|
67
|
+
ossput profile list # 列出账号
|
|
68
|
+
ossput profile use default # 当前目录写 .ossput.json
|
|
69
|
+
ossput --profile client-a put ./x.zip
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
示例见 [config.index.example.json](./config.index.example.json)、[profiles.example/default.json](./profiles.example/default.json)、[.ossput.json.example](./.ossput.json.example)。
|
|
73
|
+
|
|
74
|
+
## MCP tools
|
|
75
|
+
|
|
76
|
+
| Tool | Description |
|
|
77
|
+
|------|-------------|
|
|
78
|
+
| `upload_file` | Upload local file |
|
|
79
|
+
| `batch_upload_file` | Batch upload (max 20 files per call) |
|
|
80
|
+
| `delete_object` | Delete one object (`allowDelete` + `confirm: true`) |
|
|
81
|
+
| `list_objects` | List files (`format=markdown` for image previews) |
|
|
82
|
+
| `list_directories` | List folder prefixes |
|
|
83
|
+
| `list_profiles` | List profiles + active profile in cwd |
|
|
84
|
+
| `get_setup_status` | Config + MCP registration |
|
|
85
|
+
| `prepare_upload` / `confirm_upload` | Advanced presign flow |
|
|
86
|
+
|
|
87
|
+
All tools accept optional `profile` to override `.ossput.json`.
|
|
88
|
+
|
|
89
|
+
## MCP configuration (manual)
|
|
90
|
+
|
|
91
|
+
```json
|
|
92
|
+
{
|
|
93
|
+
"mcpServers": {
|
|
94
|
+
"ossput": {
|
|
95
|
+
"command": "node",
|
|
96
|
+
"args": ["/absolute/path/to/ossput/dist/index.js"]
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
## CLI
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
ossput setup
|
|
106
|
+
ossput profile list|add|show|use|default|rm
|
|
107
|
+
ossput status
|
|
108
|
+
ossput doctor
|
|
109
|
+
ossput put <file> [file2 …] [--subdir x] [--stop-on-error]
|
|
110
|
+
ossput rm <objectKey> --confirm
|
|
111
|
+
ossput ls [subdir] [--markdown] [--images]
|
|
112
|
+
ossput dirs [subdir] [--markdown]
|
|
113
|
+
ossput --profile <name> <command>
|
|
114
|
+
```
|
|
115
|
+
|
|
116
|
+
## Security
|
|
117
|
+
|
|
118
|
+
- Use RAM users scoped to bucket prefix (`PutObject` / `HeadObject`).
|
|
119
|
+
- Do not paste AccessKeys into chat; use `setup` / `profile add` in terminal.
|
|
120
|
+
- Commit `.ossput.json` only; never commit `profiles/*.json`.
|
|
121
|
+
- **Delete:** off by default; set `allowDelete: true` in profile only when needed. MCP requires `confirm: true` and `objectKey` under profile `prefix`. CLI: `ossput rm <key> --confirm`. RAM 示例见 [docs/ram-policy.example.json](./docs/ram-policy.example.json).
|
|
122
|
+
|
|
123
|
+
## Limits
|
|
124
|
+
|
|
125
|
+
- Single file ≤ 100MB
|
|
126
|
+
- Presigned single PUT only (v1)
|
|
127
|
+
- Requires **Node.js 18+**(内置 `fetch`,无需安装 curl)
|
|
128
|
+
- CDN / 自定义域名:在 profile JSON 设置 `publicBaseUrl`(如 `https://cdn.example.com`)
|
|
129
|
+
|
|
130
|
+
## Windows
|
|
131
|
+
|
|
132
|
+
在 Windows 上路径通过 `%USERPROFILE%`(`os.homedir()`)解析,与 macOS/Linux 使用同一套逻辑,**未在 Windows CI 中完整验证**,以下为典型位置:
|
|
133
|
+
|
|
134
|
+
| 用途 | 典型路径 |
|
|
135
|
+
|------|----------|
|
|
136
|
+
| OSS 配置 | `%USERPROFILE%\.config\ossput\` |
|
|
137
|
+
| Cursor MCP | `%USERPROFILE%\.cursor\mcp.json` |
|
|
138
|
+
| Claude Desktop MCP | `%APPDATA%\Claude\claude_desktop_config.json` |
|
|
139
|
+
| Cursor Skill | `%USERPROFILE%\.cursor\skills\ossput\` |
|
|
140
|
+
| Claude Code Skill | `%USERPROFILE%\.claude\skills\ossput\` |
|
|
141
|
+
|
|
142
|
+
说明:
|
|
143
|
+
|
|
144
|
+
- `.cursor`、`.config` 为隐藏文件夹,可在资源管理器中开启「隐藏的项目」,或在地址栏输入 `%USERPROFILE%\.cursor`。
|
|
145
|
+
- Skill 安装优先创建 **junction**;失败时自动 **复制** 到上述目录(升级 npm 后若用复制方式,需再执行 `ossput skill install`)。
|
|
146
|
+
- `chmod 600` 在 Windows 上权限语义较弱,请勿依赖其做访问控制;仍请勿将 `profiles/*.json` 提交到 Git。
|
|
147
|
+
- 上传失败:运行 `ossput doctor`,确认 Node ≥18 且 Bucket 连通;检查 RAM 是否具备 `PutObject` 权限。
|
|
148
|
+
|
|
149
|
+
## 对象路径说明
|
|
150
|
+
|
|
151
|
+
`ossput put ./a.png --subdir ossput_test` 实际上传 Key 类似:
|
|
152
|
+
|
|
153
|
+
```text
|
|
154
|
+
ossput_test/2026/05/<uuid>.png
|
|
155
|
+
```
|
|
156
|
+
|
|
157
|
+
(另加 profile 配置的 `prefix`。)列表与上传使用相同 `subdir` 才能对齐。
|
|
158
|
+
|
|
159
|
+
## Local development
|
|
160
|
+
|
|
161
|
+
```bash
|
|
162
|
+
cd ossput
|
|
163
|
+
npm ci && npm run build
|
|
164
|
+
node dist/index.js setup
|
|
165
|
+
```
|
|
166
|
+
|
|
167
|
+
## Changelog
|
|
168
|
+
|
|
169
|
+
See [CHANGELOG.md](./CHANGELOG.md).
|
|
170
|
+
|
|
171
|
+
## License
|
|
172
|
+
|
|
173
|
+
MIT
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { AppConfig } from "./types.js";
|
|
2
|
+
import type { UploadFileResult } from "./types.js";
|
|
3
|
+
export declare const MAX_BATCH_FILES = 20;
|
|
4
|
+
export interface BatchUploadItemSuccess {
|
|
5
|
+
localPath: string;
|
|
6
|
+
ok: true;
|
|
7
|
+
result: UploadFileResult;
|
|
8
|
+
}
|
|
9
|
+
export interface BatchUploadItemFailure {
|
|
10
|
+
localPath: string;
|
|
11
|
+
ok: false;
|
|
12
|
+
error: string;
|
|
13
|
+
}
|
|
14
|
+
export type BatchUploadItemResult = BatchUploadItemSuccess | BatchUploadItemFailure;
|
|
15
|
+
export interface BatchUploadResult {
|
|
16
|
+
subdir: string;
|
|
17
|
+
total: number;
|
|
18
|
+
succeeded: number;
|
|
19
|
+
failed: number;
|
|
20
|
+
results: BatchUploadItemResult[];
|
|
21
|
+
}
|
|
22
|
+
export interface BatchUploadOptions {
|
|
23
|
+
subdir?: string;
|
|
24
|
+
contentType?: string;
|
|
25
|
+
/** 遇错即停;默认 false,继续上传其余文件 */
|
|
26
|
+
stopOnError?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export declare function batchUploadFile(config: AppConfig, localPaths: string[], options?: BatchUploadOptions): Promise<BatchUploadResult>;
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { uploadFile } from "./upload-pipeline.js";
|
|
2
|
+
import { validateSubdir } from "./validators.js";
|
|
3
|
+
export const MAX_BATCH_FILES = 20;
|
|
4
|
+
export async function batchUploadFile(config, localPaths, options = {}) {
|
|
5
|
+
if (localPaths.length === 0) {
|
|
6
|
+
throw new Error("localPaths cannot be empty");
|
|
7
|
+
}
|
|
8
|
+
if (localPaths.length > MAX_BATCH_FILES) {
|
|
9
|
+
throw new Error(`at most ${MAX_BATCH_FILES} files per batch (got ${localPaths.length})`);
|
|
10
|
+
}
|
|
11
|
+
const normalizedSubdir = validateSubdir(options.subdir);
|
|
12
|
+
const results = [];
|
|
13
|
+
for (const localPath of localPaths) {
|
|
14
|
+
try {
|
|
15
|
+
const result = await uploadFile(config, localPath, normalizedSubdir || undefined, options.contentType);
|
|
16
|
+
results.push({ localPath, ok: true, result });
|
|
17
|
+
}
|
|
18
|
+
catch (err) {
|
|
19
|
+
const error = err instanceof Error ? err.message : String(err);
|
|
20
|
+
results.push({ localPath, ok: false, error });
|
|
21
|
+
if (options.stopOnError) {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
const succeeded = results.filter((r) => r.ok).length;
|
|
27
|
+
return {
|
|
28
|
+
subdir: normalizedSubdir,
|
|
29
|
+
total: localPaths.length,
|
|
30
|
+
succeeded,
|
|
31
|
+
failed: results.length - succeeded,
|
|
32
|
+
results,
|
|
33
|
+
};
|
|
34
|
+
}
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function runCli(argv: string[]): Promise<number>;
|