cloudcc-cli 2.2.2 → 2.2.4
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/.vscode/settings.json +3 -0
- package/README.md +47 -0
- package/bin/cc.js +11 -35
- package/bin/index.js +33 -0
- package/bin/mcp-svc.js +13 -0
- package/bin/mcp.js +18 -0
- package/java/com/cloudcc/core/TriggerInvoker.java +17 -1
- package/package.json +16 -7
- package/pom.xml +1 -0
- package/prompt/DevelopmentEnvironmentConstruction.ts +133 -0
- package/prompt/ccdk.ts +1190 -0
- package/prompt/ccprompt.ts +8 -0
- package/prompt/cloudccdev.ts +109 -0
- package/prompt/index.ts +52 -0
- package/prompt/objectInfo.ts +94 -0
- package/prompt/objectList.ts +25 -0
- package/prompt/openapi.ts +310 -0
- package/prompt/system.ts +14 -0
- package/prompt/vscodeExtension.ts +27 -0
- package/src/approval/approve.js +105 -0
- package/src/approval/get.js +245 -0
- package/src/approval/index.js +11 -0
- package/src/approval/reject.js +105 -0
- package/src/brief/get.js +51 -0
- package/src/brief/index.js +7 -0
- package/src/config/get.js +1 -1
- package/src/fields/create.js +204 -0
- package/src/fields/fields/A.js +23 -0
- package/src/fields/fields/AD.js +25 -0
- package/src/fields/fields/B.js +28 -0
- package/src/fields/fields/C.js +28 -0
- package/src/fields/fields/D.js +27 -0
- package/src/fields/fields/E.js +28 -0
- package/src/fields/fields/ENC.js +28 -0
- package/src/fields/fields/ENCD.js +28 -0
- package/src/fields/fields/F.js +27 -0
- package/src/fields/fields/FL.js +25 -0
- package/src/fields/fields/H.js +27 -0
- package/src/fields/fields/IMG.js +27 -0
- package/src/fields/fields/J.js +26 -0
- package/src/fields/fields/L.js +32 -0
- package/src/fields/fields/LT.js +28 -0
- package/src/fields/fields/M.js +29 -0
- package/src/fields/fields/MR.js +24 -0
- package/src/fields/fields/N.js +30 -0
- package/src/fields/fields/P.js +28 -0
- package/src/fields/fields/Q.js +35 -0
- package/src/fields/fields/S.js +30 -0
- package/src/fields/fields/SCORE.js +24 -0
- package/src/fields/fields/T.js +27 -0
- package/src/fields/fields/U.js +28 -0
- package/src/fields/fields/X.js +28 -0
- package/src/fields/fields/Y.js +33 -0
- package/src/fields/get.js +36 -0
- package/src/fields/index.js +9 -0
- package/src/mcp/MCP/345/234/272/346/231/257/346/250/241/346/213/237.md +8 -0
- package/src/mcp/index-sse-svc.js +126 -0
- package/src/mcp/index-streamable-svc.js +180 -0
- package/src/mcp/index.js +631 -0
- package/src/mcp/readme.md +137 -0
- package/src/mcp/tools/Approval/handler.js +349 -0
- package/src/mcp/tools/Class Creator/handler.js +37 -0
- package/src/mcp/tools/Class Detail Retriever/handler.js +33 -0
- package/src/mcp/tools/Class Detail Retriever/prompt.js +37 -0
- package/src/mcp/tools/Class Editor Guide/handler.js +72 -0
- package/src/mcp/tools/Class Editor Guide/prompt.js +468 -0
- package/src/mcp/tools/Class List Retriever/handler.js +36 -0
- package/src/mcp/tools/Class Publisher/handler.js +29 -0
- package/src/mcp/tools/Class Publisher/prompt.js +40 -0
- package/src/mcp/tools/Class Puller/handler.js +86 -0
- package/src/mcp/tools/Class Puller/prompt.js +49 -0
- package/src/mcp/tools/Client Script Creator/handler.js +179 -0
- package/src/mcp/tools/Client Script Detail Retriever/handler.js +53 -0
- package/src/mcp/tools/Client Script Editor Guide/handler.js +633 -0
- package/src/mcp/tools/Client Script List Retriever/handler.js +68 -0
- package/src/mcp/tools/Client Script Publisher/handler.js +54 -0
- package/src/mcp/tools/Client Script Puller/handler.js +73 -0
- package/src/mcp/tools/CloudCC Development Overview/handler.js +48 -0
- package/src/mcp/tools/CloudCC Development Overview/prompt.js +870 -0
- package/src/mcp/tools/Component Creator/handler.js +44 -0
- package/src/mcp/tools/Component Detail Retriever/handler.js +38 -0
- package/src/mcp/tools/Component Editor Guide/handler.js +76 -0
- package/src/mcp/tools/Component Editor Guide/prompt.js +519 -0
- package/src/mcp/tools/Component List Retriever/handler.js +43 -0
- package/src/mcp/tools/Component Publisher/handler.js +18 -0
- package/src/mcp/tools/Component Publisher/prompt.js +659 -0
- package/src/mcp/tools/Component Puller/handler.js +63 -0
- package/src/mcp/tools/Dev Environment Creator/fetcher.js +500 -0
- package/src/mcp/tools/Dev Environment Creator/handler.js +92 -0
- package/src/mcp/tools/Dev Environment Creator/prompt.js +273 -0
- package/src/mcp/tools/Dev Environment Validator/handler.js +88 -0
- package/src/mcp/tools/Dev Environment Validator/prompt.js +193 -0
- package/src/mcp/tools/Developer Key Setup Guide/fetcher.js +278 -0
- package/src/mcp/tools/Developer Key Setup Guide/handler.js +43 -0
- package/src/mcp/tools/Developer Key Setup Guide/prompt.js +71 -0
- package/src/mcp/tools/Object Creator/handler.js +34 -0
- package/src/mcp/tools/Object Fields Creator/handler.js +64 -0
- package/src/mcp/tools/Object Fields Retriever/handler.js +37 -0
- package/src/mcp/tools/Object Fields Retriever/prompt.js +10 -0
- package/src/mcp/tools/Object List Retriever/handler.js +43 -0
- package/src/mcp/tools/Object List Retriever/prompt.js +10 -0
- package/src/mcp/tools/Scheduled Class Creator/handler.js +37 -0
- package/src/mcp/tools/Scheduled Class Detail Retriever/handler.js +34 -0
- package/src/mcp/tools/Scheduled Class List Retriever/handler.js +52 -0
- package/src/mcp/tools/Scheduled Class Publisher/handler.js +30 -0
- package/src/mcp/tools/Scheduled Class Puller/handler.js +92 -0
- package/src/mcp/tools/Trigger Creator/handler.js +53 -0
- package/src/mcp/tools/Trigger Detail Retriever/handler.js +33 -0
- package/src/mcp/tools/Trigger Editor Guide/handler.js +58 -0
- package/src/mcp/tools/Trigger List Retriever/handler.js +49 -0
- package/src/mcp/tools/Trigger Publisher/handler.js +34 -0
- package/src/mcp/tools/Trigger Puller/handler.js +40 -0
- package/src/mcp/tools/ccdk/fetcher.js +18 -0
- package/src/mcp/tools/ccdk/handler.js +98 -0
- package/src/mcp/tools/ccdk/prompt.js +453 -0
- package/src/mcp/tools/index.js +23 -0
- package/src/object/create.js +105 -0
- package/src/object/get.js +43 -4
- package/src/object/index.js +2 -1
- package/src/plugin/create.js +1 -2
- package/src/plugin/create1.js +9 -9
- package/src/plugin/detail.js +91 -0
- package/src/plugin/get.js +79 -0
- package/src/plugin/index.js +4 -1
- package/src/plugin/publish.js +13 -13
- package/src/plugin/publish1.js +33 -24
- package/src/plugin/pull.js +173 -0
- package/src/project/create.js +9 -9
- package/src/project/create1.js +31 -17
- package/src/recordType/get.js +4 -2
- package/src/script/create.js +7 -7
- package/src/script/detail.js +95 -0
- package/src/script/get.js +4 -2
- package/src/script/index.js +1 -0
- package/src/script/publish.js +14 -14
- package/src/script/pull.js +12 -12
- package/src/script/pullList.js +5 -3
- package/src/timer/create.js +7 -7
- package/src/timer/detail.js +84 -0
- package/src/timer/get.js +6 -3
- package/src/timer/publish.js +7 -7
- package/src/timer/pull.js +8 -8
- package/src/timer/pullList.js +5 -3
- package/src/token/get.js +1 -1
- package/src/triggers/create.js +7 -7
- package/src/triggers/detail.js +90 -0
- package/src/triggers/get.js +4 -2
- package/src/triggers/index.js +1 -0
- package/src/triggers/publish.js +7 -7
- package/src/triggers/pull.js +8 -8
- package/src/triggers/pullList.js +5 -3
- package/src/version/get.js +3 -3
- package/target/ccopenapi-0.0.3-classes.jar +0 -0
- package/target/ccopenapi-0.0.3.jar +0 -0
- package/target/maven-archiver/pom.properties +3 -0
- package/target/maven-status/maven-compiler-plugin/compile/default-compile/createdFiles.lst +18 -0
- package/target/maven-status/maven-compiler-plugin/compile/default-compile/inputFiles.lst +19 -0
- package/template/Appvue +452 -12
- package/template/index.js +30 -19
- package/tool/branch/index.js +1 -1
- package/tool/checkLange/checkLang.js +6 -6
- package/tool/checkLange/clearLang.js +1 -1
- package/utils/accessClass.js +23 -0
- package/utils/checkVersion.js +22 -20
- package/utils/config.js +18 -3
- package/utils/http.js +10 -10
- package/utils/utils.js +128 -40
- package/java/com/cloudcc/core/CCTriggerDemo.java +0 -25
- package/src/classes/create.js +0 -65
- package/src/classes/get.js +0 -21
- package/src/classes/index.js +0 -11
- package/src/classes/publish.js +0 -50
- package/src/classes/pull.js +0 -54
- package/src/classes/pullList.js +0 -44
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 查找多选字段(MR)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, lookupObj, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"schemefieldLength": "255",
|
|
12
|
+
"remark": "",
|
|
13
|
+
"helps": "",
|
|
14
|
+
"lookupObj": lookupObj
|
|
15
|
+
},
|
|
16
|
+
"dtype": "MR:查找多选",
|
|
17
|
+
"fdtype": "MR",
|
|
18
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
19
|
+
"profileId": profile.id,
|
|
20
|
+
"visible": "true",
|
|
21
|
+
"readonly": "false"
|
|
22
|
+
})),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 数字字段(N)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"remark": "",
|
|
12
|
+
"helps": "",
|
|
13
|
+
"defaultValue": "",
|
|
14
|
+
"schemefieldLength": "10",
|
|
15
|
+
"decimalPlaces": "0",
|
|
16
|
+
"isrepeat": "true",
|
|
17
|
+
"displayThousands": "0"
|
|
18
|
+
},
|
|
19
|
+
"dtype": "N:数字",
|
|
20
|
+
"fdtype": "N",
|
|
21
|
+
"ischecked": "false",
|
|
22
|
+
"iscover": "",
|
|
23
|
+
"formulaText": "",
|
|
24
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
25
|
+
"profileId": profile.id,
|
|
26
|
+
"visible": "true",
|
|
27
|
+
"readonly": "false"
|
|
28
|
+
})),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 百分比字段(P)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"remark": "",
|
|
12
|
+
"helps": "",
|
|
13
|
+
"defaultValue": "",
|
|
14
|
+
"schemefieldLength": "10",
|
|
15
|
+
"decimalPlaces": "2"
|
|
16
|
+
},
|
|
17
|
+
"dtype": "P:百分比",
|
|
18
|
+
"fdtype": "P",
|
|
19
|
+
"ischecked": "false",
|
|
20
|
+
"iscover": "",
|
|
21
|
+
"formulaText": "",
|
|
22
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
23
|
+
"profileId": profile.id,
|
|
24
|
+
"visible": "true",
|
|
25
|
+
"readonly": "false"
|
|
26
|
+
})),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 选项列表(多选)字段(Q)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, ptext, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"schemefieldLength": "255",
|
|
12
|
+
"edittype": "select",
|
|
13
|
+
"visibleLines": "4",
|
|
14
|
+
"showalloptions": "0",
|
|
15
|
+
"renderstyle": "1",
|
|
16
|
+
"remark": "",
|
|
17
|
+
"helps": ""
|
|
18
|
+
},
|
|
19
|
+
"dtype": "Q:选项列表(多选)",
|
|
20
|
+
"fdtype": "Q",
|
|
21
|
+
"ischecked": "false",
|
|
22
|
+
"useGlobalSelect": "0",
|
|
23
|
+
"globalSelectId": "province",
|
|
24
|
+
"ptext": ptext,
|
|
25
|
+
"isPicklistSorted": "0",
|
|
26
|
+
"defPl": "1",
|
|
27
|
+
"iscover": "",
|
|
28
|
+
"formulaText": "",
|
|
29
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
30
|
+
"profileId": profile.id,
|
|
31
|
+
"visible": "true",
|
|
32
|
+
"readonly": "false"
|
|
33
|
+
})),
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本字段(S)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"remark": "",
|
|
12
|
+
"helps": "",
|
|
13
|
+
"schemefieldLength": "255",
|
|
14
|
+
"isrepeat": "true",
|
|
15
|
+
"casesensitive": "",
|
|
16
|
+
"placeholder": "",
|
|
17
|
+
"defaultValue": ""
|
|
18
|
+
},
|
|
19
|
+
"dtype": "S:文本",
|
|
20
|
+
"fdtype": "S",
|
|
21
|
+
"ischecked": "false",
|
|
22
|
+
"iscover": "",
|
|
23
|
+
"formulaText": "",
|
|
24
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
25
|
+
"profileId": profile.id,
|
|
26
|
+
"visible": "true",
|
|
27
|
+
"readonly": "false"
|
|
28
|
+
})),
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 评分字段(SCORE)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"remark": "",
|
|
12
|
+
"helps": "",
|
|
13
|
+
"schemefieldLength": "10",
|
|
14
|
+
"defaultValue": ""
|
|
15
|
+
},
|
|
16
|
+
"dtype": "SCORE:评分",
|
|
17
|
+
"fdtype": "SCORE",
|
|
18
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
19
|
+
"profileId": profile.id,
|
|
20
|
+
"visible": "true",
|
|
21
|
+
"readonly": "false"
|
|
22
|
+
})),
|
|
23
|
+
}
|
|
24
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 时间字段(T)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"schemefieldLength": "255",
|
|
12
|
+
"remark": "",
|
|
13
|
+
"helps": "",
|
|
14
|
+
"defaultValue": ""
|
|
15
|
+
},
|
|
16
|
+
"dtype": "T:时间",
|
|
17
|
+
"fdtype": "T",
|
|
18
|
+
"ischecked": "false",
|
|
19
|
+
"iscover": "",
|
|
20
|
+
"formulaText": "",
|
|
21
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
22
|
+
"profileId": profile.id,
|
|
23
|
+
"visible": "true",
|
|
24
|
+
"readonly": "false"
|
|
25
|
+
})),
|
|
26
|
+
}
|
|
27
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* URL字段(U)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"remark": "",
|
|
12
|
+
"helps": "",
|
|
13
|
+
"edittype": "_blank",
|
|
14
|
+
"schemefieldLength": "255",
|
|
15
|
+
"defaultValue": ""
|
|
16
|
+
},
|
|
17
|
+
"dtype": "U:URL",
|
|
18
|
+
"fdtype": "U",
|
|
19
|
+
"ischecked": "false",
|
|
20
|
+
"iscover": "",
|
|
21
|
+
"formulaText": "",
|
|
22
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
23
|
+
"profileId": profile.id,
|
|
24
|
+
"visible": "true",
|
|
25
|
+
"readonly": "false"
|
|
26
|
+
})),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 文本区字段(X)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"remark": "",
|
|
12
|
+
"helps": "",
|
|
13
|
+
"defaultValue": "",
|
|
14
|
+
"schemefieldLength": "255",
|
|
15
|
+
"placeholder": ""
|
|
16
|
+
},
|
|
17
|
+
"dtype": "X",
|
|
18
|
+
"fdtype": "X",
|
|
19
|
+
"ischecked": "false",
|
|
20
|
+
"iscover": "",
|
|
21
|
+
"formulaText": "",
|
|
22
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
23
|
+
"profileId": profile.id,
|
|
24
|
+
"visible": "true",
|
|
25
|
+
"readonly": "false"
|
|
26
|
+
})),
|
|
27
|
+
}
|
|
28
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 查找关系字段(Y)配置模板
|
|
3
|
+
*/
|
|
4
|
+
module.exports = function (objid, nameLabel, apiname, lookupObj, profileList) {
|
|
5
|
+
return {
|
|
6
|
+
"objid": objid,
|
|
7
|
+
"obj": {
|
|
8
|
+
"id": "",
|
|
9
|
+
"nameLabel": nameLabel,
|
|
10
|
+
"apiname": apiname,
|
|
11
|
+
"schemefieldLength": "255",
|
|
12
|
+
"remark": "",
|
|
13
|
+
"helps": "",
|
|
14
|
+
"lookupObj": lookupObj,
|
|
15
|
+
"defaultValue": "",
|
|
16
|
+
"childrelationName": nameLabel,
|
|
17
|
+
"lookupObjDefaultField": ""
|
|
18
|
+
},
|
|
19
|
+
"dtype": "Y:查找关系",
|
|
20
|
+
"fdtype": "Y",
|
|
21
|
+
"ischecked": "false",
|
|
22
|
+
"iscover": "",
|
|
23
|
+
"formulaText": "",
|
|
24
|
+
"lookupObjDefaultValue": "",
|
|
25
|
+
"lookupObjDefaultValueMod": "0",
|
|
26
|
+
"lookupObjDefaultValuePrefix": "",
|
|
27
|
+
"profileFieldJson": profileList.map(profile => ({
|
|
28
|
+
"profileId": profile.id,
|
|
29
|
+
"visible": "true",
|
|
30
|
+
"readonly": "false"
|
|
31
|
+
})),
|
|
32
|
+
}
|
|
33
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
const { postClass } = require("../../utils/http")
|
|
2
|
+
const { getPackageJson } = require("../../utils/config");
|
|
3
|
+
|
|
4
|
+
async function get(argvs, isMcp = false) {
|
|
5
|
+
const path = argvs[2];
|
|
6
|
+
const objArg = argvs[3];
|
|
7
|
+
const config = await getPackageJson(path);
|
|
8
|
+
const fieldsResults = await postClass(config.setupSvc + "/api/fieldSetup/queryField", { prefix: objArg }, config.accessToken);
|
|
9
|
+
|
|
10
|
+
let res = {
|
|
11
|
+
obj: fieldsResults.data.obj,
|
|
12
|
+
stdFields: fieldsResults.data.stdFields.map((field) => {
|
|
13
|
+
return {
|
|
14
|
+
fieldname: field.labelName,
|
|
15
|
+
apiname: field.schemefieldName,
|
|
16
|
+
schemefieldType: field.schemefieldType,
|
|
17
|
+
id: field.id
|
|
18
|
+
}
|
|
19
|
+
}),
|
|
20
|
+
cusFields: fieldsResults.data.cusFields.map((field) => {
|
|
21
|
+
return {
|
|
22
|
+
fieldname: field.labelName,
|
|
23
|
+
apiname: field.schemefieldName,
|
|
24
|
+
schemefieldType: field.schemefieldType,
|
|
25
|
+
id: field.id
|
|
26
|
+
}
|
|
27
|
+
})
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (!isMcp) {
|
|
31
|
+
console.log(JSON.stringify(res));
|
|
32
|
+
}
|
|
33
|
+
return res;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
module.exports = get;
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* SSE 版本的 MCP 服务器实现
|
|
3
|
+
* 基于 MCP 协议版本 2024-11-05 (已弃用,主要用于向后兼容测试)
|
|
4
|
+
*
|
|
5
|
+
* 服务器暴露两个端点:
|
|
6
|
+
* - GET /mcp: 用于建立 SSE 流
|
|
7
|
+
* - POST /messages: 用于接收客户端消息
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
11
|
+
const { SSEServerTransport } = require("@modelcontextprotocol/sdk/server/sse.js");
|
|
12
|
+
const { createMcpExpressApp } = require("@modelcontextprotocol/sdk/server/express.js");
|
|
13
|
+
const { registerAllTools } = require('./tools/index.js');
|
|
14
|
+
const MCP_PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 8018;
|
|
15
|
+
|
|
16
|
+
// 获取服务器实例(单例模式)
|
|
17
|
+
let mcpServerInstance = null;
|
|
18
|
+
function getServer() {
|
|
19
|
+
if (!mcpServerInstance) {
|
|
20
|
+
mcpServerInstance = new McpServer({
|
|
21
|
+
name: 'cctool',
|
|
22
|
+
version: '1.0.0'
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
// 注册所有工具
|
|
26
|
+
registerAllTools(mcpServerInstance);
|
|
27
|
+
}
|
|
28
|
+
return mcpServerInstance;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const app = createMcpExpressApp();
|
|
32
|
+
|
|
33
|
+
// 按 session ID 存储 transports
|
|
34
|
+
const transports = {};
|
|
35
|
+
|
|
36
|
+
// SSE 端点:用于建立 SSE 流
|
|
37
|
+
app.get('/mcp', async (req, res) => {
|
|
38
|
+
console.log('Received GET request to /mcp (establishing SSE stream)');
|
|
39
|
+
|
|
40
|
+
try {
|
|
41
|
+
// 为客户端创建新的 SSE transport
|
|
42
|
+
// POST 消息的端点是 '/messages'
|
|
43
|
+
const transport = new SSEServerTransport('/messages', res);
|
|
44
|
+
|
|
45
|
+
// 按 session ID 存储 transport
|
|
46
|
+
const sessionId = transport.sessionId;
|
|
47
|
+
transports[sessionId] = transport;
|
|
48
|
+
|
|
49
|
+
// 设置 onclose 处理器,在关闭时清理 transport
|
|
50
|
+
transport.onclose = () => {
|
|
51
|
+
console.log(`SSE transport closed for session ${sessionId}`);
|
|
52
|
+
delete transports[sessionId];
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
// 将 transport 连接到 MCP 服务器
|
|
56
|
+
const server = getServer();
|
|
57
|
+
await server.connect(transport);
|
|
58
|
+
|
|
59
|
+
console.log(`Established SSE stream with session ID: ${sessionId}`);
|
|
60
|
+
} catch (error) {
|
|
61
|
+
console.error('Error establishing SSE stream:', error);
|
|
62
|
+
if (!res.headersSent) {
|
|
63
|
+
res.status(500).send('Error establishing SSE stream');
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
|
|
68
|
+
// 消息端点:用于接收客户端 JSON-RPC 请求
|
|
69
|
+
app.post('/messages', async (req, res) => {
|
|
70
|
+
console.log('Received POST request to /messages');
|
|
71
|
+
|
|
72
|
+
// 从 URL query 参数中提取 session ID
|
|
73
|
+
// 在 SSE 协议中,这是客户端根据端点事件添加的
|
|
74
|
+
const sessionId = req.query.sessionId;
|
|
75
|
+
|
|
76
|
+
if (!sessionId) {
|
|
77
|
+
console.error('No session ID provided in request URL');
|
|
78
|
+
res.status(400).send('Missing sessionId parameter');
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const transport = transports[sessionId];
|
|
83
|
+
if (!transport) {
|
|
84
|
+
console.error(`No active transport found for session ID: ${sessionId}`);
|
|
85
|
+
res.status(404).send('Session not found');
|
|
86
|
+
return;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
try {
|
|
90
|
+
// 使用 transport 处理 POST 消息
|
|
91
|
+
await transport.handlePostMessage(req, res, req.body);
|
|
92
|
+
} catch (error) {
|
|
93
|
+
console.error('Error handling request:', error);
|
|
94
|
+
if (!res.headersSent) {
|
|
95
|
+
res.status(500).send('Error handling request');
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
// 启动服务器
|
|
101
|
+
app.listen(MCP_PORT, error => {
|
|
102
|
+
if (error) {
|
|
103
|
+
console.error('Failed to start server:', error);
|
|
104
|
+
process.exit(1);
|
|
105
|
+
}
|
|
106
|
+
console.log(`Simple SSE Server (deprecated protocol version 2024-11-05) listening on port ${MCP_PORT}`);
|
|
107
|
+
});
|
|
108
|
+
|
|
109
|
+
// Handle server shutdown
|
|
110
|
+
process.on('SIGINT', async () => {
|
|
111
|
+
console.log('Shutting down server...');
|
|
112
|
+
|
|
113
|
+
// Close all active transports to properly clean up resources
|
|
114
|
+
for (const sessionId in transports) {
|
|
115
|
+
try {
|
|
116
|
+
console.log(`Closing transport for session ${sessionId}`);
|
|
117
|
+
await transports[sessionId].close();
|
|
118
|
+
delete transports[sessionId];
|
|
119
|
+
} catch (error) {
|
|
120
|
+
console.error(`Error closing transport for session ${sessionId}:`, error);
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
console.log('Server shutdown complete');
|
|
124
|
+
process.exit(0);
|
|
125
|
+
});
|
|
126
|
+
|
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
const { randomUUID } = require('node:crypto');
|
|
2
|
+
const { McpServer } = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
3
|
+
const { StreamableHTTPServerTransport } = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
|
|
4
|
+
const { createMcpExpressApp } = require("@modelcontextprotocol/sdk/server/express.js");
|
|
5
|
+
const { isInitializeRequest } = require("@modelcontextprotocol/sdk/types.js");
|
|
6
|
+
const { InMemoryEventStore } = require("@modelcontextprotocol/sdk/examples/shared/inMemoryEventStore.js");
|
|
7
|
+
const { registerAllTools } = require('./tools/index.js');
|
|
8
|
+
const MCP_PORT = process.env.MCP_PORT ? parseInt(process.env.MCP_PORT, 10) : 8018;
|
|
9
|
+
|
|
10
|
+
// 获取服务器实例(单例模式)
|
|
11
|
+
|
|
12
|
+
let mcpServerInstance = null;
|
|
13
|
+
function getServer() {
|
|
14
|
+
if (!mcpServerInstance) {
|
|
15
|
+
mcpServerInstance = new McpServer({
|
|
16
|
+
name: 'cctool',
|
|
17
|
+
version: '1.0.0'
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
// 注册所有工具
|
|
21
|
+
registerAllTools(mcpServerInstance);
|
|
22
|
+
}
|
|
23
|
+
return mcpServerInstance;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const app = createMcpExpressApp();
|
|
27
|
+
|
|
28
|
+
// Map to store transports by session ID
|
|
29
|
+
const transports = {};
|
|
30
|
+
|
|
31
|
+
// MCP POST endpoint
|
|
32
|
+
const mcpPostHandler = async (req, res) => {
|
|
33
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
34
|
+
if (sessionId) {
|
|
35
|
+
console.log(`Received MCP request for session: ${sessionId}`);
|
|
36
|
+
} else {
|
|
37
|
+
console.log('Request body:', req.body);
|
|
38
|
+
}
|
|
39
|
+
try {
|
|
40
|
+
let transport;
|
|
41
|
+
if (sessionId && transports[sessionId]) {
|
|
42
|
+
// Reuse existing transport
|
|
43
|
+
transport = transports[sessionId];
|
|
44
|
+
} else if (!sessionId && isInitializeRequest(req.body)) {
|
|
45
|
+
// New initialization request
|
|
46
|
+
const eventStore = new InMemoryEventStore();
|
|
47
|
+
transport = new StreamableHTTPServerTransport({
|
|
48
|
+
sessionIdGenerator: () => randomUUID(),
|
|
49
|
+
eventStore, // Enable resumability
|
|
50
|
+
onsessioninitialized: sessionId => {
|
|
51
|
+
// Store the transport by session ID when session is initialized
|
|
52
|
+
// This avoids race conditions where requests might come in before the session is stored
|
|
53
|
+
console.log(`Session initialized with ID: ${sessionId}`);
|
|
54
|
+
transports[sessionId] = transport;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
// Set up onclose handler to clean up transport when closed
|
|
59
|
+
transport.onclose = () => {
|
|
60
|
+
const sid = transport.sessionId;
|
|
61
|
+
if (sid && transports[sid]) {
|
|
62
|
+
console.log(`Transport closed for session ${sid}, removing from transports map`);
|
|
63
|
+
delete transports[sid];
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
// Connect the transport to the MCP server BEFORE handling the request
|
|
68
|
+
// so responses can flow back through the same transport
|
|
69
|
+
const server = getServer();
|
|
70
|
+
await server.connect(transport);
|
|
71
|
+
|
|
72
|
+
await transport.handleRequest(req, res, req.body);
|
|
73
|
+
return; // Already handled
|
|
74
|
+
} else {
|
|
75
|
+
// Invalid request - no session ID or not initialization request
|
|
76
|
+
res.status(400).json({
|
|
77
|
+
jsonrpc: '2.0',
|
|
78
|
+
error: {
|
|
79
|
+
code: -32000,
|
|
80
|
+
message: 'Bad Request: No valid session ID provided'
|
|
81
|
+
},
|
|
82
|
+
id: null
|
|
83
|
+
});
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Handle the request with existing transport - no need to reconnect
|
|
88
|
+
// The existing transport is already connected to the server
|
|
89
|
+
await transport.handleRequest(req, res, req.body);
|
|
90
|
+
} catch (error) {
|
|
91
|
+
console.error('Error handling MCP request:', error);
|
|
92
|
+
if (!res.headersSent) {
|
|
93
|
+
res.status(500).json({
|
|
94
|
+
jsonrpc: '2.0',
|
|
95
|
+
error: {
|
|
96
|
+
code: -32603,
|
|
97
|
+
message: 'Internal server error'
|
|
98
|
+
},
|
|
99
|
+
id: null
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
// Set up POST route
|
|
106
|
+
app.post('/mcp', mcpPostHandler);
|
|
107
|
+
|
|
108
|
+
// Handle GET requests for SSE streams (using built-in support from StreamableHTTP)
|
|
109
|
+
const mcpGetHandler = async (req, res) => {
|
|
110
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
111
|
+
if (!sessionId || !transports[sessionId]) {
|
|
112
|
+
res.status(400).send('Invalid or missing session ID');
|
|
113
|
+
return;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// Check for Last-Event-ID header for resumability
|
|
117
|
+
const lastEventId = req.headers['last-event-id'];
|
|
118
|
+
if (lastEventId) {
|
|
119
|
+
console.log(`Client reconnecting with Last-Event-ID: ${lastEventId}`);
|
|
120
|
+
} else {
|
|
121
|
+
console.log(`Establishing new SSE stream for session ${sessionId}`);
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const transport = transports[sessionId];
|
|
125
|
+
await transport.handleRequest(req, res);
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
// Set up GET route
|
|
129
|
+
app.get('/mcp', mcpGetHandler);
|
|
130
|
+
|
|
131
|
+
// Handle DELETE requests for session termination (according to MCP spec)
|
|
132
|
+
const mcpDeleteHandler = async (req, res) => {
|
|
133
|
+
const sessionId = req.headers['mcp-session-id'];
|
|
134
|
+
if (!sessionId || !transports[sessionId]) {
|
|
135
|
+
res.status(400).send('Invalid or missing session ID');
|
|
136
|
+
return;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
console.log(`Received session termination request for session ${sessionId}`);
|
|
140
|
+
|
|
141
|
+
try {
|
|
142
|
+
const transport = transports[sessionId];
|
|
143
|
+
await transport.handleRequest(req, res);
|
|
144
|
+
} catch (error) {
|
|
145
|
+
console.error('Error handling session termination:', error);
|
|
146
|
+
if (!res.headersSent) {
|
|
147
|
+
res.status(500).send('Error processing session termination');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
// Set up DELETE route
|
|
153
|
+
app.delete('/mcp', mcpDeleteHandler);
|
|
154
|
+
|
|
155
|
+
app.listen(MCP_PORT, error => {
|
|
156
|
+
if (error) {
|
|
157
|
+
console.error('Failed to start server:', error);
|
|
158
|
+
process.exit(1);
|
|
159
|
+
}
|
|
160
|
+
console.log(`MCP Streamable HTTP Server listening on port ${MCP_PORT}`);
|
|
161
|
+
});
|
|
162
|
+
|
|
163
|
+
// Handle server shutdown
|
|
164
|
+
process.on('SIGINT', async () => {
|
|
165
|
+
console.log('Shutting down server...');
|
|
166
|
+
|
|
167
|
+
// Close all active transports to properly clean up resources
|
|
168
|
+
for (const sessionId in transports) {
|
|
169
|
+
try {
|
|
170
|
+
console.log(`Closing transport for session ${sessionId}`);
|
|
171
|
+
await transports[sessionId].close();
|
|
172
|
+
delete transports[sessionId];
|
|
173
|
+
} catch (error) {
|
|
174
|
+
console.error(`Error closing transport for session ${sessionId}:`, error);
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
console.log('Server shutdown complete');
|
|
178
|
+
process.exit(0);
|
|
179
|
+
});
|
|
180
|
+
|