session-weaver 1.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.
- package/LICENSE +21 -0
- package/README.md +227 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +401 -0
- package/dist/index.js.map +1 -0
- package/dist/managers/context.d.ts +15 -0
- package/dist/managers/context.d.ts.map +1 -0
- package/dist/managers/context.js +209 -0
- package/dist/managers/context.js.map +1 -0
- package/dist/managers/delete.d.ts +12 -0
- package/dist/managers/delete.d.ts.map +1 -0
- package/dist/managers/delete.js +135 -0
- package/dist/managers/delete.js.map +1 -0
- package/dist/managers/handoff.d.ts +32 -0
- package/dist/managers/handoff.d.ts.map +1 -0
- package/dist/managers/handoff.js +239 -0
- package/dist/managers/handoff.js.map +1 -0
- package/dist/managers/module.d.ts +12 -0
- package/dist/managers/module.d.ts.map +1 -0
- package/dist/managers/module.js +88 -0
- package/dist/managers/module.js.map +1 -0
- package/dist/managers/pitfall.d.ts +12 -0
- package/dist/managers/pitfall.d.ts.map +1 -0
- package/dist/managers/pitfall.js +70 -0
- package/dist/managers/pitfall.js.map +1 -0
- package/dist/managers/session.d.ts +16 -0
- package/dist/managers/session.d.ts.map +1 -0
- package/dist/managers/session.js +248 -0
- package/dist/managers/session.js.map +1 -0
- package/dist/managers/storage.d.ts +46 -0
- package/dist/managers/storage.d.ts.map +1 -0
- package/dist/managers/storage.js +166 -0
- package/dist/managers/storage.js.map +1 -0
- package/dist/types.d.ts +238 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +6 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/format.d.ts +39 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +442 -0
- package/dist/utils/format.js.map +1 -0
- package/package.json +54 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Session Handoff MCP
|
|
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,227 @@
|
|
|
1
|
+
# Session Weaver
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/session-weaver)
|
|
4
|
+
|
|
5
|
+
解决 AI 编程助手(Cursor/Claude/Kiro 等)会话上下文丢失问题,实现跨会话、跨 AI 工具的上下文无缝交接。
|
|
6
|
+
|
|
7
|
+
## 核心问题
|
|
8
|
+
|
|
9
|
+
- AI 会话有 token 上限,长对话后上下文被截断
|
|
10
|
+
- 新开会话时,AI 完全不知道之前做了什么
|
|
11
|
+
- 切换不同 AI 工具时,项目上下文无法迁移
|
|
12
|
+
- 踩过的坑、做过的决策无法持久化传递
|
|
13
|
+
|
|
14
|
+
## 功能特性(7 工具架构)
|
|
15
|
+
|
|
16
|
+
| 工具 | 功能 |
|
|
17
|
+
|------|------|
|
|
18
|
+
| `load_context` | 一键加载上下文(模块 + 会话 + 踩坑),自动设置当前模块 |
|
|
19
|
+
| `save_context` | 一键保存进度(更新模块 + 创建会话 + 记录踩坑) |
|
|
20
|
+
| `list_modules` | 查看所有项目或项目内模块概览 |
|
|
21
|
+
| `list_pitfalls` | 查看踩坑记录,支持按项目/模块/标签过滤 |
|
|
22
|
+
| `delete_data` | 删除会话、踩坑、模块或整个项目 |
|
|
23
|
+
| `export_handoff` | 导出全量交接文档(Markdown + JSON) |
|
|
24
|
+
| `import_handoff` | 导入交接文档重建完整项目 |
|
|
25
|
+
|
|
26
|
+
## 快速开始
|
|
27
|
+
|
|
28
|
+
### 通过 npm 安装
|
|
29
|
+
|
|
30
|
+
```bash
|
|
31
|
+
# 全局安装
|
|
32
|
+
npm install -g session-weaver
|
|
33
|
+
|
|
34
|
+
# 或使用 npx(无需安装,自动更新)
|
|
35
|
+
npx -y session-weaver
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## 配置 MCP 客户端
|
|
39
|
+
|
|
40
|
+
### Claude Desktop
|
|
41
|
+
|
|
42
|
+
编辑 `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
43
|
+
|
|
44
|
+
```json
|
|
45
|
+
{
|
|
46
|
+
"mcpServers": {
|
|
47
|
+
"session-weaver": {
|
|
48
|
+
"command": "npx",
|
|
49
|
+
"args": ["-y", "session-weaver"]
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Cursor
|
|
56
|
+
|
|
57
|
+
编辑 `~/.cursor/mcp.json`:
|
|
58
|
+
|
|
59
|
+
```json
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"session-weaver": {
|
|
63
|
+
"command": "npx",
|
|
64
|
+
"args": ["-y", "session-weaver"]
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
### 其他 MCP 客户端
|
|
71
|
+
|
|
72
|
+
```json
|
|
73
|
+
{
|
|
74
|
+
"mcpServers": {
|
|
75
|
+
"session-weaver": {
|
|
76
|
+
"command": "npx",
|
|
77
|
+
"args": ["-y", "session-weaver"]
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
## 使用示例
|
|
84
|
+
|
|
85
|
+
### 加载上下文(开始工作)
|
|
86
|
+
|
|
87
|
+
```json
|
|
88
|
+
{
|
|
89
|
+
"project": "my-app",
|
|
90
|
+
"module": "payment",
|
|
91
|
+
"sessionsLimit": 5
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
返回:模块详情、最近会话、相关踩坑记录
|
|
96
|
+
|
|
97
|
+
### 保存进度(完成工作)
|
|
98
|
+
|
|
99
|
+
```json
|
|
100
|
+
{
|
|
101
|
+
"project": "my-app",
|
|
102
|
+
"moduleUpdate": {
|
|
103
|
+
"removeTodos": ["微信SDK接入"],
|
|
104
|
+
"addDecision": {
|
|
105
|
+
"description": "选用 Stripe 而非 Paddle",
|
|
106
|
+
"reason": "更好的 API 文档"
|
|
107
|
+
}
|
|
108
|
+
},
|
|
109
|
+
"session": {
|
|
110
|
+
"note": "完成微信支付 SDK 接入",
|
|
111
|
+
"codeState": {
|
|
112
|
+
"modifiedFiles": ["src/payment/wechat.ts"]
|
|
113
|
+
}
|
|
114
|
+
},
|
|
115
|
+
"newPitfall": {
|
|
116
|
+
"problem": "微信回调验签失败",
|
|
117
|
+
"solution": "使用微信支付平台证书,不是商户证书",
|
|
118
|
+
"tags": ["wechat", "webhook"]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
一键完成:更新模块待办、创建会话、记录踩坑
|
|
124
|
+
|
|
125
|
+
### 查看全局概览
|
|
126
|
+
|
|
127
|
+
```json
|
|
128
|
+
// 列出所有项目
|
|
129
|
+
{}
|
|
130
|
+
|
|
131
|
+
// 查看项目内模块
|
|
132
|
+
{
|
|
133
|
+
"project": "my-app"
|
|
134
|
+
}
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
### 导出让其他 AI 接手
|
|
138
|
+
|
|
139
|
+
```json
|
|
140
|
+
{
|
|
141
|
+
"project": "my-app"
|
|
142
|
+
}
|
|
143
|
+
```
|
|
144
|
+
|
|
145
|
+
生成包含全量数据的 Markdown 文档(人类可读 + 机器可解析)
|
|
146
|
+
|
|
147
|
+
### 导入交接文档
|
|
148
|
+
|
|
149
|
+
```json
|
|
150
|
+
{
|
|
151
|
+
"handoffId": "handoff-xxx"
|
|
152
|
+
}
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
或
|
|
156
|
+
|
|
157
|
+
```json
|
|
158
|
+
{
|
|
159
|
+
"markdown": "# 🤖 AI 会话交接文档..."
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
## 数据存储
|
|
164
|
+
|
|
165
|
+
所有数据存储在 `~/.session-handoff/` 目录:
|
|
166
|
+
|
|
167
|
+
```
|
|
168
|
+
~/.session-handoff/
|
|
169
|
+
├── projects/
|
|
170
|
+
│ └── {project-name}.json # 单文件 = 项目 + 模块 + 会话 + 踩坑
|
|
171
|
+
└── handoffs/
|
|
172
|
+
└── {handoff-id}.md # 交接文档
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
### 单文件结构
|
|
176
|
+
|
|
177
|
+
每个项目一个 JSON 文件:
|
|
178
|
+
|
|
179
|
+
```json
|
|
180
|
+
{
|
|
181
|
+
"project": "my-app",
|
|
182
|
+
"currentModule": "payment",
|
|
183
|
+
"modules": {
|
|
184
|
+
"payment": {
|
|
185
|
+
"name": "payment",
|
|
186
|
+
"status": "active",
|
|
187
|
+
"summary": "支付宝完成,微信待接入",
|
|
188
|
+
"todos": ["退款接口"],
|
|
189
|
+
"decisions": [...],
|
|
190
|
+
"techStack": ["stripe", "alipay-sdk"]
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
"sessions": [...],
|
|
194
|
+
"pitfalls": [...]
|
|
195
|
+
}
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
**特点:**
|
|
199
|
+
- 单文件原子写入(临时文件 + 重命名,保证数据完整性)
|
|
200
|
+
- 无需数据库,纯 JSON 文件,可手动编辑
|
|
201
|
+
- 易于备份和版本控制
|
|
202
|
+
|
|
203
|
+
## 上下文基于架构
|
|
204
|
+
|
|
205
|
+
```
|
|
206
|
+
传统方式: Session Weaver:
|
|
207
|
+
读取所有 session 文件 → 读取单文件
|
|
208
|
+
内存过滤排序 → 按模块预筛选
|
|
209
|
+
返回全部数据 → 返回精准上下文
|
|
210
|
+
AI 自行找关联 → currentModule 自动记忆
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
## 技术栈
|
|
214
|
+
|
|
215
|
+
- Node.js >= 18 / TypeScript
|
|
216
|
+
- MCP SDK
|
|
217
|
+
- nanoid (ID 生成)
|
|
218
|
+
- zod (参数校验)
|
|
219
|
+
|
|
220
|
+
## 许可证
|
|
221
|
+
|
|
222
|
+
MIT
|
|
223
|
+
|
|
224
|
+
## 相关链接
|
|
225
|
+
|
|
226
|
+
- npm: https://www.npmjs.com/package/session-weaver
|
|
227
|
+
- MCP 协议: https://modelcontextprotocol.io
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAEA;;;GAGG"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,401 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
/**
|
|
3
|
+
* Session Handoff MCP Server
|
|
4
|
+
* 7工具完整版 - 上下文基于架构
|
|
5
|
+
*/
|
|
6
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
7
|
+
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
|
|
8
|
+
import { CallToolRequestSchema, ListToolsRequestSchema, ErrorCode, McpError } from '@modelcontextprotocol/sdk/types.js';
|
|
9
|
+
import { z } from 'zod';
|
|
10
|
+
import { StorageManager } from './managers/storage.js';
|
|
11
|
+
import { ContextManager } from './managers/context.js';
|
|
12
|
+
import { ModuleManager } from './managers/module.js';
|
|
13
|
+
import { PitfallManager } from './managers/pitfall.js';
|
|
14
|
+
import { HandoffManager } from './managers/handoff.js';
|
|
15
|
+
import { DeleteManager } from './managers/delete.js';
|
|
16
|
+
// ============ Zod 校验 Schema ============
|
|
17
|
+
// Tool 1: load_context
|
|
18
|
+
const LoadContextSchema = z.object({
|
|
19
|
+
project: z.string().min(1, '项目名称不能为空'),
|
|
20
|
+
module: z.string().optional(),
|
|
21
|
+
includePitfalls: z.boolean().optional(),
|
|
22
|
+
sessionsLimit: z.number().int().min(1).max(50).optional()
|
|
23
|
+
});
|
|
24
|
+
// Tool 2: save_context
|
|
25
|
+
const SaveContextSchema = z.object({
|
|
26
|
+
project: z.string().min(1, '项目名称不能为空'),
|
|
27
|
+
module: z.string().optional(),
|
|
28
|
+
moduleUpdate: z.object({
|
|
29
|
+
status: z.enum(['active', 'completed', 'archived']).optional(),
|
|
30
|
+
summary: z.string().optional(),
|
|
31
|
+
todos: z.array(z.string()).optional(),
|
|
32
|
+
addTodos: z.array(z.string()).optional(),
|
|
33
|
+
removeTodos: z.array(z.string()).optional(),
|
|
34
|
+
addDecision: z.object({
|
|
35
|
+
description: z.string(),
|
|
36
|
+
reason: z.string().optional()
|
|
37
|
+
}).optional(),
|
|
38
|
+
techStack: z.array(z.string()).optional()
|
|
39
|
+
}).optional(),
|
|
40
|
+
session: z.object({
|
|
41
|
+
note: z.string().min(1, '会话备注不能为空'),
|
|
42
|
+
codeState: z.object({
|
|
43
|
+
modifiedFiles: z.array(z.string()),
|
|
44
|
+
currentBranch: z.string().optional(),
|
|
45
|
+
uncommittedChanges: z.string().optional()
|
|
46
|
+
}).optional(),
|
|
47
|
+
todos: z.array(z.object({
|
|
48
|
+
task: z.string(),
|
|
49
|
+
priority: z.enum(['high', 'medium', 'low']).optional(),
|
|
50
|
+
done: z.boolean().optional()
|
|
51
|
+
})).optional(),
|
|
52
|
+
decisions: z.array(z.object({
|
|
53
|
+
description: z.string(),
|
|
54
|
+
reason: z.string(),
|
|
55
|
+
alternatives: z.array(z.string()).optional()
|
|
56
|
+
})).optional(),
|
|
57
|
+
techStack: z.array(z.string()).optional()
|
|
58
|
+
}).optional(),
|
|
59
|
+
newPitfall: z.object({
|
|
60
|
+
problem: z.string().min(1, '问题描述不能为空'),
|
|
61
|
+
solution: z.string().min(1, '解决方案不能为空'),
|
|
62
|
+
tags: z.array(z.string()).optional()
|
|
63
|
+
}).optional()
|
|
64
|
+
});
|
|
65
|
+
// Tool 3: list_modules
|
|
66
|
+
const ListModulesSchema = z.object({
|
|
67
|
+
project: z.string().optional(),
|
|
68
|
+
status: z.enum(['active', 'completed', 'archived']).optional(),
|
|
69
|
+
includeArchived: z.boolean().optional(),
|
|
70
|
+
withStats: z.boolean().optional()
|
|
71
|
+
});
|
|
72
|
+
// Tool 4: list_pitfalls
|
|
73
|
+
const ListPitfallsSchema = z.object({
|
|
74
|
+
project: z.string().optional(),
|
|
75
|
+
module: z.string().optional(),
|
|
76
|
+
tags: z.array(z.string()).optional(),
|
|
77
|
+
limit: z.number().int().min(1).max(100).optional()
|
|
78
|
+
});
|
|
79
|
+
// Tool 5: delete_data
|
|
80
|
+
const DeleteDataSchema = z.object({
|
|
81
|
+
project: z.string().min(1, '项目名称不能为空'),
|
|
82
|
+
sessionId: z.string().optional(),
|
|
83
|
+
pitfallId: z.string().optional(),
|
|
84
|
+
moduleName: z.string().optional(),
|
|
85
|
+
entireProject: z.boolean().optional()
|
|
86
|
+
});
|
|
87
|
+
// Tool 6: export_handoff
|
|
88
|
+
const ExportHandoffSchema = z.object({
|
|
89
|
+
project: z.string().min(1, '项目名称不能为空'),
|
|
90
|
+
includeModules: z.boolean().optional(),
|
|
91
|
+
includeSessions: z.boolean().optional(),
|
|
92
|
+
includePitfalls: z.boolean().optional()
|
|
93
|
+
});
|
|
94
|
+
// Tool 7: import_handoff
|
|
95
|
+
const ImportHandoffSchema = z.object({
|
|
96
|
+
handoffId: z.string().optional(),
|
|
97
|
+
markdown: z.string().optional(),
|
|
98
|
+
projectName: z.string().optional(),
|
|
99
|
+
aiTool: z.string().optional()
|
|
100
|
+
}).refine(data => data.handoffId || data.markdown, {
|
|
101
|
+
message: '必须提供 handoffId 或 markdown'
|
|
102
|
+
});
|
|
103
|
+
// ============ 主服务器类 ============
|
|
104
|
+
class SessionHandoffServer {
|
|
105
|
+
server;
|
|
106
|
+
storage;
|
|
107
|
+
contextManager;
|
|
108
|
+
moduleManager;
|
|
109
|
+
pitfallManager;
|
|
110
|
+
handoffManager;
|
|
111
|
+
deleteManager;
|
|
112
|
+
constructor() {
|
|
113
|
+
this.server = new Server({
|
|
114
|
+
name: 'session-handoff-mcp',
|
|
115
|
+
version: '2.0.0'
|
|
116
|
+
}, {
|
|
117
|
+
capabilities: {
|
|
118
|
+
tools: {}
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
this.storage = new StorageManager();
|
|
122
|
+
this.contextManager = new ContextManager(this.storage);
|
|
123
|
+
this.moduleManager = new ModuleManager(this.storage);
|
|
124
|
+
this.pitfallManager = new PitfallManager(this.storage);
|
|
125
|
+
this.handoffManager = new HandoffManager(this.storage);
|
|
126
|
+
this.deleteManager = new DeleteManager(this.storage);
|
|
127
|
+
this.setupHandlers();
|
|
128
|
+
}
|
|
129
|
+
setupHandlers() {
|
|
130
|
+
// 列出可用工具
|
|
131
|
+
this.server.setRequestHandler(ListToolsRequestSchema, async () => ({
|
|
132
|
+
tools: [
|
|
133
|
+
{
|
|
134
|
+
name: 'load_context',
|
|
135
|
+
description: '加载指定项目的上下文。返回当前模块详情、最近会话、相关踩坑记录。自动设置 currentModule。',
|
|
136
|
+
inputSchema: {
|
|
137
|
+
type: 'object',
|
|
138
|
+
properties: {
|
|
139
|
+
project: { type: 'string', description: '项目名称(必填)' },
|
|
140
|
+
module: { type: 'string', description: '模块名称(可选,默认使用 currentModule)' },
|
|
141
|
+
includePitfalls: { type: 'boolean', description: '是否包含踩坑记录(默认 true)' },
|
|
142
|
+
sessionsLimit: { type: 'number', description: '返回最近N条会话(默认 3,最大 50)' }
|
|
143
|
+
},
|
|
144
|
+
required: ['project']
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'save_context',
|
|
149
|
+
description: '保存上下文。可同时更新模块、创建会话、记录踩坑。所有参数可选,按需传递。',
|
|
150
|
+
inputSchema: {
|
|
151
|
+
type: 'object',
|
|
152
|
+
properties: {
|
|
153
|
+
project: { type: 'string', description: '项目名称(必填)' },
|
|
154
|
+
module: { type: 'string', description: '模块名称(可选,默认 currentModule)' },
|
|
155
|
+
moduleUpdate: {
|
|
156
|
+
type: 'object',
|
|
157
|
+
description: '模块层更新(可选)',
|
|
158
|
+
properties: {
|
|
159
|
+
status: { type: 'string', enum: ['active', 'completed', 'archived'] },
|
|
160
|
+
summary: { type: 'string' },
|
|
161
|
+
todos: { type: 'array', items: { type: 'string' } },
|
|
162
|
+
addTodos: { type: 'array', items: { type: 'string' } },
|
|
163
|
+
removeTodos: { type: 'array', items: { type: 'string' } },
|
|
164
|
+
addDecision: {
|
|
165
|
+
type: 'object',
|
|
166
|
+
properties: {
|
|
167
|
+
description: { type: 'string' },
|
|
168
|
+
reason: { type: 'string' }
|
|
169
|
+
}
|
|
170
|
+
},
|
|
171
|
+
techStack: { type: 'array', items: { type: 'string' } }
|
|
172
|
+
}
|
|
173
|
+
},
|
|
174
|
+
session: {
|
|
175
|
+
type: 'object',
|
|
176
|
+
description: '创建新会话(可选)',
|
|
177
|
+
properties: {
|
|
178
|
+
note: { type: 'string', description: '会话摘要' },
|
|
179
|
+
codeState: {
|
|
180
|
+
type: 'object',
|
|
181
|
+
properties: {
|
|
182
|
+
modifiedFiles: { type: 'array', items: { type: 'string' } },
|
|
183
|
+
currentBranch: { type: 'string' },
|
|
184
|
+
uncommittedChanges: { type: 'string' }
|
|
185
|
+
}
|
|
186
|
+
},
|
|
187
|
+
todos: {
|
|
188
|
+
type: 'array',
|
|
189
|
+
items: {
|
|
190
|
+
type: 'object',
|
|
191
|
+
properties: {
|
|
192
|
+
task: { type: 'string' },
|
|
193
|
+
priority: { type: 'string', enum: ['high', 'medium', 'low'] },
|
|
194
|
+
done: { type: 'boolean' }
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
},
|
|
198
|
+
decisions: {
|
|
199
|
+
type: 'array',
|
|
200
|
+
items: {
|
|
201
|
+
type: 'object',
|
|
202
|
+
properties: {
|
|
203
|
+
description: { type: 'string' },
|
|
204
|
+
reason: { type: 'string' },
|
|
205
|
+
alternatives: { type: 'array', items: { type: 'string' } }
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
},
|
|
209
|
+
techStack: { type: 'array', items: { type: 'string' } }
|
|
210
|
+
},
|
|
211
|
+
required: ['note']
|
|
212
|
+
},
|
|
213
|
+
newPitfall: {
|
|
214
|
+
type: 'object',
|
|
215
|
+
description: '记录新踩坑(可选)',
|
|
216
|
+
properties: {
|
|
217
|
+
problem: { type: 'string' },
|
|
218
|
+
solution: { type: 'string' },
|
|
219
|
+
tags: { type: 'array', items: { type: 'string' } }
|
|
220
|
+
},
|
|
221
|
+
required: ['problem', 'solution']
|
|
222
|
+
}
|
|
223
|
+
},
|
|
224
|
+
required: ['project']
|
|
225
|
+
}
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: 'list_modules',
|
|
229
|
+
description: '列出项目或模块。不传 project 时列出所有项目;传 project 时列出该项目内模块。',
|
|
230
|
+
inputSchema: {
|
|
231
|
+
type: 'object',
|
|
232
|
+
properties: {
|
|
233
|
+
project: { type: 'string', description: '项目名称(可选,不传则列出所有项目)' },
|
|
234
|
+
status: { type: 'string', enum: ['active', 'completed', 'archived'], description: '按状态过滤模块' },
|
|
235
|
+
includeArchived: { type: 'boolean', description: '是否包含已归档模块(默认 false)' },
|
|
236
|
+
withStats: { type: 'boolean', description: '是否包含统计数据(默认 true)' }
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
},
|
|
240
|
+
{
|
|
241
|
+
name: 'list_pitfalls',
|
|
242
|
+
description: '列出踩坑记录。支持按项目、模块、标签过滤。',
|
|
243
|
+
inputSchema: {
|
|
244
|
+
type: 'object',
|
|
245
|
+
properties: {
|
|
246
|
+
project: { type: 'string', description: '项目名称(可选)' },
|
|
247
|
+
module: { type: 'string', description: '模块名称(可选)' },
|
|
248
|
+
tags: { type: 'array', items: { type: 'string' }, description: '标签过滤' },
|
|
249
|
+
limit: { type: 'number', description: '返回数量限制(默认 20)' }
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
},
|
|
253
|
+
{
|
|
254
|
+
name: 'delete_data',
|
|
255
|
+
description: '删除数据。支持删除会话、踩坑、模块或整个项目。参数互斥,只能指定一种删除类型。',
|
|
256
|
+
inputSchema: {
|
|
257
|
+
type: 'object',
|
|
258
|
+
properties: {
|
|
259
|
+
project: { type: 'string', description: '项目名称(必填)' },
|
|
260
|
+
sessionId: { type: 'string', description: '删除指定会话' },
|
|
261
|
+
pitfallId: { type: 'string', description: '删除指定踩坑' },
|
|
262
|
+
moduleName: { type: 'string', description: '删除指定模块(会级联删除关联的会话和踩坑)' },
|
|
263
|
+
entireProject: { type: 'boolean', description: '删除整个项目' }
|
|
264
|
+
},
|
|
265
|
+
required: ['project']
|
|
266
|
+
}
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: 'export_handoff',
|
|
270
|
+
description: '导出让其他 AI 使用的交接文档(Markdown 格式)。包含项目的全量数据。',
|
|
271
|
+
inputSchema: {
|
|
272
|
+
type: 'object',
|
|
273
|
+
properties: {
|
|
274
|
+
project: { type: 'string', description: '项目名称(必填)' },
|
|
275
|
+
includeModules: { type: 'boolean', description: '是否包含模块详情(默认 true)' },
|
|
276
|
+
includeSessions: { type: 'boolean', description: '是否包含会话历史(默认 true)' },
|
|
277
|
+
includePitfalls: { type: 'boolean', description: '是否包含踩坑记录(默认 true)' }
|
|
278
|
+
},
|
|
279
|
+
required: ['project']
|
|
280
|
+
}
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: 'import_handoff',
|
|
284
|
+
description: '从交接文档导入项目上下文。',
|
|
285
|
+
inputSchema: {
|
|
286
|
+
type: 'object',
|
|
287
|
+
properties: {
|
|
288
|
+
handoffId: { type: 'string', description: '交接文档 ID(与 markdown 二选一)' },
|
|
289
|
+
markdown: { type: 'string', description: '交接文档内容(与 handoffId 二选一)' },
|
|
290
|
+
projectName: { type: 'string', description: '导入后的项目名(可选,默认使用文档中的)' },
|
|
291
|
+
aiTool: { type: 'string', description: '来源 AI 工具名' }
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
]
|
|
296
|
+
}));
|
|
297
|
+
// 处理工具调用
|
|
298
|
+
this.server.setRequestHandler(CallToolRequestSchema, async (request) => {
|
|
299
|
+
const { name, arguments: args } = request.params;
|
|
300
|
+
try {
|
|
301
|
+
switch (name) {
|
|
302
|
+
case 'load_context': {
|
|
303
|
+
const input = LoadContextSchema.parse(args);
|
|
304
|
+
const result = await this.contextManager.loadContext(input);
|
|
305
|
+
if (!result) {
|
|
306
|
+
return {
|
|
307
|
+
content: [{ type: 'text', text: JSON.stringify({ error: '项目或模块不存在' }, null, 2) }],
|
|
308
|
+
isError: true
|
|
309
|
+
};
|
|
310
|
+
}
|
|
311
|
+
return {
|
|
312
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
|
|
313
|
+
};
|
|
314
|
+
}
|
|
315
|
+
case 'save_context': {
|
|
316
|
+
const input = SaveContextSchema.parse(args);
|
|
317
|
+
const result = await this.contextManager.saveContext(input);
|
|
318
|
+
if (!result) {
|
|
319
|
+
return {
|
|
320
|
+
content: [{ type: 'text', text: JSON.stringify({ error: '保存失败' }, null, 2) }],
|
|
321
|
+
isError: true
|
|
322
|
+
};
|
|
323
|
+
}
|
|
324
|
+
return {
|
|
325
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
case 'list_modules': {
|
|
329
|
+
const input = ListModulesSchema.parse(args);
|
|
330
|
+
const result = await this.moduleManager.listModules(input);
|
|
331
|
+
return {
|
|
332
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
|
|
333
|
+
};
|
|
334
|
+
}
|
|
335
|
+
case 'list_pitfalls': {
|
|
336
|
+
const input = ListPitfallsSchema.parse(args);
|
|
337
|
+
const result = await this.pitfallManager.listPitfalls(input);
|
|
338
|
+
return {
|
|
339
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
|
|
340
|
+
};
|
|
341
|
+
}
|
|
342
|
+
case 'delete_data': {
|
|
343
|
+
const input = DeleteDataSchema.parse(args);
|
|
344
|
+
const result = await this.deleteManager.deleteData(input);
|
|
345
|
+
return {
|
|
346
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
|
|
347
|
+
};
|
|
348
|
+
}
|
|
349
|
+
case 'export_handoff': {
|
|
350
|
+
const input = ExportHandoffSchema.parse(args);
|
|
351
|
+
const result = await this.handoffManager.exportHandoff(input);
|
|
352
|
+
if (!result) {
|
|
353
|
+
return {
|
|
354
|
+
content: [{ type: 'text', text: JSON.stringify({ error: '项目不存在' }, null, 2) }],
|
|
355
|
+
isError: true
|
|
356
|
+
};
|
|
357
|
+
}
|
|
358
|
+
return {
|
|
359
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
case 'import_handoff': {
|
|
363
|
+
const input = ImportHandoffSchema.parse(args);
|
|
364
|
+
const result = await this.handoffManager.importHandoff(input);
|
|
365
|
+
return {
|
|
366
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }]
|
|
367
|
+
};
|
|
368
|
+
}
|
|
369
|
+
default:
|
|
370
|
+
throw new McpError(ErrorCode.MethodNotFound, `未知工具: ${name}`);
|
|
371
|
+
}
|
|
372
|
+
}
|
|
373
|
+
catch (error) {
|
|
374
|
+
if (error instanceof z.ZodError) {
|
|
375
|
+
const issues = error.issues.map(i => `${i.path.join('.')}: ${i.message}`).join('; ');
|
|
376
|
+
return {
|
|
377
|
+
content: [{ type: 'text', text: JSON.stringify({ error: `参数校验失败: ${issues}` }, null, 2) }],
|
|
378
|
+
isError: true
|
|
379
|
+
};
|
|
380
|
+
}
|
|
381
|
+
if (error instanceof Error) {
|
|
382
|
+
return {
|
|
383
|
+
content: [{ type: 'text', text: JSON.stringify({ error: error.message }, null, 2) }],
|
|
384
|
+
isError: true
|
|
385
|
+
};
|
|
386
|
+
}
|
|
387
|
+
throw error;
|
|
388
|
+
}
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
async run() {
|
|
392
|
+
const transport = new StdioServerTransport();
|
|
393
|
+
await this.server.connect(transport);
|
|
394
|
+
console.error('Session Handoff MCP Server v2.0.0 running on stdio');
|
|
395
|
+
console.error(`Storage directory: ${this.storage.getBaseDir()}`);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
// 启动服务器
|
|
399
|
+
const server = new SessionHandoffServer();
|
|
400
|
+
server.run().catch(console.error);
|
|
401
|
+
//# sourceMappingURL=index.js.map
|