@uni-helper/mcp 0.0.1 → 0.0.2-beta.2
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 +2 -4
- package/dist/index.d.mts +3 -2
- package/dist/index.mjs +21 -8
- package/package.json +18 -20
- package/scripts/download-model.mjs +23 -0
package/README.md
CHANGED
|
@@ -11,13 +11,11 @@ pnpm add @uni-helper/mcp -D
|
|
|
11
11
|
在 `vite.config.ts` 中添加如下配置:
|
|
12
12
|
|
|
13
13
|
```ts
|
|
14
|
-
import { defineConfig } from 'vite'
|
|
15
|
-
import uni from '@dcloudio/vite-plugin-uni'
|
|
16
14
|
import mcp from '@uni-helper/mcp'
|
|
15
|
+
import uni from '@uni-helper/plugin-uni'
|
|
16
|
+
import { defineConfig } from 'vite'
|
|
17
17
|
|
|
18
18
|
export default defineConfig({
|
|
19
19
|
plugins: [uni(), mcp()],
|
|
20
20
|
})
|
|
21
21
|
```
|
|
22
|
-
|
|
23
|
-
|
package/dist/index.d.mts
CHANGED
|
@@ -74,6 +74,7 @@ interface UniMcpOptions {
|
|
|
74
74
|
}
|
|
75
75
|
//#endregion
|
|
76
76
|
//#region src/index.d.ts
|
|
77
|
-
declare function
|
|
77
|
+
declare function isBuild(): boolean;
|
|
78
|
+
declare function uniMcp(options?: UniMcpOptions): Plugin | undefined;
|
|
78
79
|
//#endregion
|
|
79
|
-
export { uniMcp as default };
|
|
80
|
+
export { uniMcp as default, isBuild };
|
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
|
+
import process from "node:process";
|
|
2
|
+
import minimist from "minimist";
|
|
1
3
|
import { searchForWorkspaceRoot } from "vite";
|
|
2
4
|
import { serve } from "@hono/node-server";
|
|
3
5
|
import { WebStandardStreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/webStandardStreamableHttp.js";
|
|
6
|
+
import fkill from "fkill";
|
|
4
7
|
import { Hono } from "hono";
|
|
5
8
|
import { cors } from "hono/cors";
|
|
6
9
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
@@ -178,11 +181,16 @@ function connectServer(server, options) {
|
|
|
178
181
|
exposeHeaders: ["mcp-session-id", "mcp-protocol-version"]
|
|
179
182
|
}));
|
|
180
183
|
app.all("/mcp", (c) => transport.handleRequest(c.req.raw));
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
fkill(port, {
|
|
185
|
+
force: true,
|
|
186
|
+
silent: true
|
|
187
|
+
}).then(() => {
|
|
188
|
+
server.connect(transport).then(() => {
|
|
189
|
+
if (printUrl) console.log(`${ansis_default.cyan` ➜ MCP: `}${ansis_default.gray(`server is running at ${ansis_default.green(`http://localhost:${port}/mcp`)}`)}`);
|
|
190
|
+
serve({
|
|
191
|
+
fetch: app.fetch,
|
|
192
|
+
port
|
|
193
|
+
});
|
|
186
194
|
});
|
|
187
195
|
});
|
|
188
196
|
return `http://localhost:${port}/mcp`;
|
|
@@ -193,7 +201,8 @@ function connectServer(server, options) {
|
|
|
193
201
|
const __dirname = dirname(fileURLToPath(import.meta.url));
|
|
194
202
|
async function loadVectorStore(vectorName, _embeddings) {
|
|
195
203
|
const vectorDirMap = { uniapp: join(__dirname, "../", "vectorStore", "uniapp") };
|
|
196
|
-
env.
|
|
204
|
+
env.version = "master";
|
|
205
|
+
env.remoteHost = "https://www.modelscope.cn/models";
|
|
197
206
|
const embeddings = _embeddings ?? new HuggingFaceTransformersEmbeddings({
|
|
198
207
|
model: "onnx-community/Qwen3-Embedding-0.6B-ONNX",
|
|
199
208
|
pretrainedOptions: {
|
|
@@ -206,7 +215,7 @@ async function loadVectorStore(vectorName, _embeddings) {
|
|
|
206
215
|
|
|
207
216
|
//#endregion
|
|
208
217
|
//#region package.json
|
|
209
|
-
var version = "0.0.
|
|
218
|
+
var version = "0.0.2-beta.2";
|
|
210
219
|
|
|
211
220
|
//#endregion
|
|
212
221
|
//#region src/mcpServer/projectAnalyzer.ts
|
|
@@ -396,7 +405,11 @@ async function updateConfigs(root, sseUrl, options) {
|
|
|
396
405
|
|
|
397
406
|
//#endregion
|
|
398
407
|
//#region src/index.ts
|
|
408
|
+
function isBuild() {
|
|
409
|
+
return minimist(process.argv.slice(2))._.includes("build");
|
|
410
|
+
}
|
|
399
411
|
function uniMcp(options = {}) {
|
|
412
|
+
if (isBuild()) return;
|
|
400
413
|
return {
|
|
401
414
|
name: "uni-mcp",
|
|
402
415
|
enforce: "post",
|
|
@@ -408,4 +421,4 @@ function uniMcp(options = {}) {
|
|
|
408
421
|
}
|
|
409
422
|
|
|
410
423
|
//#endregion
|
|
411
|
-
export { uniMcp as default };
|
|
424
|
+
export { uniMcp as default, isBuild };
|
package/package.json
CHANGED
|
@@ -1,14 +1,10 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@uni-helper/mcp",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.0.
|
|
5
|
-
"packageManager": "pnpm@10.6.2",
|
|
4
|
+
"version": "0.0.2-beta.2",
|
|
6
5
|
"description": "mcp - uniapp也得有ai开发体验",
|
|
7
6
|
"author": "FliPPeDround <flippedround@qq.com>",
|
|
8
7
|
"license": "MIT",
|
|
9
|
-
"publishConfig": {
|
|
10
|
-
"access": "public"
|
|
11
|
-
},
|
|
12
8
|
"funding": "https://afdian.com/a/flippedround",
|
|
13
9
|
"homepage": "https://github.com/uni-helper/mcp#readme",
|
|
14
10
|
"repository": {
|
|
@@ -35,22 +31,9 @@
|
|
|
35
31
|
"types": "./dist/index.d.mts",
|
|
36
32
|
"files": [
|
|
37
33
|
"dist",
|
|
34
|
+
"scripts",
|
|
38
35
|
"vectorStore"
|
|
39
36
|
],
|
|
40
|
-
"scripts": {
|
|
41
|
-
"build": "tsdown",
|
|
42
|
-
"dev": "tsdown --watch ./src",
|
|
43
|
-
"lint": "eslint",
|
|
44
|
-
"task": "tsx ./tasks/uniappDocs/index.ts",
|
|
45
|
-
"play": "cd playground && pnpm dev",
|
|
46
|
-
"lint:fix": "eslint --fix",
|
|
47
|
-
"inspect": "mcp-inspector",
|
|
48
|
-
"prepublishOnly": "pnpm build",
|
|
49
|
-
"release": "bumpp",
|
|
50
|
-
"test": "vitest",
|
|
51
|
-
"prepare": "simple-git-hooks",
|
|
52
|
-
"postinstall": "node scripts/download-model.cjs"
|
|
53
|
-
},
|
|
54
37
|
"peerDependencies": {
|
|
55
38
|
"uniapp": "*",
|
|
56
39
|
"vite": ">=3.1.0"
|
|
@@ -61,11 +44,13 @@
|
|
|
61
44
|
"@langchain/community": "^1.1.4",
|
|
62
45
|
"@modelcontextprotocol/sdk": "^1.25.2",
|
|
63
46
|
"consola": "^3.2.3",
|
|
47
|
+
"fkill": "^10.0.3",
|
|
64
48
|
"fs-extra": "^11.3.3",
|
|
65
49
|
"hnswlib-node": "^3.0.0",
|
|
66
50
|
"hono": "^4.11.4",
|
|
67
51
|
"langchain": "^1.2.8",
|
|
68
52
|
"local-pkg": "^1.1.2",
|
|
53
|
+
"minimist": "^1.2.8",
|
|
69
54
|
"open": "^11.0.0",
|
|
70
55
|
"pathe": "^2.0.3",
|
|
71
56
|
"zod": "^4.3.5"
|
|
@@ -79,6 +64,7 @@
|
|
|
79
64
|
"@modelcontextprotocol/inspector": "^0.18.0",
|
|
80
65
|
"@types/debug": "^4.1.12",
|
|
81
66
|
"@types/fs-extra": "^11.0.4",
|
|
67
|
+
"@types/minimist": "^1.2.5",
|
|
82
68
|
"@types/node": "^25.0.8",
|
|
83
69
|
"@types/turndown": "^5.0.6",
|
|
84
70
|
"ansis": "^4.2.0",
|
|
@@ -102,5 +88,17 @@
|
|
|
102
88
|
},
|
|
103
89
|
"lint-staged": {
|
|
104
90
|
"*": "eslint --fix"
|
|
91
|
+
},
|
|
92
|
+
"scripts": {
|
|
93
|
+
"build": "tsdown",
|
|
94
|
+
"dev": "tsdown --watch ./src",
|
|
95
|
+
"lint": "eslint",
|
|
96
|
+
"task": "tsx ./tasks/uniappDocs/index.ts",
|
|
97
|
+
"play": "cd playground && pnpm dev",
|
|
98
|
+
"lint:fix": "eslint --fix",
|
|
99
|
+
"inspect": "mcp-inspector",
|
|
100
|
+
"release": "bumpp",
|
|
101
|
+
"test": "vitest",
|
|
102
|
+
"postinstall": "node scripts/download-model.mjs"
|
|
105
103
|
}
|
|
106
|
-
}
|
|
104
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import process from 'node:process'
|
|
2
|
+
import { env } from '@huggingface/transformers'
|
|
3
|
+
import { HuggingFaceTransformersEmbeddings } from '@langchain/community/embeddings/huggingface_transformers'
|
|
4
|
+
|
|
5
|
+
async function downloadModel() {
|
|
6
|
+
env.version = 'master'
|
|
7
|
+
env.remoteHost = 'https://www.modelscope.cn/models'
|
|
8
|
+
await new Promise(resolve => setTimeout(resolve, 1000))
|
|
9
|
+
const embeddings = new HuggingFaceTransformersEmbeddings({
|
|
10
|
+
model: 'onnx-community/Qwen3-Embedding-0.6B-ONNX',
|
|
11
|
+
pretrainedOptions: {
|
|
12
|
+
dtype: 'int8',
|
|
13
|
+
device: 'cpu',
|
|
14
|
+
},
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
await embeddings.embedQuery('warmup')
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
downloadModel().catch((err) => {
|
|
21
|
+
console.error(err)
|
|
22
|
+
process.exit(1)
|
|
23
|
+
})
|