init
Initialize a new package.json file to set up Node.js projects by specifying directory path and optional package scope.
Instructions
Initialize a new package.json
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the directory | |
| scope | No | Scope for the package (e.g. @myorg) |
Implementation Reference
- src/index.ts:302-322 (handler)The 'init' tool is registered and implemented directly in src/index.ts. It calls the 'run' helper function with the 'init' command to initialize a package.json file.
server.tool( "init", "Initialize a new package.json", { path: z.string().describe("Absolute path to the directory"), scope: z.string().optional().describe("Scope for the package (e.g. @myorg)"), }, async ({ path, scope }) => { const args = ["init", "-y"]; if (scope) args.push("--scope", scope); try { const { stdout } = await run(args, path); return { content: [{ type: "text", text: stdout }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, );