@mcp-use/cli 2.0.0 → 2.0.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/LICENSE +22 -0
- package/README.md +104 -0
- package/dist/build.d.ts +1 -1
- package/dist/build.d.ts.map +1 -1
- package/dist/index.js +368 -17
- package/dist/index.mjs +353 -0
- package/package.json +33 -5
- package/dist/build.d.mts +0 -2
- package/dist/build.d.mts.map +0 -1
- package/dist/build.js +0 -105
- package/dist/build.js.map +0 -1
- package/dist/build.mjs +0 -106
- package/dist/build.mjs.map +0 -1
- package/dist/index.js.map +0 -1
- package/src/build.ts +0 -118
- package/src/index.ts +0 -25
- package/tsconfig.json +0 -20
- package/tsconfig.tsbuildinfo +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 mcp-use, Inc.
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
22
|
+
|
package/README.md
ADDED
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
# @mcp-use/cli
|
|
2
|
+
|
|
3
|
+
Build and development tool for MCP servers with UI widgets.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install -g @mcp-use/cli
|
|
9
|
+
# or
|
|
10
|
+
yarn global add @mcp-use/cli
|
|
11
|
+
# or
|
|
12
|
+
pnpm add -g @mcp-use/cli
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
## Usage
|
|
16
|
+
|
|
17
|
+
### Development Mode
|
|
18
|
+
|
|
19
|
+
```bash
|
|
20
|
+
mcp-use dev [options]
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
Runs development server with:
|
|
24
|
+
- TypeScript compilation in watch mode
|
|
25
|
+
- Widget build in watch mode
|
|
26
|
+
- Server with auto-reload (via tsx)
|
|
27
|
+
- **Auto-opens inspector in browser** when ready
|
|
28
|
+
|
|
29
|
+
Options:
|
|
30
|
+
- `-p, --path <path>` - Project directory (default: current directory)
|
|
31
|
+
- `--port <port>` - Server port (default: 3000)
|
|
32
|
+
- `--no-open` - Don't auto-open inspector
|
|
33
|
+
|
|
34
|
+
### Production Build
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
mcp-use build [options]
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Builds TypeScript and bundles all `.tsx` files from `resources/` into standalone HTML pages.
|
|
41
|
+
|
|
42
|
+
Options:
|
|
43
|
+
- `-p, --path <path>` - Project directory (default: current directory)
|
|
44
|
+
|
|
45
|
+
Each widget gets:
|
|
46
|
+
- Hashed bundle for caching
|
|
47
|
+
- Standalone HTML file
|
|
48
|
+
- All dependencies bundled
|
|
49
|
+
|
|
50
|
+
### Production Start
|
|
51
|
+
|
|
52
|
+
```bash
|
|
53
|
+
mcp-use start [options]
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Starts the production server from built files.
|
|
57
|
+
|
|
58
|
+
Options:
|
|
59
|
+
- `-p, --path <path>` - Project directory (default: current directory)
|
|
60
|
+
- `--port <port>` - Server port (default: 3000)
|
|
61
|
+
|
|
62
|
+
## Examples
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
# Start development with auto-reload and inspector
|
|
66
|
+
mcp-use dev
|
|
67
|
+
|
|
68
|
+
# Development on custom port
|
|
69
|
+
mcp-use dev --port 8080
|
|
70
|
+
|
|
71
|
+
# Development without auto-opening inspector
|
|
72
|
+
mcp-use dev --no-open
|
|
73
|
+
|
|
74
|
+
# Build for production
|
|
75
|
+
mcp-use build
|
|
76
|
+
|
|
77
|
+
# Start production server
|
|
78
|
+
mcp-use start
|
|
79
|
+
|
|
80
|
+
# All commands support custom project path
|
|
81
|
+
mcp-use dev -p ./my-app
|
|
82
|
+
mcp-use build -p ./my-app
|
|
83
|
+
mcp-use start -p ./my-app
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Project Structure
|
|
87
|
+
|
|
88
|
+
```
|
|
89
|
+
my-app/
|
|
90
|
+
├── resources/
|
|
91
|
+
│ ├── todo-list.tsx
|
|
92
|
+
│ └── kanban-board.tsx
|
|
93
|
+
└── dist/
|
|
94
|
+
└── resources/
|
|
95
|
+
└── mcp-use/
|
|
96
|
+
└── widgets/
|
|
97
|
+
├── todo-list/
|
|
98
|
+
│ ├── index.html
|
|
99
|
+
│ └── assets/
|
|
100
|
+
└── kanban-board/
|
|
101
|
+
├── index.html
|
|
102
|
+
└── assets/
|
|
103
|
+
```
|
|
104
|
+
|
package/dist/build.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare function buildWidgets(projectPath: string): Promise<void>;
|
|
1
|
+
export declare function buildWidgets(projectPath: string, watch?: boolean): Promise<void>;
|
|
2
2
|
//# sourceMappingURL=build.d.ts.map
|
package/dist/build.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"build.d.ts","sourceRoot":"","sources":["../src/build.ts"],"names":[],"mappings":"AAmGA,wBAAsB,YAAY,CAAC,WAAW,EAAE,MAAM,EAAE,KAAK,UAAQ,iBA4FpE"}
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,376 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
"use strict";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
3
|
+
var __create = Object.create;
|
|
4
|
+
var __defProp = Object.defineProperty;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
+
var __copyProps = (to, from, except, desc) => {
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
11
|
+
for (let key of __getOwnPropNames(from))
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
13
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
14
|
+
}
|
|
15
|
+
return to;
|
|
16
|
+
};
|
|
17
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
18
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
19
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
20
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
21
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
22
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
23
|
+
mod
|
|
24
|
+
));
|
|
25
|
+
|
|
26
|
+
// src/index.ts
|
|
27
|
+
var import_commander = require("commander");
|
|
28
|
+
|
|
29
|
+
// src/build.ts
|
|
30
|
+
var import_node_fs = require("fs");
|
|
31
|
+
var import_node_path = __toESM(require("path"));
|
|
32
|
+
var import_esbuild = require("esbuild");
|
|
33
|
+
var import_globby = require("globby");
|
|
34
|
+
var ROUTE_PREFIX = "/mcp-use/widgets";
|
|
35
|
+
var SRC_DIR = "resources";
|
|
36
|
+
var OUT_DIR = "dist/resources";
|
|
37
|
+
function toRoute(file) {
|
|
38
|
+
const rel = file.replace(new RegExp(`^${SRC_DIR}/`), "").replace(/\.tsx?$/, "");
|
|
39
|
+
return `${ROUTE_PREFIX}/${rel}`;
|
|
40
|
+
}
|
|
41
|
+
function outDirForRoute(route) {
|
|
42
|
+
return import_node_path.default.join(OUT_DIR, route.replace(/^\//, ""));
|
|
43
|
+
}
|
|
44
|
+
function htmlTemplate({ title, scriptPath }) {
|
|
45
|
+
return `<!doctype html>
|
|
46
|
+
<html lang="en">
|
|
47
|
+
<head>
|
|
48
|
+
<meta charset="UTF-8" />
|
|
49
|
+
<meta name="viewport" content="width=device-width,initial-scale=1" />
|
|
50
|
+
<title>${title} Widget</title>
|
|
51
|
+
<style>
|
|
52
|
+
body {
|
|
53
|
+
margin: 0;
|
|
54
|
+
padding: 20px;
|
|
55
|
+
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Roboto', sans-serif;
|
|
56
|
+
background: #f5f5f5;
|
|
57
|
+
}
|
|
58
|
+
#widget-root {
|
|
59
|
+
max-width: 1200px;
|
|
60
|
+
margin: 0 auto;
|
|
61
|
+
}
|
|
62
|
+
</style>
|
|
63
|
+
</head>
|
|
64
|
+
<body>
|
|
65
|
+
<div id="widget-root"></div>
|
|
66
|
+
<script type="module" src="${scriptPath}"></script>
|
|
67
|
+
</body>
|
|
68
|
+
</html>`;
|
|
69
|
+
}
|
|
70
|
+
async function buildWidget(entry, projectPath, minify = true) {
|
|
71
|
+
const relativePath = import_node_path.default.relative(projectPath, entry);
|
|
72
|
+
const route = toRoute(relativePath);
|
|
73
|
+
const pageOutDir = import_node_path.default.join(projectPath, outDirForRoute(route));
|
|
74
|
+
const baseName = import_node_path.default.parse(entry).name;
|
|
75
|
+
await (0, import_esbuild.build)({
|
|
76
|
+
entryPoints: [entry],
|
|
77
|
+
bundle: true,
|
|
78
|
+
splitting: true,
|
|
79
|
+
format: "esm",
|
|
80
|
+
platform: "browser",
|
|
81
|
+
target: "es2018",
|
|
82
|
+
sourcemap: !minify,
|
|
83
|
+
minify,
|
|
84
|
+
outdir: import_node_path.default.join(pageOutDir, "assets"),
|
|
85
|
+
logLevel: "silent",
|
|
86
|
+
loader: {
|
|
87
|
+
".svg": "file",
|
|
88
|
+
".png": "file",
|
|
89
|
+
".jpg": "file",
|
|
90
|
+
".jpeg": "file",
|
|
91
|
+
".gif": "file",
|
|
92
|
+
".css": "css"
|
|
93
|
+
},
|
|
94
|
+
entryNames: `[name]-[hash]`,
|
|
95
|
+
chunkNames: `chunk-[hash]`,
|
|
96
|
+
assetNames: `asset-[hash]`,
|
|
97
|
+
define: {
|
|
98
|
+
"process.env.NODE_ENV": minify ? '"production"' : '"development"'
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
const files = await import_node_fs.promises.readdir(import_node_path.default.join(pageOutDir, "assets"));
|
|
102
|
+
const mainJs = files.find((f) => f.startsWith(`${baseName}-`) && f.endsWith(".js"));
|
|
103
|
+
if (!mainJs)
|
|
104
|
+
throw new Error(`Failed to locate entry JS for ${entry}`);
|
|
105
|
+
await import_node_fs.promises.mkdir(pageOutDir, { recursive: true });
|
|
106
|
+
await import_node_fs.promises.writeFile(
|
|
107
|
+
import_node_path.default.join(pageOutDir, "index.html"),
|
|
108
|
+
htmlTemplate({
|
|
109
|
+
title: baseName,
|
|
110
|
+
scriptPath: `./assets/${mainJs}`
|
|
111
|
+
}),
|
|
112
|
+
"utf8"
|
|
113
|
+
);
|
|
114
|
+
return { baseName, route };
|
|
115
|
+
}
|
|
116
|
+
async function buildWidgets(projectPath, watch = false) {
|
|
117
|
+
const srcDir = import_node_path.default.join(projectPath, SRC_DIR);
|
|
118
|
+
const outDir = import_node_path.default.join(projectPath, OUT_DIR);
|
|
119
|
+
await import_node_fs.promises.rm(outDir, { recursive: true, force: true });
|
|
120
|
+
const entries = await (0, import_globby.globby)([`${srcDir}/**/*.tsx`]);
|
|
121
|
+
if (!watch) {
|
|
122
|
+
console.log(`Building ${entries.length} widget files...`);
|
|
123
|
+
}
|
|
124
|
+
if (watch) {
|
|
125
|
+
const contexts = [];
|
|
126
|
+
for (const entry of entries) {
|
|
127
|
+
const relativePath = import_node_path.default.relative(projectPath, entry);
|
|
128
|
+
const route = toRoute(relativePath);
|
|
129
|
+
const pageOutDir = import_node_path.default.join(projectPath, outDirForRoute(route));
|
|
130
|
+
const baseName = import_node_path.default.parse(entry).name;
|
|
131
|
+
const ctx = await (0, import_esbuild.context)({
|
|
132
|
+
entryPoints: [entry],
|
|
133
|
+
bundle: true,
|
|
134
|
+
splitting: true,
|
|
135
|
+
format: "esm",
|
|
136
|
+
platform: "browser",
|
|
137
|
+
target: "es2018",
|
|
138
|
+
sourcemap: true,
|
|
139
|
+
minify: false,
|
|
140
|
+
outdir: import_node_path.default.join(pageOutDir, "assets"),
|
|
141
|
+
logLevel: "silent",
|
|
142
|
+
loader: {
|
|
143
|
+
".svg": "file",
|
|
144
|
+
".png": "file",
|
|
145
|
+
".jpg": "file",
|
|
146
|
+
".jpeg": "file",
|
|
147
|
+
".gif": "file",
|
|
148
|
+
".css": "css"
|
|
149
|
+
},
|
|
150
|
+
entryNames: `[name]-[hash]`,
|
|
151
|
+
chunkNames: `chunk-[hash]`,
|
|
152
|
+
assetNames: `asset-[hash]`,
|
|
153
|
+
define: {
|
|
154
|
+
"process.env.NODE_ENV": '"development"'
|
|
155
|
+
},
|
|
156
|
+
plugins: [{
|
|
157
|
+
name: "html-writer",
|
|
158
|
+
setup(build2) {
|
|
159
|
+
build2.onEnd(async () => {
|
|
160
|
+
try {
|
|
161
|
+
const files = await import_node_fs.promises.readdir(import_node_path.default.join(pageOutDir, "assets"));
|
|
162
|
+
const mainJs = files.find((f) => f.startsWith(`${baseName}-`) && f.endsWith(".js"));
|
|
163
|
+
if (mainJs) {
|
|
164
|
+
await import_node_fs.promises.mkdir(pageOutDir, { recursive: true });
|
|
165
|
+
await import_node_fs.promises.writeFile(
|
|
166
|
+
import_node_path.default.join(pageOutDir, "index.html"),
|
|
167
|
+
htmlTemplate({
|
|
168
|
+
title: baseName,
|
|
169
|
+
scriptPath: `./assets/${mainJs}`
|
|
170
|
+
}),
|
|
171
|
+
"utf8"
|
|
172
|
+
);
|
|
173
|
+
}
|
|
174
|
+
} catch (err) {
|
|
175
|
+
console.error(`Error writing HTML for ${baseName}:`, err);
|
|
176
|
+
}
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
}]
|
|
180
|
+
});
|
|
181
|
+
contexts.push(ctx);
|
|
182
|
+
}
|
|
183
|
+
for (const ctx of contexts) {
|
|
184
|
+
await ctx.watch();
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
for (const entry of entries) {
|
|
188
|
+
const { baseName, route } = await buildWidget(entry, projectPath);
|
|
189
|
+
console.log(`\x1B[32m\u2713\x1B[0m Built ${baseName} -> ${route}`);
|
|
190
|
+
}
|
|
191
|
+
console.log("Build complete!");
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
// src/index.ts
|
|
196
|
+
var import_node_child_process = require("child_process");
|
|
197
|
+
var import_node_fs2 = require("fs");
|
|
198
|
+
var import_node_path2 = __toESM(require("path"));
|
|
199
|
+
var import_open = __toESM(require("open"));
|
|
200
|
+
var program = new import_commander.Command();
|
|
201
|
+
program.name("mcp-use").description("MCP CLI tool").version("2.0.1");
|
|
202
|
+
async function isPortAvailable(port) {
|
|
203
|
+
try {
|
|
204
|
+
const response = await fetch(`http://localhost:${port}`);
|
|
205
|
+
return false;
|
|
206
|
+
} catch {
|
|
207
|
+
return true;
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
async function findAvailablePort(startPort) {
|
|
211
|
+
for (let port = startPort; port < startPort + 100; port++) {
|
|
212
|
+
if (await isPortAvailable(port)) {
|
|
213
|
+
return port;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
throw new Error("No available ports found");
|
|
217
|
+
}
|
|
218
|
+
async function waitForServer(port, maxAttempts = 30) {
|
|
219
|
+
for (let i = 0; i < maxAttempts; i++) {
|
|
220
|
+
try {
|
|
221
|
+
const response = await fetch(`http://localhost:${port}/inspector`);
|
|
222
|
+
if (response.ok) {
|
|
223
|
+
return true;
|
|
224
|
+
}
|
|
225
|
+
} catch {
|
|
226
|
+
}
|
|
227
|
+
await new Promise((resolve) => setTimeout(resolve, 1e3));
|
|
228
|
+
}
|
|
229
|
+
return false;
|
|
230
|
+
}
|
|
231
|
+
function runCommand(command, args, cwd) {
|
|
232
|
+
return new Promise((resolve, reject) => {
|
|
233
|
+
const proc = (0, import_node_child_process.spawn)(command, args, {
|
|
234
|
+
cwd,
|
|
235
|
+
stdio: "inherit",
|
|
236
|
+
shell: false
|
|
237
|
+
});
|
|
238
|
+
proc.on("error", reject);
|
|
239
|
+
proc.on("exit", (code) => {
|
|
240
|
+
if (code === 0) {
|
|
241
|
+
resolve();
|
|
242
|
+
} else {
|
|
243
|
+
reject(new Error(`Command failed with exit code ${code}`));
|
|
244
|
+
}
|
|
245
|
+
});
|
|
246
|
+
});
|
|
247
|
+
}
|
|
248
|
+
program.command("build").description("Build TypeScript and MCP UI widgets").option("-p, --path <path>", "Path to project directory", process.cwd()).action(async (options) => {
|
|
249
|
+
try {
|
|
250
|
+
const projectPath = import_node_path2.default.resolve(options.path);
|
|
251
|
+
console.log("\x1B[36m\x1B[1mmcp-use\x1B[0m \x1B[90mVersion: 2.0.1\x1B[0m\n");
|
|
252
|
+
console.log("Building TypeScript...");
|
|
253
|
+
await runCommand("npx", ["tsc"], projectPath);
|
|
254
|
+
console.log("\x1B[32m\u2713\x1B[0m TypeScript build complete!");
|
|
255
|
+
await buildWidgets(projectPath, false);
|
|
256
|
+
} catch (error) {
|
|
257
|
+
console.error("Build failed:", error);
|
|
258
|
+
process.exit(1);
|
|
259
|
+
}
|
|
260
|
+
});
|
|
261
|
+
program.command("dev").description("Run development server with auto-reload and inspector").option("-p, --path <path>", "Path to project directory", process.cwd()).option("--port <port>", "Server port", "3000").option("--no-open", "Do not auto-open inspector").action(async (options) => {
|
|
262
|
+
try {
|
|
263
|
+
const projectPath = import_node_path2.default.resolve(options.path);
|
|
264
|
+
let port = parseInt(options.port, 10);
|
|
265
|
+
console.log("\x1B[36m\x1B[1mmcp-use\x1B[0m \x1B[90mVersion: 2.0.1\x1B[0m\n");
|
|
266
|
+
if (!await isPortAvailable(port)) {
|
|
267
|
+
console.log(`\x1B[33m\u26A0\uFE0F Port ${port} is already in use\x1B[0m`);
|
|
268
|
+
const availablePort = await findAvailablePort(port);
|
|
269
|
+
console.log(`\x1B[32m\u2713\x1B[0m Using port ${availablePort} instead`);
|
|
270
|
+
port = availablePort;
|
|
271
|
+
}
|
|
272
|
+
let serverFile = "src/server.ts";
|
|
16
273
|
try {
|
|
17
|
-
|
|
274
|
+
await import_node_fs2.promises.access(import_node_path2.default.join(projectPath, serverFile));
|
|
275
|
+
} catch {
|
|
276
|
+
serverFile = "src/index.ts";
|
|
18
277
|
}
|
|
19
|
-
|
|
20
|
-
|
|
278
|
+
const processes = [];
|
|
279
|
+
const tscProc = (0, import_node_child_process.spawn)("npx", ["tsc", "--watch"], {
|
|
280
|
+
cwd: projectPath,
|
|
281
|
+
stdio: "pipe",
|
|
282
|
+
shell: false
|
|
283
|
+
});
|
|
284
|
+
tscProc.stdout?.on("data", (data) => {
|
|
285
|
+
const output = data.toString();
|
|
286
|
+
if (output.includes("Watching for file changes")) {
|
|
287
|
+
console.log("\x1B[32m\u2713\x1B[0m TypeScript compiler watching...");
|
|
288
|
+
}
|
|
289
|
+
});
|
|
290
|
+
processes.push(tscProc);
|
|
291
|
+
buildWidgets(projectPath, true).catch((error) => {
|
|
292
|
+
console.error("Widget builder failed:", error);
|
|
293
|
+
});
|
|
294
|
+
await new Promise((resolve) => setTimeout(resolve, 2e3));
|
|
295
|
+
const serverProc = (0, import_node_child_process.spawn)("npx", ["tsx", "watch", serverFile], {
|
|
296
|
+
cwd: projectPath,
|
|
297
|
+
stdio: "pipe",
|
|
298
|
+
shell: false,
|
|
299
|
+
env: { ...process.env, PORT: String(port) }
|
|
300
|
+
});
|
|
301
|
+
serverProc.stderr?.on("data", (data) => {
|
|
302
|
+
const output = data.toString();
|
|
303
|
+
if (output.includes("EADDRINUSE")) {
|
|
304
|
+
console.log(`\x1B[31m\u2717\x1B[0m Port ${port} is still in use. Please try a different port with --port`);
|
|
305
|
+
console.log(`\x1B[90mHint: Use --port 3001 or kill the process using port ${port}\x1B[0m`);
|
|
21
306
|
process.exit(1);
|
|
307
|
+
}
|
|
308
|
+
});
|
|
309
|
+
serverProc.stdout?.on("data", (data) => {
|
|
310
|
+
process.stdout.write(data);
|
|
311
|
+
});
|
|
312
|
+
processes.push(serverProc);
|
|
313
|
+
if (options.open !== false) {
|
|
314
|
+
const startTime = Date.now();
|
|
315
|
+
const ready = await waitForServer(port);
|
|
316
|
+
if (ready) {
|
|
317
|
+
const mcpUrl = `http://localhost:${port}/mcp`;
|
|
318
|
+
const inspectorUrl = `http://localhost:${port}/inspector?autoConnect=${encodeURIComponent(mcpUrl)}`;
|
|
319
|
+
const readyTime = Date.now() - startTime;
|
|
320
|
+
console.log(`
|
|
321
|
+
\x1B[32m\u2713\x1B[0m Ready in ${readyTime}ms`);
|
|
322
|
+
console.log(`Local: http://localhost:${port}`);
|
|
323
|
+
console.log(`Network: http://localhost:${port}`);
|
|
324
|
+
console.log(`MCP: ${mcpUrl}`);
|
|
325
|
+
console.log(`Inspector: ${inspectorUrl}
|
|
326
|
+
`);
|
|
327
|
+
await (0, import_open.default)(inspectorUrl);
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
const cleanup = () => {
|
|
331
|
+
console.log("\n\nShutting down...");
|
|
332
|
+
processes.forEach((proc) => proc.kill());
|
|
333
|
+
process.exit(0);
|
|
334
|
+
};
|
|
335
|
+
process.on("SIGINT", cleanup);
|
|
336
|
+
process.on("SIGTERM", cleanup);
|
|
337
|
+
await new Promise(() => {
|
|
338
|
+
});
|
|
339
|
+
} catch (error) {
|
|
340
|
+
console.error("Dev mode failed:", error);
|
|
341
|
+
process.exit(1);
|
|
342
|
+
}
|
|
343
|
+
});
|
|
344
|
+
program.command("start").description("Start production server").option("-p, --path <path>", "Path to project directory", process.cwd()).option("--port <port>", "Server port", "3000").action(async (options) => {
|
|
345
|
+
try {
|
|
346
|
+
const projectPath = import_node_path2.default.resolve(options.path);
|
|
347
|
+
const port = parseInt(options.port, 10);
|
|
348
|
+
console.log("\x1B[36m\x1B[1mmcp-use\x1B[0m \x1B[90mVersion: 2.0.1\x1B[0m\n");
|
|
349
|
+
let serverFile = "dist/server.js";
|
|
350
|
+
try {
|
|
351
|
+
await import_node_fs2.promises.access(import_node_path2.default.join(projectPath, serverFile));
|
|
352
|
+
} catch {
|
|
353
|
+
serverFile = "dist/index.js";
|
|
22
354
|
}
|
|
355
|
+
console.log("Starting production server...");
|
|
356
|
+
const serverProc = (0, import_node_child_process.spawn)("node", [serverFile], {
|
|
357
|
+
cwd: projectPath,
|
|
358
|
+
stdio: "inherit",
|
|
359
|
+
env: { ...process.env, PORT: String(port) }
|
|
360
|
+
});
|
|
361
|
+
const cleanup = () => {
|
|
362
|
+
console.log("\n\nShutting down...");
|
|
363
|
+
serverProc.kill();
|
|
364
|
+
process.exit(0);
|
|
365
|
+
};
|
|
366
|
+
process.on("SIGINT", cleanup);
|
|
367
|
+
process.on("SIGTERM", cleanup);
|
|
368
|
+
serverProc.on("exit", (code) => {
|
|
369
|
+
process.exit(code || 0);
|
|
370
|
+
});
|
|
371
|
+
} catch (error) {
|
|
372
|
+
console.error("Start failed:", error);
|
|
373
|
+
process.exit(1);
|
|
374
|
+
}
|
|
23
375
|
});
|
|
24
376
|
program.parse();
|
|
25
|
-
//# sourceMappingURL=index.js.map
|