ctxshot-mcp 0.1.0
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/LICENSE +21 -0
- package/README.md +54 -0
- package/dist/index.js +7 -0
- package/dist/server.js +139 -0
- package/package.json +52 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Glinks
|
|
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,54 @@
|
|
|
1
|
+
# ctxshot-mcp
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/ctxshot-mcp)
|
|
4
|
+
[](https://modelcontextprotocol.io)
|
|
5
|
+
|
|
6
|
+
> **轻量项目简报 MCP** — 每日开会话用,不是 Repomix 全库打包。
|
|
7
|
+
> Tools: `pack_context` · `session_brief` · `context_stats`
|
|
8
|
+
|
|
9
|
+
## Cursor 配置
|
|
10
|
+
|
|
11
|
+
```json
|
|
12
|
+
{
|
|
13
|
+
"mcpServers": {
|
|
14
|
+
"ctxshot": {
|
|
15
|
+
"command": "npx",
|
|
16
|
+
"args": ["-y", "ctxshot-mcp@latest"]
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
```
|
|
21
|
+
|
|
22
|
+
## Claude Code
|
|
23
|
+
|
|
24
|
+
```bash
|
|
25
|
+
claude mcp add ctxshot -- npx -y ctxshot-mcp@latest
|
|
26
|
+
```
|
|
27
|
+
|
|
28
|
+
## Tools
|
|
29
|
+
|
|
30
|
+
| Tool | 何时用 |
|
|
31
|
+
|---|---|
|
|
32
|
+
| `session_brief` | **每天**新会话 — 写 `.ai/context.md` + 返回简报 |
|
|
33
|
+
| `pack_context` | 需要项目全貌但不要全库文件 |
|
|
34
|
+
| `context_stats` | 只看 token 估算,不拉全文 |
|
|
35
|
+
|
|
36
|
+
## vs Repomix
|
|
37
|
+
|
|
38
|
+
| | ctxshot-mcp | Repomix |
|
|
39
|
+
|---|---|---|
|
|
40
|
+
| Token | ~200–2k | 可达 100k+ |
|
|
41
|
+
| 速度 | <1s | 大仓库慢 |
|
|
42
|
+
| 场景 | **每日开会话** | 全库 refactor |
|
|
43
|
+
|
|
44
|
+
## 开发
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
cd ctxshot && npm run build
|
|
48
|
+
cd ../ctxshot-mcp && npm install && npm run build
|
|
49
|
+
npm run inspect # MCP Inspector
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## License
|
|
53
|
+
|
|
54
|
+
MIT
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { createCtxshotMcpServer } from "./server.js";
|
|
4
|
+
const cwd = process.cwd();
|
|
5
|
+
const server = createCtxshotMcpServer(cwd);
|
|
6
|
+
const transport = new StdioServerTransport();
|
|
7
|
+
await server.connect(transport);
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
import { appendFileSync, mkdirSync, writeFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join, resolve } from "node:path";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { packContext } from "ctxshot/core";
|
|
5
|
+
import { z } from "zod";
|
|
6
|
+
const VERSION = "0.1.0";
|
|
7
|
+
const DEFAULT_OUT = ".ai/context.md";
|
|
8
|
+
const LEDGER_PATH = ".ai/ledger-events.jsonl";
|
|
9
|
+
function recordLedger(root, tool, stats) {
|
|
10
|
+
try {
|
|
11
|
+
const ledger = join(root, LEDGER_PATH);
|
|
12
|
+
mkdirSync(dirname(ledger), { recursive: true });
|
|
13
|
+
const row = JSON.stringify({
|
|
14
|
+
ts: new Date().toISOString(),
|
|
15
|
+
tool,
|
|
16
|
+
estimatedTokens: stats.estimatedTokens,
|
|
17
|
+
compact: stats.compact,
|
|
18
|
+
source: "ctxshot-mcp",
|
|
19
|
+
});
|
|
20
|
+
appendFileSync(ledger, row + "\n", "utf8");
|
|
21
|
+
}
|
|
22
|
+
catch {
|
|
23
|
+
/* ledger optional */
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
export function createCtxshotMcpServer(cwd) {
|
|
27
|
+
const server = new McpServer({
|
|
28
|
+
name: "ctxshot-mcp",
|
|
29
|
+
version: VERSION,
|
|
30
|
+
});
|
|
31
|
+
const packSchema = {
|
|
32
|
+
compact: z
|
|
33
|
+
.boolean()
|
|
34
|
+
.optional()
|
|
35
|
+
.describe("Shorter tree and truncated README (default true)"),
|
|
36
|
+
diff: z
|
|
37
|
+
.boolean()
|
|
38
|
+
.optional()
|
|
39
|
+
.describe("Include recent commits and uncommitted diff (default false)"),
|
|
40
|
+
depth: z
|
|
41
|
+
.number()
|
|
42
|
+
.int()
|
|
43
|
+
.min(1)
|
|
44
|
+
.max(6)
|
|
45
|
+
.optional()
|
|
46
|
+
.describe("Directory tree depth"),
|
|
47
|
+
maxEntries: z
|
|
48
|
+
.number()
|
|
49
|
+
.int()
|
|
50
|
+
.min(10)
|
|
51
|
+
.max(500)
|
|
52
|
+
.optional()
|
|
53
|
+
.describe("Max tree entries"),
|
|
54
|
+
root: z
|
|
55
|
+
.string()
|
|
56
|
+
.optional()
|
|
57
|
+
.describe("Project root path (default: server cwd)"),
|
|
58
|
+
};
|
|
59
|
+
server.registerTool("pack_context", {
|
|
60
|
+
title: "Pack project context",
|
|
61
|
+
description: "Generate a lightweight markdown project brief (~200-2000 tokens): tree, npm scripts, README/AGENTS excerpt, optional git diff. Use at session start instead of reading the whole repo or running Repomix.",
|
|
62
|
+
inputSchema: packSchema,
|
|
63
|
+
}, async (args) => {
|
|
64
|
+
const root = resolve(args.root ?? cwd);
|
|
65
|
+
const compact = args.compact ?? true;
|
|
66
|
+
const result = packContext({
|
|
67
|
+
root,
|
|
68
|
+
compact,
|
|
69
|
+
diff: args.diff ?? false,
|
|
70
|
+
depth: args.depth,
|
|
71
|
+
maxEntries: args.maxEntries,
|
|
72
|
+
});
|
|
73
|
+
recordLedger(root, "pack_context", result.stats);
|
|
74
|
+
return {
|
|
75
|
+
content: [
|
|
76
|
+
{
|
|
77
|
+
type: "text",
|
|
78
|
+
text: result.markdown,
|
|
79
|
+
},
|
|
80
|
+
],
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
server.registerTool("session_brief", {
|
|
84
|
+
title: "Daily session brief",
|
|
85
|
+
description: "Pack compact context with git diff and write to .ai/context.md in the project root. Call when starting a new AI coding session or switching tasks.",
|
|
86
|
+
inputSchema: {
|
|
87
|
+
root: z.string().optional().describe("Project root (default: server cwd)"),
|
|
88
|
+
out: z
|
|
89
|
+
.string()
|
|
90
|
+
.optional()
|
|
91
|
+
.describe("Output file relative to root (default .ai/context.md)"),
|
|
92
|
+
},
|
|
93
|
+
}, async (args) => {
|
|
94
|
+
const root = resolve(args.root ?? cwd);
|
|
95
|
+
const outRel = args.out ?? DEFAULT_OUT;
|
|
96
|
+
const result = packContext({ root, compact: true, diff: true });
|
|
97
|
+
const outPath = join(root, outRel);
|
|
98
|
+
mkdirSync(dirname(outPath), { recursive: true });
|
|
99
|
+
writeFileSync(outPath, result.markdown, "utf8");
|
|
100
|
+
recordLedger(root, "session_brief", result.stats);
|
|
101
|
+
const summary = [
|
|
102
|
+
`Wrote ${outRel} (${result.stats.lineCount} lines, ~${result.stats.estimatedTokens} tokens est.)`,
|
|
103
|
+
`Root: ${root}`,
|
|
104
|
+
"Tell the user they can @-reference this file in the next turns.",
|
|
105
|
+
].join("\n");
|
|
106
|
+
return {
|
|
107
|
+
content: [{ type: "text", text: summary + "\n\n" + result.markdown }],
|
|
108
|
+
};
|
|
109
|
+
});
|
|
110
|
+
server.registerTool("context_stats", {
|
|
111
|
+
title: "Context pack statistics",
|
|
112
|
+
description: "Estimate token cost of a context pack without returning full markdown. Useful before/after comparisons.",
|
|
113
|
+
inputSchema: {
|
|
114
|
+
compact: z.boolean().optional(),
|
|
115
|
+
diff: z.boolean().optional(),
|
|
116
|
+
root: z.string().optional(),
|
|
117
|
+
},
|
|
118
|
+
}, async (args) => {
|
|
119
|
+
const root = resolve(args.root ?? cwd);
|
|
120
|
+
const result = packContext({
|
|
121
|
+
root,
|
|
122
|
+
compact: args.compact ?? true,
|
|
123
|
+
diff: args.diff ?? false,
|
|
124
|
+
});
|
|
125
|
+
return {
|
|
126
|
+
content: [
|
|
127
|
+
{
|
|
128
|
+
type: "text",
|
|
129
|
+
text: JSON.stringify({
|
|
130
|
+
...result.stats,
|
|
131
|
+
root,
|
|
132
|
+
hint: "Use pack_context for full brief; Repomix for entire codebase.",
|
|
133
|
+
}, null, 2),
|
|
134
|
+
},
|
|
135
|
+
],
|
|
136
|
+
};
|
|
137
|
+
});
|
|
138
|
+
return server;
|
|
139
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "ctxshot-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server — lightweight daily project brief for Claude Code & Cursor (pack_context, session_brief, context_stats).",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": {
|
|
7
|
+
"ctxshot-mcp": "dist/index.js"
|
|
8
|
+
},
|
|
9
|
+
"files": [
|
|
10
|
+
"dist",
|
|
11
|
+
"README.md",
|
|
12
|
+
"LICENSE"
|
|
13
|
+
],
|
|
14
|
+
"scripts": {
|
|
15
|
+
"build": "tsc -p tsconfig.json",
|
|
16
|
+
"dev": "tsx src/index.ts",
|
|
17
|
+
"start": "node dist/index.js",
|
|
18
|
+
"inspect": "npx @modelcontextprotocol/inspector tsx src/index.ts",
|
|
19
|
+
"prepublishOnly": "npm run build && npm run test:smoke",
|
|
20
|
+
"test:smoke": "node scripts/ci-smoke.mjs"
|
|
21
|
+
},
|
|
22
|
+
"keywords": [
|
|
23
|
+
"mcp",
|
|
24
|
+
"model-context-protocol",
|
|
25
|
+
"ctxshot",
|
|
26
|
+
"cursor",
|
|
27
|
+
"claude-code",
|
|
28
|
+
"context"
|
|
29
|
+
],
|
|
30
|
+
"license": "MIT",
|
|
31
|
+
"engines": {
|
|
32
|
+
"node": ">=18"
|
|
33
|
+
},
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/G12789/ctxshot.git",
|
|
37
|
+
"directory": "packages/mcp"
|
|
38
|
+
},
|
|
39
|
+
"publishConfig": {
|
|
40
|
+
"access": "public"
|
|
41
|
+
},
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@modelcontextprotocol/sdk": "^1.12.0",
|
|
44
|
+
"ctxshot": "^0.2.0",
|
|
45
|
+
"zod": "^3.23.8"
|
|
46
|
+
},
|
|
47
|
+
"devDependencies": {
|
|
48
|
+
"@types/node": "^22.10.2",
|
|
49
|
+
"tsx": "^4.19.2",
|
|
50
|
+
"typescript": "^5.7.2"
|
|
51
|
+
}
|
|
52
|
+
}
|