dc-cli-mcp 0.0.1-alpha.4 → 0.0.1-alpha.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/es/index.mjs +63 -63
- package/es/test.mjs +4 -1
- package/package.json +3 -2
package/es/index.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { P as Q, L as q, A as ee, I as te, a as se, S as re, m as ie, g as C, i as ae, b as ne, c as oe, d as
|
|
3
|
-
import { ZodOptional as Te, z as
|
|
2
|
+
import { P as Q, L as q, A as ee, I as te, a as se, S as re, m as ie, g as C, i as ae, b as ne, c as oe, d as le, E as ce, C as de, e as ue, f as M, M as p, h as m, j as pe, s as E, k as me, l as $, n as he, o as fe, p as j, q as _, t as O, r as P, u as I, v as x, w as ge, x as we, y as V, z, R as A, B as N, G as U, D as R, F as be, H as _e, J as ve, K as Re, N as Se } from "./stdio-ClkAdHuL.js";
|
|
3
|
+
import { ZodOptional as Te, z as T } from "zod";
|
|
4
4
|
import B from "node:process";
|
|
5
|
-
import { injectInfo as
|
|
5
|
+
import { injectInfo as S, FormNameEnum as y } from "create-done-coding";
|
|
6
6
|
import { log as L, params2cliParams as ye, initEnvConfig as Ce, EnvConfigCallModeEnum as ke } from "@done-coding/cli-utils";
|
|
7
7
|
import { execSync as Ee } from "node:child_process";
|
|
8
8
|
class Pe {
|
|
@@ -87,8 +87,8 @@ class Ie extends Q {
|
|
|
87
87
|
var s;
|
|
88
88
|
return (s = this.oninitialized) == null ? void 0 : s.call(this);
|
|
89
89
|
}), this._capabilities.logging && this.setRequestHandler(re, async (s, r) => {
|
|
90
|
-
var
|
|
91
|
-
const a = r.sessionId || ((
|
|
90
|
+
var c;
|
|
91
|
+
const a = r.sessionId || ((c = r.requestInfo) == null ? void 0 : c.headers["mcp-session-id"]) || void 0, { level: i } = s.params, n = q.safeParse(i);
|
|
92
92
|
return n.success && this._loggingLevels.set(a, n.data), {};
|
|
93
93
|
});
|
|
94
94
|
}
|
|
@@ -124,22 +124,22 @@ class Ie extends Q {
|
|
|
124
124
|
throw new Error("Schema is missing a method literal");
|
|
125
125
|
let a;
|
|
126
126
|
if (ae(r)) {
|
|
127
|
-
const
|
|
128
|
-
a = (
|
|
127
|
+
const c = r, l = (n = c._zod) == null ? void 0 : n.def;
|
|
128
|
+
a = (l == null ? void 0 : l.value) ?? c.value;
|
|
129
129
|
} else {
|
|
130
|
-
const
|
|
131
|
-
a = (
|
|
130
|
+
const c = r, l = c._def;
|
|
131
|
+
a = (l == null ? void 0 : l.value) ?? c.value;
|
|
132
132
|
}
|
|
133
133
|
if (typeof a != "string")
|
|
134
134
|
throw new Error("Schema method literal must be a string");
|
|
135
135
|
if (a === "tools/call") {
|
|
136
|
-
const
|
|
137
|
-
const d = E($,
|
|
136
|
+
const c = async (l, u) => {
|
|
137
|
+
const d = E($, l);
|
|
138
138
|
if (!d.success) {
|
|
139
139
|
const f = d.error instanceof Error ? d.error.message : String(d.error);
|
|
140
140
|
throw new p(m.InvalidParams, `Invalid tools/call request: ${f}`);
|
|
141
141
|
}
|
|
142
|
-
const { params: w } = d.data, h = await Promise.resolve(t(
|
|
142
|
+
const { params: w } = d.data, h = await Promise.resolve(t(l, u));
|
|
143
143
|
if (w.task) {
|
|
144
144
|
const f = E(he, h);
|
|
145
145
|
if (!f.success) {
|
|
@@ -155,7 +155,7 @@ class Ie extends Q {
|
|
|
155
155
|
}
|
|
156
156
|
return b.data;
|
|
157
157
|
};
|
|
158
|
-
return super.setRequestHandler(e,
|
|
158
|
+
return super.setRequestHandler(e, c);
|
|
159
159
|
}
|
|
160
160
|
return super.setRequestHandler(e, t);
|
|
161
161
|
}
|
|
@@ -249,7 +249,7 @@ class Ie extends Q {
|
|
|
249
249
|
async _oninitialize(e) {
|
|
250
250
|
const t = e.params.protocolVersion;
|
|
251
251
|
return this._clientCapabilities = e.params.capabilities, this._clientVersion = e.params.clientInfo, {
|
|
252
|
-
protocolVersion: me.includes(t) ? t :
|
|
252
|
+
protocolVersion: me.includes(t) ? t : le,
|
|
253
253
|
capabilities: this.getCapabilities(),
|
|
254
254
|
serverInfo: this._serverInfo,
|
|
255
255
|
...this._instructions && { instructions: this._instructions }
|
|
@@ -271,7 +271,7 @@ class Ie extends Q {
|
|
|
271
271
|
return this._capabilities;
|
|
272
272
|
}
|
|
273
273
|
async ping() {
|
|
274
|
-
return this.request({ method: "ping" },
|
|
274
|
+
return this.request({ method: "ping" }, ce);
|
|
275
275
|
}
|
|
276
276
|
// Implementation
|
|
277
277
|
async createMessage(e, t) {
|
|
@@ -279,7 +279,7 @@ class Ie extends Q {
|
|
|
279
279
|
if ((e.tools || e.toolChoice) && !((r = (s = this._clientCapabilities) == null ? void 0 : s.sampling) != null && r.tools))
|
|
280
280
|
throw new Error("Client does not support sampling tools capability.");
|
|
281
281
|
if (e.messages.length > 0) {
|
|
282
|
-
const a = e.messages[e.messages.length - 1], i = Array.isArray(a.content) ? a.content : [a.content], n = i.some((d) => d.type === "tool_result"),
|
|
282
|
+
const a = e.messages[e.messages.length - 1], i = Array.isArray(a.content) ? a.content : [a.content], n = i.some((d) => d.type === "tool_result"), c = e.messages.length > 1 ? e.messages[e.messages.length - 2] : void 0, l = c ? Array.isArray(c.content) ? c.content : [c.content] : [], u = l.some((d) => d.type === "tool_use");
|
|
283
283
|
if (n) {
|
|
284
284
|
if (i.some((d) => d.type !== "tool_result"))
|
|
285
285
|
throw new Error("The last message must contain only tool_result content if any is present");
|
|
@@ -287,7 +287,7 @@ class Ie extends Q {
|
|
|
287
287
|
throw new Error("tool_result blocks are not matching any tool_use from the previous message");
|
|
288
288
|
}
|
|
289
289
|
if (u) {
|
|
290
|
-
const d = new Set(
|
|
290
|
+
const d = new Set(l.filter((h) => h.type === "tool_use").map((h) => h.id)), w = new Set(i.filter((h) => h.type === "tool_result").map((h) => h.toolUseId));
|
|
291
291
|
if (d.size !== w.size || ![...d].every((h) => w.has(h)))
|
|
292
292
|
throw new Error("ids of tool_result blocks and tool_use blocks from previous message do not match");
|
|
293
293
|
}
|
|
@@ -307,22 +307,22 @@ class Ie extends Q {
|
|
|
307
307
|
case "url": {
|
|
308
308
|
if (!((a = (r = this._clientCapabilities) == null ? void 0 : r.elicitation) != null && a.url))
|
|
309
309
|
throw new Error("Client does not support url elicitation.");
|
|
310
|
-
const
|
|
311
|
-
return this.request({ method: "elicitation/create", params:
|
|
310
|
+
const c = e;
|
|
311
|
+
return this.request({ method: "elicitation/create", params: c }, M, t);
|
|
312
312
|
}
|
|
313
313
|
case "form": {
|
|
314
314
|
if (!((n = (i = this._clientCapabilities) == null ? void 0 : i.elicitation) != null && n.form))
|
|
315
315
|
throw new Error("Client does not support form elicitation.");
|
|
316
|
-
const
|
|
317
|
-
if (
|
|
316
|
+
const c = e.mode === "form" ? e : { ...e, mode: "form" }, l = await this.request({ method: "elicitation/create", params: c }, M, t);
|
|
317
|
+
if (l.action === "accept" && l.content && c.requestedSchema)
|
|
318
318
|
try {
|
|
319
|
-
const d = this._jsonSchemaValidator.getValidator(
|
|
319
|
+
const d = this._jsonSchemaValidator.getValidator(c.requestedSchema)(l.content);
|
|
320
320
|
if (!d.valid)
|
|
321
321
|
throw new p(m.InvalidParams, `Elicitation response content does not match requested schema: ${d.errorMessage}`);
|
|
322
322
|
} catch (u) {
|
|
323
323
|
throw u instanceof p ? u : new p(m.InternalError, `Error validating elicitation response: ${u instanceof Error ? u.message : String(u)}`);
|
|
324
324
|
}
|
|
325
|
-
return
|
|
325
|
+
return l;
|
|
326
326
|
}
|
|
327
327
|
}
|
|
328
328
|
}
|
|
@@ -513,8 +513,8 @@ class je {
|
|
|
513
513
|
throw new p(m.MethodNotFound, `Tool ${e.params.name} requires task augmentation (taskSupport: 'required')`);
|
|
514
514
|
if (i === "optional" && !a && n)
|
|
515
515
|
return await this.handleAutomaticTaskPolling(r, e, t);
|
|
516
|
-
const
|
|
517
|
-
return a || await this.validateToolOutput(r,
|
|
516
|
+
const c = await this.validateToolInput(r, e.params.arguments, e.params.name), l = await this.executeToolHandler(r, c, t);
|
|
517
|
+
return a || await this.validateToolOutput(r, l, e.params.name), l;
|
|
518
518
|
} catch (r) {
|
|
519
519
|
if (r instanceof p && r.code === m.UrlElicitationRequired)
|
|
520
520
|
throw r;
|
|
@@ -547,8 +547,8 @@ class je {
|
|
|
547
547
|
return;
|
|
548
548
|
const a = _(e.inputSchema) ?? e.inputSchema, i = await P(a, t);
|
|
549
549
|
if (!i.success) {
|
|
550
|
-
const n = "error" in i ? i.error : "Unknown error",
|
|
551
|
-
throw new p(m.InvalidParams, `Input validation error: Invalid arguments for tool ${s}: ${
|
|
550
|
+
const n = "error" in i ? i.error : "Unknown error", c = I(n);
|
|
551
|
+
throw new p(m.InvalidParams, `Input validation error: Invalid arguments for tool ${s}: ${c}`);
|
|
552
552
|
}
|
|
553
553
|
return i.data;
|
|
554
554
|
}
|
|
@@ -600,17 +600,17 @@ class je {
|
|
|
600
600
|
const r = await this.validateToolInput(e, t.params.arguments, t.params.name), a = e.handler, i = { ...s, taskStore: s.taskStore }, n = r ? await Promise.resolve(a.createTask(r, i)) : (
|
|
601
601
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
602
602
|
await Promise.resolve(a.createTask(i))
|
|
603
|
-
),
|
|
604
|
-
let
|
|
605
|
-
const u =
|
|
606
|
-
for (;
|
|
603
|
+
), c = n.task.taskId;
|
|
604
|
+
let l = n.task;
|
|
605
|
+
const u = l.pollInterval ?? 5e3;
|
|
606
|
+
for (; l.status !== "completed" && l.status !== "failed" && l.status !== "cancelled"; ) {
|
|
607
607
|
await new Promise((w) => setTimeout(w, u));
|
|
608
|
-
const d = await s.taskStore.getTask(
|
|
608
|
+
const d = await s.taskStore.getTask(c);
|
|
609
609
|
if (!d)
|
|
610
|
-
throw new p(m.InternalError, `Task ${
|
|
611
|
-
|
|
610
|
+
throw new p(m.InternalError, `Task ${c} not found during polling`);
|
|
611
|
+
l = d;
|
|
612
612
|
}
|
|
613
|
-
return await s.taskStore.getTaskResult(
|
|
613
|
+
return await s.taskStore.getTaskResult(c);
|
|
614
614
|
}
|
|
615
615
|
setCompletionRequestHandler() {
|
|
616
616
|
this._completionHandlerInitialized || (this.server.assertCanSetRequestHandler(g(x)), this.server.registerCapabilities({
|
|
@@ -719,8 +719,8 @@ class je {
|
|
|
719
719
|
if (s.argsSchema) {
|
|
720
720
|
const r = _(s.argsSchema), a = await P(r, e.params.arguments);
|
|
721
721
|
if (!a.success) {
|
|
722
|
-
const
|
|
723
|
-
throw new p(m.InvalidParams, `Invalid arguments for prompt ${e.params.name}: ${
|
|
722
|
+
const c = "error" in a ? a.error : "Unknown error", l = I(c);
|
|
723
|
+
throw new p(m.InvalidParams, `Invalid arguments for prompt ${e.params.name}: ${l}`);
|
|
724
724
|
}
|
|
725
725
|
const i = a.data, n = s.callback;
|
|
726
726
|
return await Promise.resolve(n(i, t));
|
|
@@ -785,13 +785,13 @@ class je {
|
|
|
785
785
|
disable: () => i.update({ enabled: !1 }),
|
|
786
786
|
enable: () => i.update({ enabled: !0 }),
|
|
787
787
|
remove: () => i.update({ name: null }),
|
|
788
|
-
update: (
|
|
789
|
-
typeof
|
|
788
|
+
update: (l) => {
|
|
789
|
+
typeof l.name < "u" && l.name !== e && (delete this._registeredResourceTemplates[e], l.name && (this._registeredResourceTemplates[l.name] = i)), typeof l.title < "u" && (i.title = l.title), typeof l.template < "u" && (i.resourceTemplate = l.template), typeof l.metadata < "u" && (i.metadata = l.metadata), typeof l.callback < "u" && (i.readCallback = l.callback), typeof l.enabled < "u" && (i.enabled = l.enabled), this.sendResourceListChanged();
|
|
790
790
|
}
|
|
791
791
|
};
|
|
792
792
|
this._registeredResourceTemplates[e] = i;
|
|
793
793
|
const n = s.uriTemplate.variableNames;
|
|
794
|
-
return Array.isArray(n) && n.some((
|
|
794
|
+
return Array.isArray(n) && n.some((l) => !!s.completeCallback(l)) && this.setCompletionRequestHandler(), i;
|
|
795
795
|
}
|
|
796
796
|
_createRegisteredPrompt(e, t, s, r, a) {
|
|
797
797
|
const i = {
|
|
@@ -807,13 +807,13 @@ class je {
|
|
|
807
807
|
typeof n.name < "u" && n.name !== e && (delete this._registeredPrompts[e], n.name && (this._registeredPrompts[n.name] = i)), typeof n.title < "u" && (i.title = n.title), typeof n.description < "u" && (i.description = n.description), typeof n.argsSchema < "u" && (i.argsSchema = R(n.argsSchema)), typeof n.callback < "u" && (i.callback = n.callback), typeof n.enabled < "u" && (i.enabled = n.enabled), this.sendPromptListChanged();
|
|
808
808
|
}
|
|
809
809
|
};
|
|
810
|
-
return this._registeredPrompts[e] = i, r && Object.values(r).some((
|
|
810
|
+
return this._registeredPrompts[e] = i, r && Object.values(r).some((c) => {
|
|
811
811
|
var u;
|
|
812
|
-
const
|
|
813
|
-
return Z(
|
|
812
|
+
const l = c instanceof Te ? (u = c._def) == null ? void 0 : u.innerType : c;
|
|
813
|
+
return Z(l);
|
|
814
814
|
}) && this.setCompletionRequestHandler(), i;
|
|
815
815
|
}
|
|
816
|
-
_createRegisteredTool(e, t, s, r, a, i, n,
|
|
816
|
+
_createRegisteredTool(e, t, s, r, a, i, n, c, l) {
|
|
817
817
|
J(e);
|
|
818
818
|
const u = {
|
|
819
819
|
title: t,
|
|
@@ -822,8 +822,8 @@ class je {
|
|
|
822
822
|
outputSchema: F(a),
|
|
823
823
|
annotations: i,
|
|
824
824
|
execution: n,
|
|
825
|
-
_meta:
|
|
826
|
-
handler:
|
|
825
|
+
_meta: c,
|
|
826
|
+
handler: l,
|
|
827
827
|
enabled: !0,
|
|
828
828
|
disable: () => u.update({ enabled: !1 }),
|
|
829
829
|
enable: () => u.update({ enabled: !0 }),
|
|
@@ -842,8 +842,8 @@ class je {
|
|
|
842
842
|
throw new Error(`Tool ${e} is already registered`);
|
|
843
843
|
let s, r, a, i;
|
|
844
844
|
if (typeof t[0] == "string" && (s = t.shift()), t.length > 1) {
|
|
845
|
-
const
|
|
846
|
-
H(
|
|
845
|
+
const c = t[0];
|
|
846
|
+
H(c) ? (r = t.shift(), t.length > 1 && typeof t[0] == "object" && t[0] !== null && !H(t[0]) && (i = t.shift())) : typeof c == "object" && c !== null && (i = t.shift());
|
|
847
847
|
}
|
|
848
848
|
const n = t[0];
|
|
849
849
|
return this._createRegisteredTool(e, void 0, s, r, a, i, { taskSupport: "forbidden" }, void 0, n);
|
|
@@ -854,8 +854,8 @@ class je {
|
|
|
854
854
|
registerTool(e, t, s) {
|
|
855
855
|
if (this._registeredTools[e])
|
|
856
856
|
throw new Error(`Tool ${e} is already registered`);
|
|
857
|
-
const { title: r, description: a, inputSchema: i, outputSchema: n, annotations:
|
|
858
|
-
return this._createRegisteredTool(e, r, a, i, n,
|
|
857
|
+
const { title: r, description: a, inputSchema: i, outputSchema: n, annotations: c, _meta: l } = t;
|
|
858
|
+
return this._createRegisteredTool(e, r, a, i, n, c, { taskSupport: "forbidden" }, l, s);
|
|
859
859
|
}
|
|
860
860
|
prompt(e, ...t) {
|
|
861
861
|
if (this._registeredPrompts[e])
|
|
@@ -1006,7 +1006,7 @@ class ze {
|
|
|
1006
1006
|
}
|
|
1007
1007
|
const Y = {
|
|
1008
1008
|
name: "dc-cli-mcp",
|
|
1009
|
-
version: "0.0.1-alpha.
|
|
1009
|
+
version: "0.0.1-alpha.5"
|
|
1010
1010
|
}, Ae = {
|
|
1011
1011
|
templateList: [
|
|
1012
1012
|
{
|
|
@@ -1160,14 +1160,14 @@ const Y = {
|
|
|
1160
1160
|
}
|
|
1161
1161
|
]
|
|
1162
1162
|
}, Ne = (o) => o.registerTool(
|
|
1163
|
-
|
|
1163
|
+
S.cliConfig.moduleName,
|
|
1164
1164
|
{
|
|
1165
|
-
title: `创建项目工具 - ${
|
|
1165
|
+
title: `创建项目工具 - ${S.name}`,
|
|
1166
1166
|
description: "根据用户提供的项目名称、模板地址和分支创建新项目",
|
|
1167
|
-
inputSchema:
|
|
1168
|
-
[
|
|
1169
|
-
[
|
|
1170
|
-
[
|
|
1167
|
+
inputSchema: T.object({
|
|
1168
|
+
[y.PROJECT_NAME]: T.string().min(1, "项目名称不能为空").describe("项目名称"),
|
|
1169
|
+
[y.TEMPLATE_GIT_PATH]: T.string().min(1, "模板仓库地址不能为空").describe("模板仓库地址"),
|
|
1170
|
+
[y.TEMPLATE_GIT_BRANCH]: T.string().optional().describe("对应的 Git 分支名称")
|
|
1171
1171
|
})
|
|
1172
1172
|
},
|
|
1173
1173
|
async (e) => {
|
|
@@ -1178,18 +1178,18 @@ const Y = {
|
|
|
1178
1178
|
simple: !0
|
|
1179
1179
|
};
|
|
1180
1180
|
L.info(37, process.env);
|
|
1181
|
-
const
|
|
1182
|
-
`
|
|
1181
|
+
const s = Ee(
|
|
1182
|
+
`npx create-done-coding@${S.version} ${ye(t)}`,
|
|
1183
1183
|
{
|
|
1184
1184
|
cwd: process.cwd(),
|
|
1185
1185
|
env: process.env
|
|
1186
1186
|
}
|
|
1187
1187
|
);
|
|
1188
|
-
return L.info(42, JSON.stringify(
|
|
1188
|
+
return L.info(42, JSON.stringify(s.toString())), {
|
|
1189
1189
|
content: [
|
|
1190
1190
|
{
|
|
1191
1191
|
type: "text",
|
|
1192
|
-
text: `✅ 项目 [${e[
|
|
1192
|
+
text: `✅ 项目 [${e[y.PROJECT_NAME]}] 创建成功!`
|
|
1193
1193
|
}
|
|
1194
1194
|
]
|
|
1195
1195
|
};
|
|
@@ -1205,7 +1205,7 @@ const Y = {
|
|
|
1205
1205
|
), Ue = (o) => o.registerResource(
|
|
1206
1206
|
"template-list",
|
|
1207
1207
|
// 1. name: 唯一标识符
|
|
1208
|
-
`resource:///${
|
|
1208
|
+
`resource:///${S.cliConfig.moduleName}/templates`,
|
|
1209
1209
|
// 2. uriOrTemplate: 资源访问的 URI
|
|
1210
1210
|
{
|
|
1211
1211
|
title: "可用项目模板列表",
|
|
@@ -1223,7 +1223,7 @@ const Y = {
|
|
|
1223
1223
|
]
|
|
1224
1224
|
})
|
|
1225
1225
|
), Be = (o) => o.registerPrompt(
|
|
1226
|
-
`${
|
|
1226
|
+
`${S.cliConfig.moduleName}/create-project-assistant`,
|
|
1227
1227
|
{
|
|
1228
1228
|
title: "创建项目助手",
|
|
1229
1229
|
// 将 name 修改为 title
|
package/es/test.mjs
CHANGED
|
@@ -993,5 +993,8 @@ async function Pt() {
|
|
|
993
993
|
console.log("MCP 服务返回结果:", t);
|
|
994
994
|
}
|
|
995
995
|
Pt().catch(
|
|
996
|
-
(s) =>
|
|
996
|
+
(s) => (
|
|
997
|
+
// eslint-disable-next-line no-restricted-syntax
|
|
998
|
+
console.log("出错了", (s == null ? void 0 : s.message) || s)
|
|
999
|
+
)
|
|
997
1000
|
);
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dc-cli-mcp",
|
|
3
|
-
"version": "0.0.1-alpha.
|
|
3
|
+
"version": "0.0.1-alpha.5",
|
|
4
4
|
"description": "调用done-coding命令行的mcp服务",
|
|
5
5
|
"private": false,
|
|
6
6
|
"module": "es/index.mjs",
|
|
7
7
|
"types": "types/index.d.ts",
|
|
8
8
|
"type": "module",
|
|
9
9
|
"bin": {
|
|
10
|
+
"dc-cli-test": "./es/test.mjs",
|
|
10
11
|
"dc-cli-mcp": "./es/index.mjs"
|
|
11
12
|
},
|
|
12
13
|
"exports": {
|
|
@@ -62,5 +63,5 @@
|
|
|
62
63
|
"create-done-coding": "0.11.23-alpha.3",
|
|
63
64
|
"zod": "^4.3.5"
|
|
64
65
|
},
|
|
65
|
-
"gitHead": "
|
|
66
|
+
"gitHead": "9f1c715ed189612557e08c4320c65e6d823b6d14"
|
|
66
67
|
}
|