npmBuild
Execute npm build commands to automate project compilation, streamlining the build process within the GonMCPtool MCP server environment.
Instructions
執行npm build命令構建專案
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| options | No | ||
| path | No |
Implementation Reference
- tools/npmBuildTool.ts:16-39 (handler)Core handler logic: static method executeBuild that runs 'cd {path} && npm run build {options}' using promisified child_process.exec, logs output, and returns stdout/stderr.static async executeBuild(path: string = '.', options: string = ''): Promise<{ stdout: string; stderr: string }> { try { console.log(`執行 npm build ${options} 在路徑 ${path}`); // 構建完整指令 const command = `cd ${path} && npm run build ${options}`; // 執行指令 const { stdout, stderr } = await execPromise(command); if (stdout) { console.log('Build輸出:', stdout); } if (stderr && !stderr.includes('npm notice')) { console.error('Build錯誤:', stderr); } return { stdout, stderr }; } catch (error) { console.error('Build執行失敗:', error); throw error; } }
- main.ts:36-36 (schema)Zod input schema for the npmBuild tool: optional path (default '.') and options (default '').{ path: z.string().optional(), options: z.string().optional() },
- main.ts:34-48 (registration)MCP server.tool registration for 'npmBuild', including description, schema, and wrapper handler that delegates to NpmBuildTool.executeBuild and formats response as MCP content.server.tool("npmBuild", "執行npm build命令構建專案", { path: z.string().optional(), options: z.string().optional() }, async ({ path = ".", options = "" }) => { try { const result = await NpmBuildTool.executeBuild(path, options); return { content: [{ type: "text", text: `Build completed successfully: ${result.stdout}` }] }; } catch (error) { return { content: [{ type: "text", text: `Build failed: ${error instanceof Error ? error.message : "Unknown error"}` }] }; } });