@zohairhussain/mcp-scaffold-studio 0.1.0 → 0.1.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 -3
- package/dist/index.js +298 -26
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,7 +18,7 @@ Requires **Node.js 22.12 or newer**.
|
|
|
18
18
|
npx -y @zohairhussain/mcp-scaffold-studio
|
|
19
19
|
```
|
|
20
20
|
|
|
21
|
-
|
|
21
|
+
When run directly in an interactive terminal (or with `--setup`), it asks whether you want to auto-configure an MCP client or view manual setup instructions. When launched by an MCP client over stdio (or with `--stdio`), it starts the MCP server silently.
|
|
22
22
|
|
|
23
23
|
## Tools
|
|
24
24
|
|
|
@@ -140,8 +140,7 @@ Edit `opencode.json` (or the global OpenCode config):
|
|
|
140
140
|
"servers": {
|
|
141
141
|
"scaffold-studio": {
|
|
142
142
|
"type": "local",
|
|
143
|
-
"command": ["npx", "-y", "@zohairhussain/mcp-scaffold-studio"]
|
|
144
|
-
"enabled": true
|
|
143
|
+
"command": ["npx", "-y", "@zohairhussain/mcp-scaffold-studio"]
|
|
145
144
|
}
|
|
146
145
|
}
|
|
147
146
|
}
|
package/dist/index.js
CHANGED
|
@@ -6,13 +6,246 @@ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js"
|
|
|
6
6
|
import { readFileSync, realpathSync } from "fs";
|
|
7
7
|
import { fileURLToPath } from "url";
|
|
8
8
|
|
|
9
|
+
// src/cli/setup.ts
|
|
10
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
11
|
+
import os from "os";
|
|
12
|
+
import path from "path";
|
|
13
|
+
import { createInterface } from "readline/promises";
|
|
14
|
+
var SERVER_KEY = "scaffold-studio";
|
|
15
|
+
function buildStandardMcpEntry(packageName) {
|
|
16
|
+
return {
|
|
17
|
+
command: "npx",
|
|
18
|
+
args: ["-y", packageName]
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
function mergeNestedRecord(root, key, entryKey, entryValue) {
|
|
22
|
+
const current = root[key];
|
|
23
|
+
const section = current !== null && typeof current === "object" && !Array.isArray(current) ? { ...current } : {};
|
|
24
|
+
section[entryKey] = entryValue;
|
|
25
|
+
return { ...root, [key]: section };
|
|
26
|
+
}
|
|
27
|
+
function getClaudeDesktopConfigPath(platform, homeDir, appDataDir) {
|
|
28
|
+
if (platform === "win32") {
|
|
29
|
+
const base = appDataDir || path.join(homeDir, "AppData", "Roaming");
|
|
30
|
+
return path.join(base, "Claude", "claude_desktop_config.json");
|
|
31
|
+
}
|
|
32
|
+
if (platform === "darwin") {
|
|
33
|
+
return path.join(homeDir, "Library", "Application Support", "Claude", "claude_desktop_config.json");
|
|
34
|
+
}
|
|
35
|
+
return path.join(homeDir, ".config", "Claude", "claude_desktop_config.json");
|
|
36
|
+
}
|
|
37
|
+
function getClientTargets(env) {
|
|
38
|
+
return [
|
|
39
|
+
{
|
|
40
|
+
id: "claude-desktop",
|
|
41
|
+
label: "Claude Desktop (global)",
|
|
42
|
+
configPath: getClaudeDesktopConfigPath(env.platform, env.homeDir, env.appDataDir),
|
|
43
|
+
applyConfig: (existing, packageName) => mergeNestedRecord(existing, "mcpServers", SERVER_KEY, buildStandardMcpEntry(packageName))
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
id: "cursor-global",
|
|
47
|
+
label: "Cursor (global ~/.cursor/mcp.json)",
|
|
48
|
+
configPath: path.join(env.homeDir, ".cursor", "mcp.json"),
|
|
49
|
+
applyConfig: (existing, packageName) => mergeNestedRecord(existing, "mcpServers", SERVER_KEY, buildStandardMcpEntry(packageName))
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
id: "cursor-project",
|
|
53
|
+
label: "Cursor (current project .cursor/mcp.json)",
|
|
54
|
+
configPath: path.join(env.cwd, ".cursor", "mcp.json"),
|
|
55
|
+
applyConfig: (existing, packageName) => mergeNestedRecord(existing, "mcpServers", SERVER_KEY, buildStandardMcpEntry(packageName))
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
id: "windsurf",
|
|
59
|
+
label: "Windsurf (global ~/.codeium/windsurf/mcp_config.json)",
|
|
60
|
+
configPath: path.join(env.homeDir, ".codeium", "windsurf", "mcp_config.json"),
|
|
61
|
+
applyConfig: (existing, packageName) => mergeNestedRecord(existing, "mcpServers", SERVER_KEY, buildStandardMcpEntry(packageName))
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
id: "vscode",
|
|
65
|
+
label: "VS Code / GitHub Copilot (current project .vscode/mcp.json)",
|
|
66
|
+
configPath: path.join(env.cwd, ".vscode", "mcp.json"),
|
|
67
|
+
applyConfig: (existing, packageName) => mergeNestedRecord(existing, "servers", SERVER_KEY, {
|
|
68
|
+
type: "stdio",
|
|
69
|
+
...buildStandardMcpEntry(packageName)
|
|
70
|
+
})
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: "gemini-cli",
|
|
74
|
+
label: "Gemini CLI (global ~/.gemini/settings.json)",
|
|
75
|
+
configPath: path.join(env.homeDir, ".gemini", "settings.json"),
|
|
76
|
+
applyConfig: (existing, packageName) => mergeNestedRecord(existing, "mcpServers", SERVER_KEY, buildStandardMcpEntry(packageName))
|
|
77
|
+
},
|
|
78
|
+
{
|
|
79
|
+
id: "opencode",
|
|
80
|
+
label: "OpenCode (current project opencode.json)",
|
|
81
|
+
configPath: path.join(env.cwd, "opencode.json"),
|
|
82
|
+
applyConfig: (existing, packageName) => {
|
|
83
|
+
const mcpCurrent = existing["mcp"];
|
|
84
|
+
const mcpObj = mcpCurrent !== null && typeof mcpCurrent === "object" && !Array.isArray(mcpCurrent) ? { ...mcpCurrent } : {};
|
|
85
|
+
const updatedMcp = mergeNestedRecord(mcpObj, "servers", SERVER_KEY, {
|
|
86
|
+
type: "local",
|
|
87
|
+
command: ["npx", "-y", packageName]
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
$schema: "https://opencode.ai/config.json",
|
|
91
|
+
...existing,
|
|
92
|
+
mcp: updatedMcp
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
}
|
|
98
|
+
function formatManualInstructions(packageName, targets) {
|
|
99
|
+
const lines = [
|
|
100
|
+
"",
|
|
101
|
+
"Manual Setup Instructions:",
|
|
102
|
+
"--------------------------",
|
|
103
|
+
"This server speaks MCP over stdio, so register it in your AI client instead of running it directly.",
|
|
104
|
+
"",
|
|
105
|
+
"1) Standard JSON config (Claude Desktop, Cursor, Windsurf, Gemini CLI):",
|
|
106
|
+
JSON.stringify(
|
|
107
|
+
{
|
|
108
|
+
mcpServers: {
|
|
109
|
+
[SERVER_KEY]: buildStandardMcpEntry(packageName)
|
|
110
|
+
}
|
|
111
|
+
},
|
|
112
|
+
null,
|
|
113
|
+
2
|
|
114
|
+
),
|
|
115
|
+
"",
|
|
116
|
+
"2) VS Code / GitHub Copilot (.vscode/mcp.json):",
|
|
117
|
+
JSON.stringify(
|
|
118
|
+
{
|
|
119
|
+
servers: {
|
|
120
|
+
[SERVER_KEY]: {
|
|
121
|
+
type: "stdio",
|
|
122
|
+
...buildStandardMcpEntry(packageName)
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
},
|
|
126
|
+
null,
|
|
127
|
+
2
|
|
128
|
+
),
|
|
129
|
+
"",
|
|
130
|
+
"3) Claude Code (run in terminal):",
|
|
131
|
+
` claude mcp add ${SERVER_KEY} -- npx -y ${packageName}`,
|
|
132
|
+
"",
|
|
133
|
+
"4) Config file locations on this machine:",
|
|
134
|
+
...targets.map((target) => ` - ${target.label}: ${target.configPath}`),
|
|
135
|
+
"",
|
|
136
|
+
"Tip: To force stdio server mode from a terminal, run:",
|
|
137
|
+
` npx -y ${packageName} --stdio`,
|
|
138
|
+
""
|
|
139
|
+
];
|
|
140
|
+
return lines.join("\n");
|
|
141
|
+
}
|
|
142
|
+
async function writeClientConfig(target, packageName) {
|
|
143
|
+
let existing = {};
|
|
144
|
+
try {
|
|
145
|
+
const raw = await readFile(target.configPath, "utf8");
|
|
146
|
+
const trimmed = raw.trim();
|
|
147
|
+
if (trimmed.length > 0) {
|
|
148
|
+
const parsed = JSON.parse(trimmed);
|
|
149
|
+
if (parsed === null || typeof parsed !== "object" || Array.isArray(parsed)) {
|
|
150
|
+
throw new Error(`Expected a JSON object in ${target.configPath}`);
|
|
151
|
+
}
|
|
152
|
+
existing = parsed;
|
|
153
|
+
}
|
|
154
|
+
} catch (error) {
|
|
155
|
+
const err = error;
|
|
156
|
+
if (err.code !== "ENOENT") {
|
|
157
|
+
throw error;
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const updated = target.applyConfig(existing, packageName);
|
|
161
|
+
await mkdir(path.dirname(target.configPath), { recursive: true });
|
|
162
|
+
await writeFile(target.configPath, `${JSON.stringify(updated, null, 2)}
|
|
163
|
+
`, "utf8");
|
|
164
|
+
}
|
|
165
|
+
function formatCliHelp(packageName, version) {
|
|
166
|
+
return [
|
|
167
|
+
`${packageName} v${version}`,
|
|
168
|
+
"",
|
|
169
|
+
"Usage:",
|
|
170
|
+
` npx -y ${packageName} Start interactive setup in a terminal, or stdio MCP server when piped`,
|
|
171
|
+
` npx -y ${packageName} --setup Run interactive client configuration / instructions`,
|
|
172
|
+
` npx -y ${packageName} --stdio Force stdio MCP server mode`,
|
|
173
|
+
` npx -y ${packageName} --help Show this help message`,
|
|
174
|
+
` npx -y ${packageName} --version Show version`,
|
|
175
|
+
""
|
|
176
|
+
].join("\n");
|
|
177
|
+
}
|
|
178
|
+
async function runInteractiveSetup(env) {
|
|
179
|
+
const input = env.input ?? process.stdin;
|
|
180
|
+
const output = env.output ?? process.stdout;
|
|
181
|
+
const cwd = env.cwd ?? process.cwd();
|
|
182
|
+
const homeDir = env.homeDir ?? os.homedir();
|
|
183
|
+
const appDataDir = env.appDataDir ?? process.env.APPDATA;
|
|
184
|
+
const platform = env.platform ?? process.platform;
|
|
185
|
+
const targets = getClientTargets({ cwd, homeDir, appDataDir, platform });
|
|
186
|
+
const write = (text) => {
|
|
187
|
+
output.write(text);
|
|
188
|
+
};
|
|
189
|
+
write(`
|
|
190
|
+
${env.serverName} v${env.serverVersion}
|
|
191
|
+
`);
|
|
192
|
+
write("This is a stdio MCP server designed to run inside an AI client.\n\n");
|
|
193
|
+
const rl = createInterface({ input, output });
|
|
194
|
+
try {
|
|
195
|
+
const answer = (await rl.question("Do you want to auto-configure an MCP client now? (y/n): ")).trim().toLowerCase();
|
|
196
|
+
if (answer !== "y" && answer !== "yes") {
|
|
197
|
+
write(formatManualInstructions(env.serverName, targets));
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
write("\nSelect a client to configure:\n");
|
|
201
|
+
targets.forEach((target, index) => {
|
|
202
|
+
write(` ${index + 1}. ${target.label}
|
|
203
|
+
`);
|
|
204
|
+
});
|
|
205
|
+
write(` ${targets.length + 1}. Claude Code (show CLI command)
|
|
206
|
+
`);
|
|
207
|
+
write(" 0. Cancel and show manual instructions\n\n");
|
|
208
|
+
const choiceRaw = (await rl.question(`Enter choice (0-${targets.length + 1}): `)).trim();
|
|
209
|
+
const choice = Number.parseInt(choiceRaw, 10);
|
|
210
|
+
if (Number.isNaN(choice) || choice <= 0 || choice > targets.length + 1) {
|
|
211
|
+
write(formatManualInstructions(env.serverName, targets));
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
if (choice === targets.length + 1) {
|
|
215
|
+
write("\nRun this command in your terminal to add the server to Claude Code:\n");
|
|
216
|
+
write(` claude mcp add ${SERVER_KEY} -- npx -y ${env.serverName}
|
|
217
|
+
|
|
218
|
+
`);
|
|
219
|
+
return;
|
|
220
|
+
}
|
|
221
|
+
const selectedTarget = targets[choice - 1];
|
|
222
|
+
try {
|
|
223
|
+
await writeClientConfig(selectedTarget, env.serverName);
|
|
224
|
+
write(`
|
|
225
|
+
Configured ${selectedTarget.label} successfully!
|
|
226
|
+
`);
|
|
227
|
+
write(`Updated: ${selectedTarget.configPath}
|
|
228
|
+
`);
|
|
229
|
+
write("Restart your MCP client to load scaffold-studio.\n\n");
|
|
230
|
+
} catch (error) {
|
|
231
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
232
|
+
write(`
|
|
233
|
+
Could not auto-configure ${selectedTarget.label}: ${message}
|
|
234
|
+
`);
|
|
235
|
+
write(formatManualInstructions(env.serverName, targets));
|
|
236
|
+
}
|
|
237
|
+
} finally {
|
|
238
|
+
rl.close();
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
9
242
|
// src/tools/generateProjectScaffold.ts
|
|
10
|
-
import
|
|
243
|
+
import path4 from "path";
|
|
11
244
|
import { z as z2 } from "zod";
|
|
12
245
|
|
|
13
246
|
// src/lib/files.ts
|
|
14
|
-
import { mkdir as
|
|
15
|
-
import
|
|
247
|
+
import { mkdir as mkdir3, rm, stat as stat2, writeFile as writeFile2 } from "fs/promises";
|
|
248
|
+
import path3 from "path";
|
|
16
249
|
|
|
17
250
|
// src/lib/errors.ts
|
|
18
251
|
var ToolInputError = class extends Error {
|
|
@@ -40,8 +273,8 @@ function describeError(error) {
|
|
|
40
273
|
}
|
|
41
274
|
|
|
42
275
|
// src/lib/paths.ts
|
|
43
|
-
import { lstat, mkdir, realpath, stat } from "fs/promises";
|
|
44
|
-
import
|
|
276
|
+
import { lstat, mkdir as mkdir2, realpath, stat } from "fs/promises";
|
|
277
|
+
import path2 from "path";
|
|
45
278
|
var DEFAULT_ALLOWED_ROOT_ENV = "MCP_SCAFFOLD_ROOTS";
|
|
46
279
|
var PROJECT_NAME_PATTERN = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;
|
|
47
280
|
var WINDOWS_RESERVED_NAMES = /* @__PURE__ */ new Set([
|
|
@@ -92,8 +325,8 @@ function assertSafeProjectName(projectName) {
|
|
|
92
325
|
}
|
|
93
326
|
}
|
|
94
327
|
function isInside(parent, child) {
|
|
95
|
-
const relative =
|
|
96
|
-
return relative === "" || relative !== ".." && !relative.startsWith(`..${
|
|
328
|
+
const relative = path2.relative(parent, child);
|
|
329
|
+
return relative === "" || relative !== ".." && !relative.startsWith(`..${path2.sep}`) && !path2.isAbsolute(relative);
|
|
97
330
|
}
|
|
98
331
|
function isInsideAny(roots, candidate) {
|
|
99
332
|
return roots.some((root) => isInside(root, candidate));
|
|
@@ -109,13 +342,13 @@ function assertInsideRoots(roots, candidate, label) {
|
|
|
109
342
|
}
|
|
110
343
|
}
|
|
111
344
|
async function getAllowedRoots(options = {}) {
|
|
112
|
-
const cwd =
|
|
345
|
+
const cwd = path2.resolve(options.cwd ?? process.cwd());
|
|
113
346
|
const env = options.env ?? process.env;
|
|
114
|
-
const configured = (env[DEFAULT_ALLOWED_ROOT_ENV] ?? "").split(
|
|
347
|
+
const configured = (env[DEFAULT_ALLOWED_ROOT_ENV] ?? "").split(path2.delimiter).map((entry) => entry.trim()).filter(Boolean);
|
|
115
348
|
const requestedRoots = configured.length > 0 ? configured : [cwd];
|
|
116
349
|
const roots = [];
|
|
117
350
|
for (const requested of requestedRoots) {
|
|
118
|
-
const absolute =
|
|
351
|
+
const absolute = path2.isAbsolute(requested) ? path2.resolve(requested) : path2.resolve(cwd, requested);
|
|
119
352
|
let stats;
|
|
120
353
|
try {
|
|
121
354
|
stats = await stat(absolute);
|
|
@@ -155,7 +388,7 @@ async function assertExistingAncestorSafe(candidate, roots) {
|
|
|
155
388
|
} catch (error) {
|
|
156
389
|
const code = error.code;
|
|
157
390
|
if (code !== "ENOENT") throw error;
|
|
158
|
-
const parent =
|
|
391
|
+
const parent = path2.dirname(cursor);
|
|
159
392
|
if (parent === cursor) {
|
|
160
393
|
throw new PathSafetyError("Could not find an existing directory for the target path.", {
|
|
161
394
|
hint: "Choose a targetDir inside an existing allowed root."
|
|
@@ -178,8 +411,8 @@ async function resolveScaffoldTarget(options) {
|
|
|
178
411
|
if (rawTargetDir && rawTargetDir.includes("\0")) {
|
|
179
412
|
throw new PathSafetyError("targetDir contains an invalid null byte.");
|
|
180
413
|
}
|
|
181
|
-
const parentDirectory = rawTargetDir ?
|
|
182
|
-
const projectDirectory =
|
|
414
|
+
const parentDirectory = rawTargetDir ? path2.isAbsolute(rawTargetDir) ? path2.resolve(rawTargetDir) : path2.resolve(root, rawTargetDir) : root;
|
|
415
|
+
const projectDirectory = path2.join(parentDirectory, options.projectName);
|
|
183
416
|
assertInsideRoots(allowedRoots, parentDirectory, "targetDir");
|
|
184
417
|
assertInsideRoots(allowedRoots, projectDirectory, "Project directory");
|
|
185
418
|
await assertExistingAncestorSafe(parentDirectory, allowedRoots);
|
|
@@ -196,7 +429,7 @@ async function resolveScaffoldTarget(options) {
|
|
|
196
429
|
}
|
|
197
430
|
async function createScaffoldParentDirectory(target) {
|
|
198
431
|
try {
|
|
199
|
-
await
|
|
432
|
+
await mkdir2(target.parentDirectory, { recursive: true });
|
|
200
433
|
} catch (error) {
|
|
201
434
|
throw new ToolInputError(`Could not create targetDir: ${target.parentDirectory}`, {
|
|
202
435
|
hint: `Check permissions or choose another targetDir. ${error.message}`
|
|
@@ -211,7 +444,7 @@ async function createScaffoldParentDirectory(target) {
|
|
|
211
444
|
|
|
212
445
|
// src/lib/files.ts
|
|
213
446
|
function validateRelativeFilePath(filePath) {
|
|
214
|
-
if (filePath.length === 0 || filePath.includes("\0") || filePath.includes("\\") ||
|
|
447
|
+
if (filePath.length === 0 || filePath.includes("\0") || filePath.includes("\\") || path3.posix.isAbsolute(filePath) || filePath === "." || filePath === ".." || filePath.startsWith("../") || filePath.includes("/../") || filePath.endsWith("/..")) {
|
|
215
448
|
throw new PathSafetyError(`Refusing to write unsafe project file path: ${filePath}`);
|
|
216
449
|
}
|
|
217
450
|
}
|
|
@@ -226,18 +459,27 @@ async function createProjectTree(projectDirectory, files) {
|
|
|
226
459
|
}
|
|
227
460
|
seen.add(key);
|
|
228
461
|
}
|
|
229
|
-
|
|
462
|
+
try {
|
|
463
|
+
await mkdir3(projectDirectory, { recursive: false });
|
|
464
|
+
} catch (error) {
|
|
465
|
+
if (error.code === "EEXIST") {
|
|
466
|
+
throw new ToolInputError(`Target directory already exists: ${projectDirectory}`, {
|
|
467
|
+
hint: "Choose a different projectName or targetDir. This tool never overwrites existing folders."
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
throw error;
|
|
471
|
+
}
|
|
230
472
|
try {
|
|
231
473
|
const written = [];
|
|
232
474
|
for (const file2 of ordered) {
|
|
233
|
-
const absolutePath =
|
|
475
|
+
const absolutePath = path3.resolve(projectDirectory, ...file2.path.split("/"));
|
|
234
476
|
if (absolutePath === projectDirectory || !isInside(projectDirectory, absolutePath)) {
|
|
235
477
|
throw new PathSafetyError(`Generated file escapes the project directory: ${file2.path}`);
|
|
236
478
|
}
|
|
237
|
-
await
|
|
479
|
+
await mkdir3(path3.dirname(absolutePath), { recursive: true });
|
|
238
480
|
const content = file2.content.endsWith("\n") ? file2.content : `${file2.content}
|
|
239
481
|
`;
|
|
240
|
-
await
|
|
482
|
+
await writeFile2(absolutePath, content, { encoding: "utf8", flag: "wx" });
|
|
241
483
|
written.push({ path: file2.path, bytes: (await stat2(absolutePath)).size });
|
|
242
484
|
}
|
|
243
485
|
return written;
|
|
@@ -1372,8 +1614,8 @@ function json(value) {
|
|
|
1372
1614
|
return `${JSON.stringify(value, null, 2)}
|
|
1373
1615
|
`;
|
|
1374
1616
|
}
|
|
1375
|
-
function file(
|
|
1376
|
-
return { path:
|
|
1617
|
+
function file(path5, content) {
|
|
1618
|
+
return { path: path5, content };
|
|
1377
1619
|
}
|
|
1378
1620
|
function envExample(input) {
|
|
1379
1621
|
const lines = [
|
|
@@ -4543,9 +4785,9 @@ function shellQuote(value) {
|
|
|
4543
4785
|
return `"${value.replaceAll('"', '\\"')}"`;
|
|
4544
4786
|
}
|
|
4545
4787
|
function displayPath(cwd, targetDirectory) {
|
|
4546
|
-
const relative =
|
|
4788
|
+
const relative = path4.relative(cwd, targetDirectory);
|
|
4547
4789
|
if (relative === "") return ".";
|
|
4548
|
-
if (relative === ".." || relative.startsWith(`..${
|
|
4790
|
+
if (relative === ".." || relative.startsWith(`..${path4.sep}`) || path4.isAbsolute(relative)) {
|
|
4549
4791
|
return targetDirectory;
|
|
4550
4792
|
}
|
|
4551
4793
|
return relative;
|
|
@@ -4676,7 +4918,7 @@ async function generateProjectScaffold(input, options = {}) {
|
|
|
4676
4918
|
layout,
|
|
4677
4919
|
features: new Set(features)
|
|
4678
4920
|
});
|
|
4679
|
-
const cwd =
|
|
4921
|
+
const cwd = path4.resolve(options.cwd ?? process.cwd());
|
|
4680
4922
|
const target = await resolveScaffoldTarget({
|
|
4681
4923
|
projectName: parsed.projectName,
|
|
4682
4924
|
targetDir: parsed.targetDir,
|
|
@@ -5007,6 +5249,34 @@ async function main() {
|
|
|
5007
5249
|
const transport = new StdioServerTransport();
|
|
5008
5250
|
await server.connect(transport);
|
|
5009
5251
|
}
|
|
5252
|
+
function resolveCliAction(args, isTTY) {
|
|
5253
|
+
if (args.includes("--help") || args.includes("-h")) return "help";
|
|
5254
|
+
if (args.includes("--version") || args.includes("-v")) return "version";
|
|
5255
|
+
if (args.includes("--stdio")) return "stdio";
|
|
5256
|
+
if (args.includes("--setup") || args.includes("setup") || args.includes("init")) return "setup";
|
|
5257
|
+
return isTTY ? "setup" : "stdio";
|
|
5258
|
+
}
|
|
5259
|
+
async function runCli(args = process.argv.slice(2), isTTY = Boolean(process.stdin.isTTY)) {
|
|
5260
|
+
const action = resolveCliAction(args, isTTY);
|
|
5261
|
+
switch (action) {
|
|
5262
|
+
case "help":
|
|
5263
|
+
process.stdout.write(formatCliHelp(SERVER_NAME, SERVER_VERSION));
|
|
5264
|
+
return;
|
|
5265
|
+
case "version":
|
|
5266
|
+
process.stdout.write(`${SERVER_NAME} ${SERVER_VERSION}
|
|
5267
|
+
`);
|
|
5268
|
+
return;
|
|
5269
|
+
case "setup":
|
|
5270
|
+
await runInteractiveSetup({
|
|
5271
|
+
serverName: SERVER_NAME,
|
|
5272
|
+
serverVersion: SERVER_VERSION
|
|
5273
|
+
});
|
|
5274
|
+
return;
|
|
5275
|
+
case "stdio":
|
|
5276
|
+
await main();
|
|
5277
|
+
return;
|
|
5278
|
+
}
|
|
5279
|
+
}
|
|
5010
5280
|
function isDirectRun() {
|
|
5011
5281
|
const entryPoint = process.argv[1];
|
|
5012
5282
|
if (typeof entryPoint !== "string") return false;
|
|
@@ -5017,7 +5287,7 @@ function isDirectRun() {
|
|
|
5017
5287
|
}
|
|
5018
5288
|
}
|
|
5019
5289
|
if (isDirectRun()) {
|
|
5020
|
-
|
|
5290
|
+
runCli().catch((error) => {
|
|
5021
5291
|
console.error(`${SERVER_NAME} failed to start:`, error);
|
|
5022
5292
|
process.exitCode = 1;
|
|
5023
5293
|
});
|
|
@@ -5026,6 +5296,8 @@ export {
|
|
|
5026
5296
|
SERVER_NAME,
|
|
5027
5297
|
SERVER_VERSION,
|
|
5028
5298
|
createServer,
|
|
5029
|
-
main
|
|
5299
|
+
main,
|
|
5300
|
+
resolveCliAction,
|
|
5301
|
+
runCli
|
|
5030
5302
|
};
|
|
5031
5303
|
//# sourceMappingURL=index.js.map
|