@creatoria/miniapp-mcp 0.1.2 → 0.2.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/README.md +14 -3
- package/dist/app/cli/index.d.ts +6 -0
- package/dist/app/cli/index.d.ts.map +1 -0
- package/dist/app/cli/index.js +6 -0
- package/dist/app/cli/index.js.map +1 -0
- package/dist/app/index.d.ts +6 -0
- package/dist/app/index.d.ts.map +1 -0
- package/dist/app/index.js +6 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/server/index.d.ts +7 -0
- package/dist/app/server/index.d.ts.map +1 -0
- package/dist/app/server/index.js +6 -0
- package/dist/app/server/index.js.map +1 -0
- package/dist/capabilities/assert/index.d.ts +5 -0
- package/dist/capabilities/assert/index.d.ts.map +1 -0
- package/dist/capabilities/assert/index.js +5 -0
- package/dist/capabilities/assert/index.js.map +1 -0
- package/dist/capabilities/automator/index.d.ts +6 -0
- package/dist/capabilities/automator/index.d.ts.map +1 -0
- package/dist/capabilities/automator/index.js +6 -0
- package/dist/capabilities/automator/index.js.map +1 -0
- package/dist/capabilities/automator/schemas/close.d.ts +5 -0
- package/dist/capabilities/automator/schemas/close.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/close.js +11 -0
- package/dist/capabilities/automator/schemas/close.js.map +1 -0
- package/dist/capabilities/automator/schemas/connect.d.ts +11 -0
- package/dist/capabilities/automator/schemas/connect.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/connect.js +19 -0
- package/dist/capabilities/automator/schemas/connect.js.map +1 -0
- package/dist/capabilities/automator/schemas/disconnect.d.ts +5 -0
- package/dist/capabilities/automator/schemas/disconnect.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/disconnect.js +11 -0
- package/dist/capabilities/automator/schemas/disconnect.js.map +1 -0
- package/dist/capabilities/automator/schemas/index.d.ts +4 -0
- package/dist/capabilities/automator/schemas/index.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/index.js +12 -0
- package/dist/capabilities/automator/schemas/index.js.map +1 -0
- package/dist/capabilities/automator/schemas/launch.d.ts +17 -0
- package/dist/capabilities/automator/schemas/launch.d.ts.map +1 -0
- package/dist/capabilities/automator/schemas/launch.js +26 -0
- package/dist/capabilities/automator/schemas/launch.js.map +1 -0
- package/dist/capabilities/element/index.d.ts +5 -0
- package/dist/capabilities/element/index.d.ts.map +1 -0
- package/dist/capabilities/element/index.js +5 -0
- package/dist/capabilities/element/index.js.map +1 -0
- package/dist/capabilities/index.d.ts +15 -0
- package/dist/capabilities/index.d.ts.map +1 -0
- package/dist/capabilities/index.js +14 -0
- package/dist/capabilities/index.js.map +1 -0
- package/dist/capabilities/miniprogram/index.d.ts +5 -0
- package/dist/capabilities/miniprogram/index.d.ts.map +1 -0
- package/dist/capabilities/miniprogram/index.js +5 -0
- package/dist/capabilities/miniprogram/index.js.map +1 -0
- package/dist/capabilities/network/index.d.ts +5 -0
- package/dist/capabilities/network/index.d.ts.map +1 -0
- package/dist/capabilities/network/index.js +5 -0
- package/dist/capabilities/network/index.js.map +1 -0
- package/dist/capabilities/page/index.d.ts +5 -0
- package/dist/capabilities/page/index.d.ts.map +1 -0
- package/dist/capabilities/page/index.js +5 -0
- package/dist/capabilities/page/index.js.map +1 -0
- package/dist/capabilities/record/index.d.ts +5 -0
- package/dist/capabilities/record/index.d.ts.map +1 -0
- package/dist/capabilities/record/index.js +5 -0
- package/dist/capabilities/record/index.js.map +1 -0
- package/dist/capabilities/schema-registry.d.ts +4 -0
- package/dist/capabilities/schema-registry.d.ts.map +1 -0
- package/dist/capabilities/schema-registry.js +18 -0
- package/dist/capabilities/schema-registry.js.map +1 -0
- package/dist/capabilities/schema-types.d.ts +22 -0
- package/dist/capabilities/schema-types.d.ts.map +1 -0
- package/dist/capabilities/schema-types.js +2 -0
- package/dist/capabilities/schema-types.js.map +1 -0
- package/dist/capabilities/snapshot/index.d.ts +5 -0
- package/dist/capabilities/snapshot/index.d.ts.map +1 -0
- package/dist/capabilities/snapshot/index.js +5 -0
- package/dist/capabilities/snapshot/index.js.map +1 -0
- package/dist/config/loader.js +1 -1
- package/dist/config/loader.js.map +1 -1
- package/dist/core/element-ref.d.ts +1 -43
- package/dist/core/element-ref.d.ts.map +1 -1
- package/dist/core/element-ref.js +1 -212
- package/dist/core/element-ref.js.map +1 -1
- package/dist/core/logger.d.ts +1 -54
- package/dist/core/logger.d.ts.map +1 -1
- package/dist/core/logger.js +1 -377
- package/dist/core/logger.js.map +1 -1
- package/dist/core/output.d.ts +1 -20
- package/dist/core/output.d.ts.map +1 -1
- package/dist/core/output.js +1 -55
- package/dist/core/output.js.map +1 -1
- package/dist/core/report-generator.d.ts +1 -23
- package/dist/core/report-generator.d.ts.map +1 -1
- package/dist/core/report-generator.js +1 -211
- package/dist/core/report-generator.js.map +1 -1
- package/dist/core/session.d.ts +2 -82
- package/dist/core/session.d.ts.map +1 -1
- package/dist/core/session.js +2 -305
- package/dist/core/session.js.map +1 -1
- package/dist/core/timeout.d.ts +1 -48
- package/dist/core/timeout.d.ts.map +1 -1
- package/dist/core/timeout.js +1 -66
- package/dist/core/timeout.js.map +1 -1
- package/dist/core/tool-logger.d.ts +1 -82
- package/dist/core/tool-logger.d.ts.map +1 -1
- package/dist/core/tool-logger.js +1 -452
- package/dist/core/tool-logger.js.map +1 -1
- package/dist/core/validation.d.ts +1 -38
- package/dist/core/validation.d.ts.map +1 -1
- package/dist/core/validation.js +1 -92
- package/dist/core/validation.js.map +1 -1
- package/dist/runtime/element/element-ref.d.ts +44 -0
- package/dist/runtime/element/element-ref.d.ts.map +1 -0
- package/dist/runtime/element/element-ref.js +214 -0
- package/dist/runtime/element/element-ref.js.map +1 -0
- package/dist/runtime/element/index.d.ts +2 -0
- package/dist/runtime/element/index.d.ts.map +1 -0
- package/dist/runtime/element/index.js +2 -0
- package/dist/runtime/element/index.js.map +1 -0
- package/dist/runtime/index.d.ts +10 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +10 -0
- package/dist/runtime/index.js.map +1 -0
- package/dist/runtime/logging/index.d.ts +3 -0
- package/dist/runtime/logging/index.d.ts.map +1 -0
- package/dist/runtime/logging/index.js +3 -0
- package/dist/runtime/logging/index.js.map +1 -0
- package/dist/runtime/logging/logger.d.ts +55 -0
- package/dist/runtime/logging/logger.d.ts.map +1 -0
- package/dist/runtime/logging/logger.js +379 -0
- package/dist/runtime/logging/logger.js.map +1 -0
- package/dist/runtime/logging/tool-logger.d.ts +83 -0
- package/dist/runtime/logging/tool-logger.d.ts.map +1 -0
- package/dist/runtime/logging/tool-logger.js +454 -0
- package/dist/runtime/logging/tool-logger.js.map +1 -0
- package/dist/runtime/outputs/index.d.ts +3 -0
- package/dist/runtime/outputs/index.d.ts.map +1 -0
- package/dist/runtime/outputs/index.js +3 -0
- package/dist/runtime/outputs/index.js.map +1 -0
- package/dist/runtime/outputs/output-manager.d.ts +12 -0
- package/dist/runtime/outputs/output-manager.d.ts.map +1 -0
- package/dist/runtime/outputs/output-manager.js +39 -0
- package/dist/runtime/outputs/output-manager.js.map +1 -0
- package/dist/runtime/outputs/report-generator.d.ts +5 -0
- package/dist/runtime/outputs/report-generator.d.ts.map +1 -0
- package/dist/runtime/outputs/report-generator.js +175 -0
- package/dist/runtime/outputs/report-generator.js.map +1 -0
- package/dist/runtime/session/index.d.ts +3 -0
- package/dist/runtime/session/index.d.ts.map +1 -0
- package/dist/runtime/session/index.js +3 -0
- package/dist/runtime/session/index.js.map +1 -0
- package/dist/runtime/session/store.d.ts +28 -0
- package/dist/runtime/session/store.d.ts.map +1 -0
- package/dist/runtime/session/store.js +154 -0
- package/dist/runtime/session/store.js.map +1 -0
- package/dist/runtime/session/utils/cleanup.d.ts +3 -0
- package/dist/runtime/session/utils/cleanup.d.ts.map +1 -0
- package/dist/runtime/session/utils/cleanup.js +78 -0
- package/dist/runtime/session/utils/cleanup.js.map +1 -0
- package/dist/runtime/timeout/index.d.ts +2 -0
- package/dist/runtime/timeout/index.d.ts.map +1 -0
- package/dist/runtime/timeout/index.js +2 -0
- package/dist/runtime/timeout/index.js.map +1 -0
- package/dist/runtime/timeout/timeout.d.ts +49 -0
- package/dist/runtime/timeout/timeout.d.ts.map +1 -0
- package/dist/runtime/timeout/timeout.js +67 -0
- package/dist/runtime/timeout/timeout.js.map +1 -0
- package/dist/runtime/validation/index.d.ts +2 -0
- package/dist/runtime/validation/index.d.ts.map +1 -0
- package/dist/runtime/validation/index.js +2 -0
- package/dist/runtime/validation/index.js.map +1 -0
- package/dist/runtime/validation/validation.d.ts +39 -0
- package/dist/runtime/validation/validation.d.ts.map +1 -0
- package/dist/runtime/validation/validation.js +93 -0
- package/dist/runtime/validation/validation.js.map +1 -0
- package/dist/schemas/automator/miniprogram_close.json +12 -0
- package/dist/schemas/automator/miniprogram_connect.json +19 -0
- package/dist/schemas/automator/miniprogram_disconnect.json +12 -0
- package/dist/schemas/automator/miniprogram_launch.json +30 -0
- package/dist/server.js +1 -1
- package/dist/server.js.map +1 -1
- package/dist/tools/index.d.ts.map +1 -1
- package/dist/tools/index.js +3 -3
- package/dist/tools/index.js.map +1 -1
- package/dist/tools/miniprogram.d.ts +2 -1
- package/dist/tools/miniprogram.d.ts.map +1 -1
- package/dist/tools/miniprogram.js +19 -24
- package/dist/tools/miniprogram.js.map +1 -1
- package/dist/tools/page.js +2 -2
- package/dist/tools/page.js.map +1 -1
- package/docs/directory-structure-and-code-style-best-practices.md +91 -0
- package/docs/migration/README.md +34 -0
- package/docs/migration/TC-ALIGN-01-notes.md +35 -0
- package/docs/migration/runtime-skeleton.md +50 -0
- package/docs/migration/tool-schema-strategy.md +75 -0
- package/docs//345/256/214/346/225/264/345/256/236/347/216/260/346/226/271/346/241/210.md +14 -14
- package/docs//347/254/254/344/270/200/347/211/210/346/234/254/346/226/271/346/241/210.md +7 -7
- package/package.json +4 -2
- package/docs/SIMPLE_USAGE.md +0 -210
- package/docs/architecture.E-Docs.md +0 -1359
- package/docs/architecture.F1.md +0 -720
- package/docs/architecture.F2.md +0 -871
- package/docs/architecture.F3.md +0 -905
- package/docs/architecture.md +0 -90
- package/docs/charter.A1.align.yaml +0 -170
- package/docs/charter.A2.align.yaml +0 -199
- package/docs/charter.A3.align.yaml +0 -242
- package/docs/charter.A4.align.yaml +0 -227
- package/docs/charter.B1.align.yaml +0 -179
- package/docs/charter.B2.align.yaml +0 -200
- package/docs/charter.B3.align.yaml +0 -200
- package/docs/charter.B4.align.yaml +0 -188
- package/docs/charter.C1.align.yaml +0 -190
- package/docs/charter.C2.align.yaml +0 -202
- package/docs/charter.C3.align.yaml +0 -211
- package/docs/charter.C4.align.yaml +0 -263
- package/docs/charter.C5.align.yaml +0 -220
- package/docs/charter.D1.align.yaml +0 -190
- package/docs/charter.D2.align.yaml +0 -234
- package/docs/charter.D3.align.yaml +0 -206
- package/docs/charter.E-Docs.align.yaml +0 -294
- package/docs/charter.F1.align.yaml +0 -193
- package/docs/charter.F2.align.yaml +0 -248
- package/docs/charter.F3.align.yaml +0 -287
- package/docs/charter.G.align.yaml +0 -174
- package/docs/charter.align.yaml +0 -111
- package/docs/maintenance.md +0 -682
- package/docs/playwright-mcp/350/260/203/347/240/224.md +0 -53
- package/docs/setup-guide.md +0 -775
- package/docs/tasks.A1.atomize.md +0 -296
- package/docs/tasks.A2.atomize.md +0 -408
- package/docs/tasks.A3.atomize.md +0 -564
- package/docs/tasks.A4.atomize.md +0 -496
- package/docs/tasks.B1.atomize.md +0 -352
- package/docs/tasks.B2.atomize.md +0 -561
- package/docs/tasks.B3.atomize.md +0 -508
- package/docs/tasks.B4.atomize.md +0 -504
- package/docs/tasks.C1.atomize.md +0 -540
- package/docs/tasks.C2.atomize.md +0 -665
- package/docs/tasks.C3.atomize.md +0 -745
- package/docs/tasks.C4.atomize.md +0 -908
- package/docs/tasks.C5.atomize.md +0 -755
- package/docs/tasks.D1.atomize.md +0 -547
- package/docs/tasks.D2.atomize.md +0 -619
- package/docs/tasks.D3.atomize.md +0 -790
- package/docs/tasks.E-Docs.atomize.md +0 -1204
- package/docs/tasks.atomize.md +0 -189
package/docs/tasks.B1.atomize.md
DELETED
|
@@ -1,352 +0,0 @@
|
|
|
1
|
-
# Task Card: [B1] MCP Server 骨架
|
|
2
|
-
|
|
3
|
-
**Task ID**: B1
|
|
4
|
-
**Task Name**: MCP Server 骨架实现
|
|
5
|
-
**Charter**: `docs/charter.B1.align.yaml`
|
|
6
|
-
**Stage**: B (Core Architecture)
|
|
7
|
-
**Status**: ✅ COMPLETED (Retrospective)
|
|
8
|
-
**Estimated**: 2-3 hours
|
|
9
|
-
**Actual**: ~2 hours
|
|
10
|
-
**Completed**: 2025-10-02
|
|
11
|
-
|
|
12
|
-
---
|
|
13
|
-
|
|
14
|
-
## 目标 (Goal)
|
|
15
|
-
|
|
16
|
-
实现可运行的 MCP Server 入口,支持 stdio transport 连接,为后续工具注册提供基础框架。
|
|
17
|
-
|
|
18
|
-
**交付物**:
|
|
19
|
-
- ✅ `src/server.ts` (64 lines)
|
|
20
|
-
- ✅ `startServer(config)` 函数
|
|
21
|
-
- ✅ ListToolsRequestSchema 处理器
|
|
22
|
-
- ✅ 优雅关闭机制
|
|
23
|
-
|
|
24
|
-
---
|
|
25
|
-
|
|
26
|
-
## 前置条件 (Prerequisites)
|
|
27
|
-
|
|
28
|
-
- ✅ A3: 仓库结构已初始化
|
|
29
|
-
- ✅ `@modelcontextprotocol/sdk` 已安装 (v0.x.x)
|
|
30
|
-
- ✅ TypeScript 配置完成 (tsconfig.json)
|
|
31
|
-
- ✅ 了解 MCP 协议基础
|
|
32
|
-
|
|
33
|
-
---
|
|
34
|
-
|
|
35
|
-
## 实现步骤 (Steps)
|
|
36
|
-
|
|
37
|
-
### 1. 创建 Server 入口文件 ✅
|
|
38
|
-
|
|
39
|
-
**文件**: `src/server.ts`
|
|
40
|
-
|
|
41
|
-
**步骤**:
|
|
42
|
-
```typescript
|
|
43
|
-
// 导入 MCP SDK
|
|
44
|
-
import { Server } from '@modelcontextprotocol/sdk/server/index.js'
|
|
45
|
-
import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
46
|
-
import { ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js'
|
|
47
|
-
|
|
48
|
-
// 定义 startServer 函数
|
|
49
|
-
export async function startServer(config: ServerConfig = {}) {
|
|
50
|
-
// 实现...
|
|
51
|
-
}
|
|
52
|
-
```
|
|
53
|
-
|
|
54
|
-
**验证**: TypeScript 编译通过,无导入错误
|
|
55
|
-
|
|
56
|
-
---
|
|
57
|
-
|
|
58
|
-
### 2. 实例化 Server 对象 ✅
|
|
59
|
-
|
|
60
|
-
**代码**:
|
|
61
|
-
```typescript
|
|
62
|
-
const server = new Server(
|
|
63
|
-
{
|
|
64
|
-
name: 'creatoria-miniapp-mcp',
|
|
65
|
-
version: '0.1.0',
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
capabilities: {
|
|
69
|
-
tools: {},
|
|
70
|
-
},
|
|
71
|
-
}
|
|
72
|
-
)
|
|
73
|
-
```
|
|
74
|
-
|
|
75
|
-
**验证**: Server 对象创建成功
|
|
76
|
-
|
|
77
|
-
---
|
|
78
|
-
|
|
79
|
-
### 3. 集成 SessionStore ✅
|
|
80
|
-
|
|
81
|
-
**代码**:
|
|
82
|
-
```typescript
|
|
83
|
-
import { SessionStore } from './core/session.js'
|
|
84
|
-
|
|
85
|
-
const { capabilities = ['core'], outputDir, sessionTimeout } = config
|
|
86
|
-
|
|
87
|
-
const sessionStore = new SessionStore({
|
|
88
|
-
outputDir,
|
|
89
|
-
sessionTimeout,
|
|
90
|
-
})
|
|
91
|
-
```
|
|
92
|
-
|
|
93
|
-
**验证**: SessionStore 正确接收配置
|
|
94
|
-
|
|
95
|
-
---
|
|
96
|
-
|
|
97
|
-
### 4. 注册工具 ✅
|
|
98
|
-
|
|
99
|
-
**代码**:
|
|
100
|
-
```typescript
|
|
101
|
-
import { registerTools } from './tools/index.js'
|
|
102
|
-
|
|
103
|
-
const tools = registerTools(server, {
|
|
104
|
-
capabilities,
|
|
105
|
-
getSession: (sessionId) => {
|
|
106
|
-
const session = sessionStore.getOrCreate(sessionId)
|
|
107
|
-
sessionStore.updateActivity(sessionId)
|
|
108
|
-
return session
|
|
109
|
-
},
|
|
110
|
-
deleteSession: (sessionId) => sessionStore.delete(sessionId),
|
|
111
|
-
})
|
|
112
|
-
```
|
|
113
|
-
|
|
114
|
-
**验证**: tools 数组包含注册的工具
|
|
115
|
-
|
|
116
|
-
---
|
|
117
|
-
|
|
118
|
-
### 5. 实现 ListToolsRequestSchema 处理器 ✅
|
|
119
|
-
|
|
120
|
-
**代码**:
|
|
121
|
-
```typescript
|
|
122
|
-
server.setRequestHandler(ListToolsRequestSchema, async () => {
|
|
123
|
-
return { tools }
|
|
124
|
-
})
|
|
125
|
-
```
|
|
126
|
-
|
|
127
|
-
**验证**: `list_tools` 请求返回正确工具列表
|
|
128
|
-
|
|
129
|
-
---
|
|
130
|
-
|
|
131
|
-
### 6. 配置 Transport 并连接 ✅
|
|
132
|
-
|
|
133
|
-
**代码**:
|
|
134
|
-
```typescript
|
|
135
|
-
const transport = new StdioServerTransport()
|
|
136
|
-
await server.connect(transport)
|
|
137
|
-
|
|
138
|
-
console.error('WeChat Mini Program MCP Server running on stdio')
|
|
139
|
-
console.error(`Capabilities: ${capabilities.join(', ')}`)
|
|
140
|
-
console.error(`Tools registered: ${tools.length}`)
|
|
141
|
-
```
|
|
142
|
-
|
|
143
|
-
**验证**:
|
|
144
|
-
- 日志输出到 stderr
|
|
145
|
-
- Server 成功监听 stdin/stdout
|
|
146
|
-
|
|
147
|
-
---
|
|
148
|
-
|
|
149
|
-
### 7. 实现优雅关闭 ✅
|
|
150
|
-
|
|
151
|
-
**代码**:
|
|
152
|
-
```typescript
|
|
153
|
-
const cleanup = () => {
|
|
154
|
-
console.error('\nShutting down MCP server...')
|
|
155
|
-
sessionStore.dispose()
|
|
156
|
-
process.exit(0)
|
|
157
|
-
}
|
|
158
|
-
|
|
159
|
-
process.on('SIGINT', cleanup)
|
|
160
|
-
process.on('SIGTERM', cleanup)
|
|
161
|
-
```
|
|
162
|
-
|
|
163
|
-
**验证**:
|
|
164
|
-
- CTRL+C 触发 cleanup
|
|
165
|
-
- sessionStore.dispose() 被调用
|
|
166
|
-
- 进程正常退出
|
|
167
|
-
|
|
168
|
-
---
|
|
169
|
-
|
|
170
|
-
## 完成标准 (Definition of Done)
|
|
171
|
-
|
|
172
|
-
### 功能完成 ✅
|
|
173
|
-
|
|
174
|
-
- [x] `node dist/server.js` 可启动 Server
|
|
175
|
-
- [x] MCP 客户端可连接
|
|
176
|
-
- [x] `list_tools` 返回工具列表
|
|
177
|
-
- [x] SIGINT/SIGTERM 触发优雅关闭
|
|
178
|
-
- [x] sessionStore.dispose() 正确调用
|
|
179
|
-
|
|
180
|
-
### 代码质量 ✅
|
|
181
|
-
|
|
182
|
-
- [x] TypeScript 编译 0 错误
|
|
183
|
-
- [x] 无 ESLint 错误
|
|
184
|
-
- [x] 代码行数 <100 行 (实际 64 行)
|
|
185
|
-
- [x] JSDoc 注释完整
|
|
186
|
-
- [x] 符合 ESM 规范(.js 后缀)
|
|
187
|
-
|
|
188
|
-
### 测试 ✅
|
|
189
|
-
|
|
190
|
-
- [x] 手动测试:启动并连接成功
|
|
191
|
-
- [x] 集成测试:通过工具测试间接验证
|
|
192
|
-
- [x] 优雅关闭测试:CTRL+C 正常退出
|
|
193
|
-
|
|
194
|
-
### 文档 ⏳
|
|
195
|
-
|
|
196
|
-
- [x] 代码注释完整
|
|
197
|
-
- [x] README 更新(启动说明)
|
|
198
|
-
- [x] types.ts 定义 ServerConfig
|
|
199
|
-
- ⏳ charter.B1.align.yaml (追溯)
|
|
200
|
-
- ⏳ tasks.B1.atomize.md (本文档)
|
|
201
|
-
|
|
202
|
-
---
|
|
203
|
-
|
|
204
|
-
## 实现结果 (Implementation)
|
|
205
|
-
|
|
206
|
-
### 文件清单
|
|
207
|
-
|
|
208
|
-
| 文件 | 行数 | 说明 |
|
|
209
|
-
|------|------|------|
|
|
210
|
-
| `src/server.ts` | 64 | Server 入口和配置 |
|
|
211
|
-
| `src/types.ts` | +10 | ServerConfig 接口 |
|
|
212
|
-
|
|
213
|
-
### 关键代码片段
|
|
214
|
-
|
|
215
|
-
**ServerConfig 接口**:
|
|
216
|
-
```typescript
|
|
217
|
-
export interface ServerConfig {
|
|
218
|
-
capabilities?: string[]
|
|
219
|
-
outputDir?: string
|
|
220
|
-
sessionTimeout?: number
|
|
221
|
-
}
|
|
222
|
-
```
|
|
223
|
-
|
|
224
|
-
**startServer 函数签名**:
|
|
225
|
-
```typescript
|
|
226
|
-
export async function startServer(config: ServerConfig = {}): Promise<void>
|
|
227
|
-
```
|
|
228
|
-
|
|
229
|
-
### 设计决策
|
|
230
|
-
|
|
231
|
-
1. **函数式 API**
|
|
232
|
-
- 使用 `startServer()` 函数而非类封装
|
|
233
|
-
- 理由:简化使用,便于测试
|
|
234
|
-
|
|
235
|
-
2. **依赖注入**
|
|
236
|
-
- SessionStore 和 registerTools 通过参数传入
|
|
237
|
-
- 理由:解耦,提高可测试性
|
|
238
|
-
|
|
239
|
-
3. **stderr 日志**
|
|
240
|
-
- 所有日志输出到 console.error
|
|
241
|
-
- 理由:避免干扰 stdio transport
|
|
242
|
-
|
|
243
|
-
4. **优雅关闭**
|
|
244
|
-
- 监听 SIGINT/SIGTERM
|
|
245
|
-
- 理由:确保资源释放(SessionStore.dispose)
|
|
246
|
-
|
|
247
|
-
---
|
|
248
|
-
|
|
249
|
-
## 测试证据 (Test Evidence)
|
|
250
|
-
|
|
251
|
-
### 手动测试
|
|
252
|
-
|
|
253
|
-
**启动 Server**:
|
|
254
|
-
```bash
|
|
255
|
-
$ node dist/server.js
|
|
256
|
-
WeChat Mini Program MCP Server running on stdio
|
|
257
|
-
Capabilities: core
|
|
258
|
-
Tools registered: 4
|
|
259
|
-
```
|
|
260
|
-
|
|
261
|
-
**MCP 客户端连接**:
|
|
262
|
-
```bash
|
|
263
|
-
# 使用 MCP Inspector 或 Claude Desktop 连接
|
|
264
|
-
# 验证 list_tools 返回正确工具列表
|
|
265
|
-
```
|
|
266
|
-
|
|
267
|
-
**优雅关闭**:
|
|
268
|
-
```bash
|
|
269
|
-
$ node dist/server.js
|
|
270
|
-
^C
|
|
271
|
-
Shutting down MCP server...
|
|
272
|
-
Session 12345 cleaned up successfully
|
|
273
|
-
```
|
|
274
|
-
|
|
275
|
-
### 集成测试
|
|
276
|
-
|
|
277
|
-
通过后续 C1-C5 工具测试间接验证:
|
|
278
|
-
- ✅ Server 可正常启动
|
|
279
|
-
- ✅ 工具调用成功
|
|
280
|
-
- ✅ SessionStore 正常工作
|
|
281
|
-
|
|
282
|
-
---
|
|
283
|
-
|
|
284
|
-
## 已知问题 (Known Issues)
|
|
285
|
-
|
|
286
|
-
### 技术债务
|
|
287
|
-
|
|
288
|
-
1. **无单元测试** - 🟡 中优先级
|
|
289
|
-
- 原因:Server 入口代码难以单独测试
|
|
290
|
-
- 影响:依赖集成测试验证
|
|
291
|
-
- 计划:Stage G 补充集成测试
|
|
292
|
-
|
|
293
|
-
2. **仅支持 stdio** - 🟢 低优先级
|
|
294
|
-
- 原因:当前需求仅 stdio
|
|
295
|
-
- 影响:无法通过 HTTP/WebSocket 连接
|
|
296
|
-
- 计划:未来扩展 transport
|
|
297
|
-
|
|
298
|
-
### 风险
|
|
299
|
-
|
|
300
|
-
1. **MCP SDK 升级** - 🟢 低风险
|
|
301
|
-
- 缓解:锁定 SDK 版本
|
|
302
|
-
- 监控:定期检查 SDK 更新
|
|
303
|
-
|
|
304
|
-
---
|
|
305
|
-
|
|
306
|
-
## 参考资料 (References)
|
|
307
|
-
|
|
308
|
-
### 文档
|
|
309
|
-
|
|
310
|
-
- `docs/完整实现方案.md` - Server 架构设计
|
|
311
|
-
- `docs/第一版本方案.md` - MCP 集成方案
|
|
312
|
-
- `docs/charter.B1.align.yaml` - 任务对齐文档
|
|
313
|
-
|
|
314
|
-
### 代码
|
|
315
|
-
|
|
316
|
-
- `src/core/session.ts` - SessionStore 实现(B2)
|
|
317
|
-
- `src/tools/index.ts` - registerTools 函数(C5)
|
|
318
|
-
|
|
319
|
-
### 外部资源
|
|
320
|
-
|
|
321
|
-
- [MCP SDK 文档](https://github.com/anthropics/modelcontextprotocol)
|
|
322
|
-
- [MCP 协议规范](https://spec.modelcontextprotocol.io)
|
|
323
|
-
|
|
324
|
-
---
|
|
325
|
-
|
|
326
|
-
## 后续任务 (Next Steps)
|
|
327
|
-
|
|
328
|
-
### 依赖此任务的后续任务
|
|
329
|
-
|
|
330
|
-
- ✅ B2: SessionStore 实现(已完成)
|
|
331
|
-
- ✅ C5: registerTools 实现(已完成)
|
|
332
|
-
- ⏳ E3: CLI 集成(未开始)
|
|
333
|
-
|
|
334
|
-
### 改进建议
|
|
335
|
-
|
|
336
|
-
1. **性能优化**
|
|
337
|
-
- 添加启动时间监控
|
|
338
|
-
- 优化 SessionStore 初始化
|
|
339
|
-
|
|
340
|
-
2. **可观测性**
|
|
341
|
-
- 集成结构化日志
|
|
342
|
-
- 添加性能指标
|
|
343
|
-
|
|
344
|
-
3. **扩展性**
|
|
345
|
-
- 支持多种 transport
|
|
346
|
-
- 支持配置热重载
|
|
347
|
-
|
|
348
|
-
---
|
|
349
|
-
|
|
350
|
-
**任务状态**: ✅ COMPLETED
|
|
351
|
-
**代码提交**: ✅ 已提交(随 A2-B1-B2 修复)
|
|
352
|
-
**文档状态**: ⏳ RETROSPECTIVE (追溯补齐中)
|