@cg3/prior-mcp 0.5.3 → 0.5.5
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/dist/tools.js +27 -3
- package/package.json +1 -1
package/dist/tools.js
CHANGED
|
@@ -12,6 +12,30 @@ exports.expandNudgeTokens = expandNudgeTokens;
|
|
|
12
12
|
exports.registerTools = registerTools;
|
|
13
13
|
const zod_1 = require("zod");
|
|
14
14
|
const utils_js_1 = require("./utils.js");
|
|
15
|
+
/**
|
|
16
|
+
* Coerce a value that might be a string into an array.
|
|
17
|
+
* MCP clients (e.g. Claude Code) sometimes serialize arrays as strings.
|
|
18
|
+
* Call this in the handler, NOT in the Zod schema (z.union breaks JSON Schema generation).
|
|
19
|
+
*/
|
|
20
|
+
function coerceArray(val) {
|
|
21
|
+
if (val == null)
|
|
22
|
+
return undefined;
|
|
23
|
+
if (Array.isArray(val))
|
|
24
|
+
return val.map(String);
|
|
25
|
+
if (typeof val === "string") {
|
|
26
|
+
const s = val.trim();
|
|
27
|
+
if (s.startsWith("[")) {
|
|
28
|
+
try {
|
|
29
|
+
const parsed = JSON.parse(s);
|
|
30
|
+
if (Array.isArray(parsed))
|
|
31
|
+
return parsed.map(String);
|
|
32
|
+
}
|
|
33
|
+
catch { /* fall through */ }
|
|
34
|
+
}
|
|
35
|
+
return s.split(",").map((t) => t.trim()).filter(Boolean);
|
|
36
|
+
}
|
|
37
|
+
return undefined;
|
|
38
|
+
}
|
|
15
39
|
/**
|
|
16
40
|
* Expand [PRIOR:*] client-side tokens to MCP tool call syntax.
|
|
17
41
|
*/
|
|
@@ -204,15 +228,15 @@ function registerTools(server, { client }) {
|
|
|
204
228
|
creditsEarned: zod_1.z.number().optional(),
|
|
205
229
|
},
|
|
206
230
|
}, async ({ title, content, tags, model, problem, solution, errorMessages, failedApproaches, environment, effort, ttl }) => {
|
|
207
|
-
const body = { title, content, tags, model: model || "unknown" };
|
|
231
|
+
const body = { title, content, tags: coerceArray(tags) || tags, model: model || "unknown" };
|
|
208
232
|
if (problem)
|
|
209
233
|
body.problem = problem;
|
|
210
234
|
if (solution)
|
|
211
235
|
body.solution = solution;
|
|
212
236
|
if (errorMessages)
|
|
213
|
-
body.errorMessages = errorMessages;
|
|
237
|
+
body.errorMessages = coerceArray(errorMessages) || errorMessages;
|
|
214
238
|
if (failedApproaches)
|
|
215
|
-
body.failedApproaches = failedApproaches;
|
|
239
|
+
body.failedApproaches = coerceArray(failedApproaches) || failedApproaches;
|
|
216
240
|
if (environment)
|
|
217
241
|
body.environment = environment;
|
|
218
242
|
if (effort)
|
package/package.json
CHANGED