@sanqianx/project-knowledge 5.1.7 → 5.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/.claude-plugin/marketplace.json +1 -1
- package/CHANGELOG.md +6 -0
- package/_site/_test/workflow-module-wiring-test.js +150 -0
- package/_site/_test/workflow-tools-test.js +218 -72
- package/_site/lib/contracts.js +3 -0
- package/_site/lib/module-bridge.js +86 -5
- package/_site/lib/server-app.js +6 -1
- package/_site/lib/workflow-tool-runtime.js +233 -43
- package/bin/project-knowledge-mcp.js +312 -282
- package/module-runtime-manifest.json +15 -15
- package/package.json +2 -2
- package/plugins/project-knowledge/.claude-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.codex-plugin/plugin.json +1 -1
- package/plugins/project-knowledge/.mcp.json +1 -1
- package/plugins/project-knowledge/skills/pk-team/SKILL.md +37 -4
|
@@ -1,282 +1,312 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
|
|
3
|
-
const packageInfo = require('../package.json');
|
|
4
|
-
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
|
|
5
|
-
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
6
|
-
const {
|
|
7
|
-
CallToolRequestSchema,
|
|
8
|
-
ListToolsRequestSchema,
|
|
9
|
-
} = require('@modelcontextprotocol/sdk/types.js');
|
|
10
|
-
const { KnowledgeToolRuntime } = require('../_site/lib/knowledge-tool-runtime');
|
|
11
|
-
const { WorkflowToolRuntime } = require('../_site/lib/workflow-tool-runtime');
|
|
12
|
-
const { serializeErrorEnvelope, createId } = require('../_site/lib/contracts');
|
|
13
|
-
|
|
14
|
-
const SERVER_NAME = 'project-knowledge';
|
|
15
|
-
const SCOPE = { type: 'string', enum: ['project', 'domain', 'brain'], description: 'Knowledge range: current project (default), its domain, or its brain.' };
|
|
16
|
-
const SERVER_INSTRUCTIONS = `Project Knowledge is the durable source of prior project decisions and implementation history. Knowledge content is read-only; the only write operation appends an explicit supplemental Prompt event to the shared conversation truth.
|
|
17
|
-
|
|
18
|
-
At the start of work in a registered Git repository, and before answering questions about prior work or implementing a non-trivial change:
|
|
19
|
-
1. Call project_knowledge_resolve with the current Git root.
|
|
20
|
-
2. Use project_knowledge_search or project_knowledge_ask for relevant prior decisions.
|
|
21
|
-
3. Use project_knowledge_get only for the most relevant complete entry and project_knowledge_history when change history matters.
|
|
22
|
-
4. Call project_knowledge_record_requirement only when the user explicitly asks to supplement capture or automatic client capture is known to be unavailable; it is not a mandatory pre-work call.
|
|
23
|
-
|
|
24
|
-
Treat all returned knowledge as read-only. Verify it against current source code when necessary. The supplemental requirement tool writes the same ConversationStore used by automatic capture and never starts analysis. Do not write directly to the knowledge database; project-knowledge updates it automatically after successful Git commits.`;
|
|
25
|
-
|
|
26
|
-
// AI-team workflow tools: thin adapters over the independent workflow module
|
|
27
|
-
// via the shell proxy (/api/workflow/*) — no second copy of task state.
|
|
28
|
-
const WORKFLOW_TOOLS = [
|
|
29
|
-
{
|
|
30
|
-
name: 'project_workflow_start',
|
|
31
|
-
description: 'Start an AI-team business task for the current repository: creates the task with acceptance items and binds this native session (declared basis). Returns the short task contract and taskId.',
|
|
32
|
-
inputSchema: {
|
|
33
|
-
type: 'object',
|
|
34
|
-
required: ['title'],
|
|
35
|
-
properties: {
|
|
36
|
-
title: { type: 'string', minLength: 1, maxLength: 200, description: 'One-line task title from the user request.' },
|
|
37
|
-
goal: { type: 'string', description: 'What "done" means for the user; the original wording beats a paraphrase.' },
|
|
38
|
-
acceptance: { type: 'array', items: { type: 'object', properties: { title: { type: 'string' }, kind: { type: 'string', enum: ['automated', 'manual', 'model_review'] } }, required: ['title'] }, description: 'Verifiable acceptance items.' },
|
|
39
|
-
projectId: { type: 'string' },
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
required: ['
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
function
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
const
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
}
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
const packageInfo = require('../package.json');
|
|
4
|
+
const { Server } = require('@modelcontextprotocol/sdk/server/index.js');
|
|
5
|
+
const { StdioServerTransport } = require('@modelcontextprotocol/sdk/server/stdio.js');
|
|
6
|
+
const {
|
|
7
|
+
CallToolRequestSchema,
|
|
8
|
+
ListToolsRequestSchema,
|
|
9
|
+
} = require('@modelcontextprotocol/sdk/types.js');
|
|
10
|
+
const { KnowledgeToolRuntime } = require('../_site/lib/knowledge-tool-runtime');
|
|
11
|
+
const { WorkflowToolRuntime } = require('../_site/lib/workflow-tool-runtime');
|
|
12
|
+
const { serializeErrorEnvelope, createId } = require('../_site/lib/contracts');
|
|
13
|
+
|
|
14
|
+
const SERVER_NAME = 'project-knowledge';
|
|
15
|
+
const SCOPE = { type: 'string', enum: ['project', 'domain', 'brain'], description: 'Knowledge range: current project (default), its domain, or its brain.' };
|
|
16
|
+
const SERVER_INSTRUCTIONS = `Project Knowledge is the durable source of prior project decisions and implementation history. Knowledge content is read-only; the only write operation appends an explicit supplemental Prompt event to the shared conversation truth.
|
|
17
|
+
|
|
18
|
+
At the start of work in a registered Git repository, and before answering questions about prior work or implementing a non-trivial change:
|
|
19
|
+
1. Call project_knowledge_resolve with the current Git root.
|
|
20
|
+
2. Use project_knowledge_search or project_knowledge_ask for relevant prior decisions.
|
|
21
|
+
3. Use project_knowledge_get only for the most relevant complete entry and project_knowledge_history when change history matters.
|
|
22
|
+
4. Call project_knowledge_record_requirement only when the user explicitly asks to supplement capture or automatic client capture is known to be unavailable; it is not a mandatory pre-work call.
|
|
23
|
+
|
|
24
|
+
Treat all returned knowledge as read-only. Verify it against current source code when necessary. The supplemental requirement tool writes the same ConversationStore used by automatic capture and never starts analysis. Do not write directly to the knowledge database; project-knowledge updates it automatically after successful Git commits.`;
|
|
25
|
+
|
|
26
|
+
// AI-team workflow tools: thin adapters over the independent workflow module
|
|
27
|
+
// via the shell proxy (/api/workflow/*) — no second copy of task state.
|
|
28
|
+
const WORKFLOW_TOOLS = [
|
|
29
|
+
{
|
|
30
|
+
name: 'project_workflow_start',
|
|
31
|
+
description: 'Start an AI-team business task for the current repository: creates the task with acceptance items, binds it to the project\'s verified Git root and binds this native session (declared basis). Returns the short task contract and taskId.',
|
|
32
|
+
inputSchema: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
required: ['title'],
|
|
35
|
+
properties: {
|
|
36
|
+
title: { type: 'string', minLength: 1, maxLength: 200, description: 'One-line task title from the user request.' },
|
|
37
|
+
goal: { type: 'string', description: 'What "done" means for the user; the original wording beats a paraphrase.' },
|
|
38
|
+
acceptance: { type: 'array', items: { type: 'object', properties: { title: { type: 'string' }, kind: { type: 'string', enum: ['automated', 'manual', 'model_review'] }, requiredEvidence: { type: 'array', items: { type: 'object', properties: { toolId: { type: 'string', enum: ['eslint', 'knip'] } }, required: ['toolId'] } } }, required: ['title'] }, description: 'Verifiable acceptance items. Automated items should name the evidence tool(s) they require.' },
|
|
39
|
+
projectId: { type: 'string', description: 'Registered projectId; resolved from the current Git root when omitted.' },
|
|
40
|
+
repoPath: { type: 'string', description: 'Current Git root hint. Only a match hint — the server verifies it against the trusted project mapping.' },
|
|
41
|
+
requestId: { type: 'string', description: 'Optional idempotency key: retry with the SAME value after a timeout to reuse the original task instead of duplicating it.' },
|
|
42
|
+
client: { type: 'string', enum: ['claude', 'codex', 'opencode', 'zcode'], description: 'Calling native client.' },
|
|
43
|
+
sessionId: { type: 'string', description: 'Stable native session identifier for event attribution.' },
|
|
44
|
+
memberId: { type: 'string', description: 'Team member that owns this task, when the caller is a named member.' },
|
|
45
|
+
workspaceIdentity: { type: 'string' },
|
|
46
|
+
executionMode: { type: 'string', enum: ['team'], description: 'Explicit team execution: only when the user clearly asks the configured team to run this task end to end. Requires an enabled project with autoDispatch; untrusted callers are degraded to a plain task.' },
|
|
47
|
+
},
|
|
48
|
+
additionalProperties: false,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'project_workflow_resume',
|
|
53
|
+
description: 'Resume an existing AI-team task by taskId: returns goal, acceptance with the current revision, confirmed decisions, verified results, remaining items and the next action.',
|
|
54
|
+
inputSchema: { type: 'object', required: ['taskId'], properties: { taskId: { type: 'string' } }, additionalProperties: false },
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: 'project_workflow_status',
|
|
58
|
+
description: 'Read one AI-team task by taskId, or the active task list (filter by projectId/status). Read-only.',
|
|
59
|
+
inputSchema: { type: 'object', properties: { taskId: { type: 'string' }, projectId: { type: 'string' }, status: { type: 'string' } }, additionalProperties: false },
|
|
60
|
+
},
|
|
61
|
+
{
|
|
62
|
+
name: 'project_workflow_checkpoint',
|
|
63
|
+
description: 'Record a checkpoint on an AI-team task. kind="fact" is a verified fact (updates nextAction); kind="candidate" is an inference kept separate.',
|
|
64
|
+
inputSchema: {
|
|
65
|
+
type: 'object',
|
|
66
|
+
required: ['taskId'],
|
|
67
|
+
properties: {
|
|
68
|
+
taskId: { type: 'string' },
|
|
69
|
+
kind: { type: 'string', enum: ['fact', 'candidate'] },
|
|
70
|
+
summary: { type: 'string' },
|
|
71
|
+
decided: { type: 'array', items: { type: 'string' } },
|
|
72
|
+
verifiedResults: { type: 'array', items: { type: 'string' } },
|
|
73
|
+
remaining: { type: 'array', items: { type: 'string' } },
|
|
74
|
+
nextAction: { type: 'string' },
|
|
75
|
+
},
|
|
76
|
+
additionalProperties: false,
|
|
77
|
+
},
|
|
78
|
+
},
|
|
79
|
+
{
|
|
80
|
+
name: 'project_workflow_request_review',
|
|
81
|
+
description: 'Reserve a review job for the task\'s current snapshot and wait (bounded) for the deterministic checks. Returns the reviewJobId, receipts and the delivery decision, or an honest "pending" answer to read later.',
|
|
82
|
+
inputSchema: {
|
|
83
|
+
type: 'object',
|
|
84
|
+
required: ['taskId'],
|
|
85
|
+
properties: {
|
|
86
|
+
taskId: { type: 'string' },
|
|
87
|
+
repoPath: { type: 'string', description: 'Current Git root hint; must match the task\'s bound root.' },
|
|
88
|
+
projectId: { type: 'string', description: 'Registered projectId for the trusted shell forward.' },
|
|
89
|
+
tools: { type: 'array', items: { type: 'string', enum: ['eslint', 'knip'] }, description: 'Check tools to run (default eslint).' },
|
|
90
|
+
included: { type: 'array', items: { type: 'string' }, description: 'Untracked source files the delivery explicitly includes.' },
|
|
91
|
+
requestId: { type: 'string', description: 'Optional idempotency key: retry with the SAME value to reuse the same review job.' },
|
|
92
|
+
waitMs: { type: 'integer', minimum: 0, maximum: 8000, description: 'Bounded wait for the job to finish (default 8000; a slow check answers pending).' },
|
|
93
|
+
note: { type: 'string', description: 'Advisory note forwarded for context; never evidence.' },
|
|
94
|
+
},
|
|
95
|
+
additionalProperties: false,
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: 'project_workflow_review_result',
|
|
100
|
+
description: 'Read the review job results for a task: receipts, rework items and the delivery decision. Pass reviewJobId to read a specific job; otherwise the task\'s latest job is used. Bounded waitMs.',
|
|
101
|
+
inputSchema: {
|
|
102
|
+
type: 'object',
|
|
103
|
+
required: ['taskId'],
|
|
104
|
+
properties: {
|
|
105
|
+
taskId: { type: 'string' },
|
|
106
|
+
reviewJobId: { type: 'string', description: 'Specific review job to read (from request_review); defaults to the task\'s latest.' },
|
|
107
|
+
waitMs: { type: 'integer', minimum: 0, maximum: 8000, description: 'Bounded wait while the job is still running (default 0).' },
|
|
108
|
+
},
|
|
109
|
+
additionalProperties: false,
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
const TOOLS = [
|
|
115
|
+
{
|
|
116
|
+
name: 'project_knowledge_resolve',
|
|
117
|
+
description: 'Resolve the registered Project Knowledge project for a Git repository. Call this first before using other knowledge tools.',
|
|
118
|
+
inputSchema: {
|
|
119
|
+
type: 'object',
|
|
120
|
+
properties: {
|
|
121
|
+
repoPath: { type: 'string', description: 'Current Git repository root or any path inside it. Defaults to the MCP process working directory.' },
|
|
122
|
+
projectId: { type: 'string', description: 'Stable projectId when it is already known.' },
|
|
123
|
+
project: { type: 'string', description: 'Optional registered project slug when it is already known.' },
|
|
124
|
+
},
|
|
125
|
+
additionalProperties: false,
|
|
126
|
+
},
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'project_knowledge_record_requirement',
|
|
130
|
+
description: 'Explicitly supplement automatic capture with one project-scoped user Prompt event. This is the only write-capable tool; it never starts analysis or writes knowledge Markdown.',
|
|
131
|
+
inputSchema: {
|
|
132
|
+
type: 'object',
|
|
133
|
+
required: ['text', 'client', 'sessionId'],
|
|
134
|
+
properties: {
|
|
135
|
+
text: { type: 'string', minLength: 1, maxLength: 131072, description: 'The user request exactly as received; do not include system prompts or tool transcripts.' },
|
|
136
|
+
client: { type: 'string', enum: ['claude', 'codex', 'opencode'] },
|
|
137
|
+
sessionId: { type: 'string', minLength: 1, maxLength: 512, description: 'Stable identifier for the current client session.' },
|
|
138
|
+
conversationId: { type: 'string', minLength: 1, maxLength: 512 },
|
|
139
|
+
projectId: { type: 'string', description: 'Stable projectId returned by project_knowledge_resolve.' },
|
|
140
|
+
repoPath: { type: 'string', description: 'Current Git root. Used for exact project resolution when projectId is omitted.' },
|
|
141
|
+
explicitCommit: { type: 'string', description: 'Optional Git commit explicitly associated with this requirement.' },
|
|
142
|
+
},
|
|
143
|
+
anyOf: [{ required: ['projectId'] }, { required: ['repoPath'] }],
|
|
144
|
+
additionalProperties: false,
|
|
145
|
+
},
|
|
146
|
+
},
|
|
147
|
+
{
|
|
148
|
+
name: 'project_knowledge_search',
|
|
149
|
+
description: 'Search the same durable knowledge and commit citations as the product UI, within the selected project, domain or brain. This tool is read-only.',
|
|
150
|
+
inputSchema: {
|
|
151
|
+
type: 'object',
|
|
152
|
+
required: ['query'],
|
|
153
|
+
properties: {
|
|
154
|
+
query: { type: 'string', minLength: 1 },
|
|
155
|
+
repoPath: { type: 'string', description: 'Current Git repository root or a path inside it.' },
|
|
156
|
+
projectId: { type: 'string', description: 'Stable projectId returned by project_knowledge_resolve.' },
|
|
157
|
+
project: { type: 'string', description: 'Optional registered project slug.' },
|
|
158
|
+
limit: { type: 'integer', minimum: 1, maximum: 30, default: 8 },
|
|
159
|
+
scope: SCOPE,
|
|
160
|
+
},
|
|
161
|
+
additionalProperties: false,
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
name: 'project_knowledge_ask',
|
|
166
|
+
description: 'Return a compact answer with citations from durable project knowledge. This tool is read-only.',
|
|
167
|
+
inputSchema: {
|
|
168
|
+
type: 'object',
|
|
169
|
+
required: ['query'],
|
|
170
|
+
properties: {
|
|
171
|
+
query: { type: 'string', minLength: 1 },
|
|
172
|
+
repoPath: { type: 'string' },
|
|
173
|
+
projectId: { type: 'string' },
|
|
174
|
+
project: { type: 'string' },
|
|
175
|
+
limit: { type: 'integer', minimum: 1, maximum: 30, default: 8 },
|
|
176
|
+
scope: SCOPE,
|
|
177
|
+
},
|
|
178
|
+
additionalProperties: false,
|
|
179
|
+
},
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
name: 'project_knowledge_get',
|
|
183
|
+
description: 'Read one complete knowledge entry selected from search results. This tool is read-only and scope checked.',
|
|
184
|
+
inputSchema: {
|
|
185
|
+
type: 'object',
|
|
186
|
+
required: ['entry'],
|
|
187
|
+
properties: {
|
|
188
|
+
entry: { type: 'string', minLength: 1, description: 'Entry identifier returned by search.' },
|
|
189
|
+
space: { type: 'string', description: 'Optional scoped knowledge space identifier.' },
|
|
190
|
+
spaceId: { type: 'string', description: 'Knowledge space identifier returned by a citation; alias of space.' },
|
|
191
|
+
scope: SCOPE,
|
|
192
|
+
repoPath: { type: 'string' },
|
|
193
|
+
projectId: { type: 'string' },
|
|
194
|
+
project: { type: 'string' },
|
|
195
|
+
},
|
|
196
|
+
additionalProperties: false,
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
{
|
|
200
|
+
name: 'project_knowledge_history',
|
|
201
|
+
description: 'Read recent durable change history for the current project and its allowed scope. This tool is read-only.',
|
|
202
|
+
inputSchema: {
|
|
203
|
+
type: 'object',
|
|
204
|
+
properties: {
|
|
205
|
+
repoPath: { type: 'string' },
|
|
206
|
+
projectId: { type: 'string' },
|
|
207
|
+
project: { type: 'string' },
|
|
208
|
+
limit: { type: 'integer', minimum: 1, maximum: 100, default: 20 },
|
|
209
|
+
scope: SCOPE,
|
|
210
|
+
},
|
|
211
|
+
additionalProperties: false,
|
|
212
|
+
},
|
|
213
|
+
},
|
|
214
|
+
...WORKFLOW_TOOLS,
|
|
215
|
+
];
|
|
216
|
+
|
|
217
|
+
function toolContent(result) {
|
|
218
|
+
return {
|
|
219
|
+
content: [{ type: 'text', text: JSON.stringify(result, null, 2) }],
|
|
220
|
+
structuredContent: result,
|
|
221
|
+
isError: false,
|
|
222
|
+
};
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
function callTool(runtime, workflowRuntimeOrName, nameOrArgs, maybeArgs) {
|
|
226
|
+
// Accept both the internal signature (runtime, workflowRuntime, name, args)
|
|
227
|
+
// and the exported legacy signature (runtime, name, args) used by tests.
|
|
228
|
+
let workflowRuntime = workflowRuntimeOrName;
|
|
229
|
+
let name = nameOrArgs;
|
|
230
|
+
let args = maybeArgs;
|
|
231
|
+
if (typeof workflowRuntimeOrName === 'string') {
|
|
232
|
+
name = workflowRuntimeOrName;
|
|
233
|
+
args = nameOrArgs;
|
|
234
|
+
workflowRuntime = null;
|
|
235
|
+
}
|
|
236
|
+
if (name === 'project_knowledge_resolve') return runtime.resolveProject(args);
|
|
237
|
+
if (name === 'project_knowledge_record_requirement') return runtime.recordRequirement(args);
|
|
238
|
+
if (name === 'project_knowledge_search') return runtime.search(args);
|
|
239
|
+
if (name === 'project_knowledge_ask') return runtime.ask(args);
|
|
240
|
+
if (name === 'project_knowledge_get') return runtime.get(args);
|
|
241
|
+
if (name === 'project_knowledge_history') return runtime.history(args);
|
|
242
|
+
if (name === 'project_workflow_start') return workflowRuntime.start(args);
|
|
243
|
+
if (name === 'project_workflow_resume') return workflowRuntime.resume(args);
|
|
244
|
+
if (name === 'project_workflow_status') return workflowRuntime.status(args);
|
|
245
|
+
if (name === 'project_workflow_checkpoint') return workflowRuntime.checkpoint(args);
|
|
246
|
+
if (name === 'project_workflow_request_review') return workflowRuntime.requestReview(args);
|
|
247
|
+
if (name === 'project_workflow_review_result') return workflowRuntime.reviewResult(args);
|
|
248
|
+
throw new Error(`unknown tool: ${name}`);
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
function createServer(options = {}) {
|
|
252
|
+
const runtime = options.runtime || new KnowledgeToolRuntime();
|
|
253
|
+
// M0-C: workflow tools reuse the knowledge runtime's registration
|
|
254
|
+
// resolution — tasks map to registered projects, never 'unknown-project'.
|
|
255
|
+
const workflowRuntime = options.workflowRuntime || new WorkflowToolRuntime({
|
|
256
|
+
resolveProject: typeof runtime.resolveProject === 'function' ? input => runtime.resolveProject(input) : null,
|
|
257
|
+
});
|
|
258
|
+
const server = new Server(
|
|
259
|
+
{ name: SERVER_NAME, version: packageInfo.version },
|
|
260
|
+
{
|
|
261
|
+
capabilities: { tools: { listChanged: false } },
|
|
262
|
+
instructions: SERVER_INSTRUCTIONS,
|
|
263
|
+
},
|
|
264
|
+
);
|
|
265
|
+
server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS }));
|
|
266
|
+
server.setRequestHandler(CallToolRequestSchema, async request => {
|
|
267
|
+
const name = String(request.params?.name || '');
|
|
268
|
+
const args = request.params?.arguments && typeof request.params.arguments === 'object'
|
|
269
|
+
? request.params.arguments
|
|
270
|
+
: {};
|
|
271
|
+
try {
|
|
272
|
+
return toolContent(await callTool(runtime, workflowRuntime, name, args));
|
|
273
|
+
} catch (error) {
|
|
274
|
+
const operationId = createId('op');
|
|
275
|
+
return {
|
|
276
|
+
content: [{ type: 'text', text: JSON.stringify(serializeErrorEnvelope(error, operationId)) }],
|
|
277
|
+
isError: true,
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
return { server, runtime, workflowRuntime };
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
async function main() {
|
|
285
|
+
const { server, runtime } = createServer();
|
|
286
|
+
const transport = new StdioServerTransport();
|
|
287
|
+
let closing = false;
|
|
288
|
+
const close = async () => {
|
|
289
|
+
if (closing) return;
|
|
290
|
+
closing = true;
|
|
291
|
+
await runtime.close();
|
|
292
|
+
await server.close();
|
|
293
|
+
};
|
|
294
|
+
process.once('SIGINT', () => close().finally(() => process.exit(0)));
|
|
295
|
+
process.once('SIGTERM', () => close().finally(() => process.exit(0)));
|
|
296
|
+
await server.connect(transport);
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
if (require.main === module) {
|
|
300
|
+
main().catch(error => {
|
|
301
|
+
process.stderr.write(`[project-knowledge-mcp] ${JSON.stringify(serializeErrorEnvelope(error, createId('op')))}\n`);
|
|
302
|
+
process.exit(1);
|
|
303
|
+
});
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
module.exports = {
|
|
307
|
+
callTool,
|
|
308
|
+
createServer,
|
|
309
|
+
SERVER_INSTRUCTIONS,
|
|
310
|
+
SERVER_NAME,
|
|
311
|
+
TOOLS,
|
|
312
|
+
};
|