ctxshot-mcp 0.1.0 → 0.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.
Files changed (2) hide show
  1. package/README.md +209 -16
  2. package/package.json +5 -5
package/README.md CHANGED
@@ -1,17 +1,58 @@
1
1
  # ctxshot-mcp
2
2
 
3
+ [![CI](https://github.com/G12789/ctxshot-mcp/actions/workflows/ci.yml/badge.svg)](https://github.com/G12789/ctxshot-mcp/actions/workflows/ci.yml)
3
4
  [![npm](https://img.shields.io/npm/v/ctxshot-mcp?color=cb3837&logo=npm)](https://www.npmjs.com/package/ctxshot-mcp)
4
5
  [![MCP](https://img.shields.io/badge/MCP-stdio-7c3aed)](https://modelcontextprotocol.io)
6
+ [![node](https://img.shields.io/badge/node-%3E%3D18-339933?logo=node.js&logoColor=white)](https://nodejs.org)
7
+ [![license](https://img.shields.io/badge/license-MIT-blue)](LICENSE)
5
8
 
6
- > **轻量项目简报 MCP** 每日开会话用,不是 Repomix 全库打包。
7
- > Tools: `pack_context` · `session_brief` · `context_stats`
9
+ > **给 Cursor / Claude Code 的轻量项目简报 MCP。**
10
+ > 每天开会话 ~400 token 交代项目结构,不是 Repomix 全库打包。
11
+ >
12
+ > Tools: `session_brief` · `pack_context` · `context_stats`
8
13
 
9
- ## Cursor 配置
14
+ [ctxshot](https://github.com/G12789/ctxshot) MCP 封装。让 Agent **原生调用**打包逻辑,自动写 `.ai/context.md`,不用你每次手动 `npx ctxshot`。
15
+
16
+ ---
17
+
18
+ ## 解决什么问题
19
+
20
+ | 场景 | 笨办法 | ctxshot-mcp |
21
+ |---|---|---|
22
+ | 每天新开会话 | 反复贴 README、glob 目录 | Agent 调 `session_brief` → `@.ai/context.md` |
23
+ | 想知道简报多大 | 跑完再看 | `context_stats` 先看 token 估算 |
24
+ | 临时要结构 | 复制终端输出 | `pack_context` 直接返回 Markdown |
25
+ | 要读全库 | Repomix 一把梭 | **仍用 Repomix**,本 MCP 不替代 |
26
+
27
+ ---
28
+
29
+ ## 实测(同仓库 benchmark)
30
+
31
+ 基于 [ctxshot](https://github.com/G12789/ctxshot) 自身仓库:
32
+
33
+ | 工具 | 耗时 | 估 token |
34
+ |---|---:|---:|
35
+ | ctxshot / session_brief | **356ms** | **423** |
36
+ | README 手贴 | <1ms | 685 |
37
+ | repomix --stdout | **3.6s** | **7,023** |
38
+
39
+ <p align="center">
40
+ <img src="https://raw.githubusercontent.com/G12789/ctxshot/main/docs/benchmark-chart.svg" alt="ctxshot vs Repomix" width="860" />
41
+ </p>
42
+
43
+ ---
44
+
45
+ ## 30 秒接入
46
+
47
+ ### Cursor
48
+
49
+ `~/.cursor/mcp.json` 或项目 `.cursor/mcp.json`:
10
50
 
11
51
  ```json
12
52
  {
13
53
  "mcpServers": {
14
54
  "ctxshot": {
55
+ "type": "stdio",
15
56
  "command": "npx",
16
57
  "args": ["-y", "ctxshot-mcp@latest"]
17
58
  }
@@ -19,36 +60,188 @@
19
60
  }
20
61
  ```
21
62
 
22
- ## Claude Code
63
+ **Developer: Reload Window** 后,Settings → **Tools & MCPs** 看到绿色 `ctxshot` 即成功。
64
+
65
+ ### Claude Code
23
66
 
24
67
  ```bash
25
68
  claude mcp add ctxshot -- npx -y ctxshot-mcp@latest
26
69
  ```
27
70
 
28
- ## Tools
71
+ ### 验证
29
72
 
30
- | Tool | 何时用 |
31
- |---|---|
32
- | `session_brief` | **每天**新会话 — 写 `.ai/context.md` + 返回简报 |
33
- | `pack_context` | 需要项目全貌但不要全库文件 |
34
- | `context_stats` | 只看 token 估算,不拉全文 |
73
+ ```bash
74
+ npx ctxshot-mcp # stdio server(由 IDE 拉起,勿手动交互)
75
+ ```
76
+
77
+ 或在项目里:
35
78
 
36
- ## vs Repomix
79
+ ```bash
80
+ git clone https://github.com/G12789/ctxshot-mcp
81
+ cd ctxshot-mcp && npm install
82
+ npm run test:mcp
83
+ ```
84
+
85
+ ---
86
+
87
+ ## MCP Tools 完整说明
88
+
89
+ ### `session_brief`(推荐:每日起手)
90
+
91
+ 打包 compact + diff 简报,写入 `.ai/context.md`,并返回全文。
92
+
93
+ | 参数 | 类型 | 说明 |
94
+ |---|---|---|
95
+ | `root` | string? | 项目根目录(默认:server cwd) |
96
+ | `out` | string? | 输出路径,相对 root(默认 `.ai/context.md`) |
97
+
98
+ **典型用法:** 新会话开头让 Agent 调用,然后 `@.ai/context.md`。
99
+
100
+ ---
101
+
102
+ ### `pack_context`
103
+
104
+ 返回 Markdown 简报,不写文件。
105
+
106
+ | 参数 | 类型 | 默认 | 说明 |
107
+ |---|---|---|---|
108
+ | `compact` | boolean? | `true` | 浅树 + 截断 README |
109
+ | `diff` | boolean? | `false` | 包含 git 摘要 |
110
+ | `depth` | number? | compact=2 | 目录树深度 (1–6) |
111
+ | `maxEntries` | number? | compact=50 | 最多树节点 (10–500) |
112
+ | `root` | string? | cwd | 项目根目录 |
113
+
114
+ ---
115
+
116
+ ### `context_stats`
117
+
118
+ 只返回 JSON 统计,不拉全文。适合对比 token 成本。
119
+
120
+ | 参数 | 类型 | 说明 |
121
+ |---|---|---|
122
+ | `compact` | boolean? | 同 pack_context |
123
+ | `diff` | boolean? | 同 pack_context |
124
+ | `root` | string? | 项目根目录 |
125
+
126
+ 返回示例:
127
+
128
+ ```json
129
+ {
130
+ "estimatedTokens": 423,
131
+ "lineCount": 76,
132
+ "treeLineCount": 22,
133
+ "compact": true,
134
+ "hasGit": true,
135
+ "manifestCount": 1,
136
+ "root": "/your/project",
137
+ "hint": "Use pack_context for full brief; Repomix for entire codebase."
138
+ }
139
+ ```
140
+
141
+ ---
142
+
143
+ ## 推荐工作流
144
+
145
+ ```
146
+ ┌─────────────────────────────────────────────────────┐
147
+ │ 1. 打开项目(或传 root 参数) │
148
+ │ 2. 新会话 → Agent 调用 session_brief │
149
+ │ 3. 生成 .ai/context.md + ledger-events.jsonl │
150
+ │ 4. 对话 @.ai/context.md │
151
+ │ 5. 读具体实现 → @文件 或 Repomix │
152
+ └─────────────────────────────────────────────────────┘
153
+ ```
154
+
155
+ `.ai/ledger-events.jsonl` 记录每次调用的 token 估算,为后续 token 账本功能预埋。
156
+
157
+ ---
158
+
159
+ ## 架构
160
+
161
+ ```
162
+ Cursor / Claude Code
163
+ │ stdio MCP
164
+
165
+ ctxshot-mcp (本仓库)
166
+ ├── index.ts stdio 入口
167
+ └── server.ts 注册 3 个 Tool
168
+
169
+
170
+ ctxshot/core (npm 依赖)
171
+ packContext() — 与 CLI 共用同一套逻辑
172
+
173
+
174
+ .ai/context.md
175
+ .ai/ledger-events.jsonl
176
+ ```
177
+
178
+ 与 CLI 的关系:
179
+
180
+ | | [ctxshot](https://github.com/G12789/ctxshot) CLI | ctxshot-mcp |
181
+ |---|---|---|
182
+ | 调用方 | 人 / 脚本 | Agent / IDE |
183
+ | 传输 | 终端 | MCP stdio |
184
+ | 核心 | `packContext()` | 同左 |
185
+ | 输出 | stdout 或 `-o` 文件 | Tool 返回 + `session_brief` 写文件 |
186
+
187
+ ---
188
+
189
+ ## 和 Repomix 怎么选
37
190
 
38
191
  | | ctxshot-mcp | Repomix |
39
192
  |---|---|---|
40
193
  | Token | ~200–2k | 可达 100k+ |
41
194
  | 速度 | <1s | 大仓库慢 |
42
- | 场景 | **每日开会话** | 全库 refactor |
195
+ | 内容 | + 脚本 + 摘要 | 全文件内容 |
196
+ | 场景 | **每日开会话** | 全库 refactor / 审计 |
197
+ | 关系 | **互补** | 互补 |
198
+
199
+ ---
200
+
201
+ ## 常见问题
202
+
203
+ **Q: MCP 绿灯但扫错目录?**
204
+ 全局 MCP 的 cwd 可能是用户主目录。解法:
205
+ - 把目标项目作为 Cursor 工作区根目录打开
206
+ - 或调用时传 `root`: `"/path/to/your/project"`
207
+
208
+ **Q: 和 CLI 有什么区别?**
209
+ 逻辑完全一样(共用 `ctxshot/core`)。MCP 让 Agent 在会话里自动调用,不用你记命令。
210
+
211
+ **Q: 能替代 Repomix 吗?**
212
+ 不能。简报 ≠ 全库。需要 AI 读每一行代码时请用 Repomix。
213
+
214
+ **Q: 离线能用吗?**
215
+ 能。纯本地扫描,不联网,不上传任何内容。
216
+
217
+ ---
43
218
 
44
219
  ## 开发
45
220
 
46
221
  ```bash
47
- cd ctxshot && npm run build
48
- cd ../ctxshot-mcp && npm install && npm run build
49
- npm run inspect # MCP Inspector
222
+ git clone https://github.com/G12789/ctxshot-mcp
223
+ cd ctxshot-mcp && npm install
224
+ npm run build
225
+ npm run test:smoke # 单元 smoke
226
+ npm run test:mcp # MCP 客户端端到端
227
+ npm run inspect # MCP Inspector
50
228
  ```
51
229
 
230
+ 依赖 [ctxshot@0.2.1+](https://www.npmjs.com/package/ctxshot) 的 `ctxshot/core` 导出。
231
+
232
+ ---
233
+
234
+ ## 相关项目
235
+
236
+ | 项目 | 链接 |
237
+ |---|---|
238
+ | ctxshot CLI | https://github.com/G12789/ctxshot |
239
+ | evaldrift | https://github.com/G12789/evaldrift |
240
+ | mcp-quickstart | https://github.com/G12789/mcp-quickstart |
241
+ | ship-skills | https://www.npmjs.com/package/ship-skills |
242
+
243
+ ---
244
+
52
245
  ## License
53
246
 
54
- MIT
247
+ MIT · [ctxshot CLI](https://github.com/G12789/ctxshot) · [npm](https://www.npmjs.com/package/ctxshot-mcp)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ctxshot-mcp",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "MCP server — lightweight daily project brief for Claude Code & Cursor (pack_context, session_brief, context_stats).",
5
5
  "type": "module",
6
6
  "bin": {
@@ -17,7 +17,8 @@
17
17
  "start": "node dist/index.js",
18
18
  "inspect": "npx @modelcontextprotocol/inspector tsx src/index.ts",
19
19
  "prepublishOnly": "npm run build && npm run test:smoke",
20
- "test:smoke": "node scripts/ci-smoke.mjs"
20
+ "test:smoke": "node scripts/ci-smoke.mjs",
21
+ "test:mcp": "node scripts/test-mcp-client.mjs"
21
22
  },
22
23
  "keywords": [
23
24
  "mcp",
@@ -33,15 +34,14 @@
33
34
  },
34
35
  "repository": {
35
36
  "type": "git",
36
- "url": "git+https://github.com/G12789/ctxshot.git",
37
- "directory": "packages/mcp"
37
+ "url": "git+https://github.com/G12789/ctxshot-mcp.git"
38
38
  },
39
39
  "publishConfig": {
40
40
  "access": "public"
41
41
  },
42
42
  "dependencies": {
43
43
  "@modelcontextprotocol/sdk": "^1.12.0",
44
- "ctxshot": "^0.2.0",
44
+ "ctxshot": "^0.2.2",
45
45
  "zod": "^3.23.8"
46
46
  },
47
47
  "devDependencies": {