version
Bump the package version by specifying the bump type (patch, minor, major, etc.), optional prerelease identifier, and whether to skip git tag creation. Requires the absolute path to the package directory.
Instructions
Bump the package version
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| path | Yes | Absolute path to the package directory | |
| bump | Yes | Version bump type | |
| preid | No | Prerelease identifier (e.g. alpha, beta) | |
| noGitTag | No | Skip git tag creation |
Implementation Reference
- src/index.ts:81-105 (registration)Registration of the 'version' tool on the MCP server with name 'version' and description 'Bump the package version'. Defines schema inputs (path, bump, preid, noGitTag) and the handler callback.
server.tool( "version", "Bump the package version", { path: z.string().describe("Absolute path to the package directory"), bump: z .enum(["patch", "minor", "major", "prepatch", "preminor", "premajor", "prerelease"]) .describe("Version bump type"), preid: z.string().optional().describe("Prerelease identifier (e.g. alpha, beta)"), noGitTag: z.boolean().optional().describe("Skip git tag creation"), }, async ({ path, bump, preid, noGitTag }) => { const args = ["version", bump]; if (preid) args.push("--preid", preid); if (noGitTag) args.push("--no-git-tag-version"); try { const { stdout } = await run(args, path); return { content: [{ type: "text", text: stdout.trim() }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, - src/index.ts:92-105 (handler)Handler function that executes the 'version' tool logic: constructs 'npm version <bump>' CLI args, calls the run() helper, and returns the stdout output or an error message.
async ({ path, bump, preid, noGitTag }) => { const args = ["version", bump]; if (preid) args.push("--preid", preid); if (noGitTag) args.push("--no-git-tag-version"); try { const { stdout } = await run(args, path); return { content: [{ type: "text", text: stdout.trim() }] }; } catch (e: any) { return { content: [{ type: "text", text: `Error: ${e.stderr || e.message}` }], isError: true, }; } }, - src/index.ts:84-91 (schema)Input schema for the 'version' tool: path (string), bump (enum of patch/minor/major/prepatch/preminor/premajor/prerelease), preid (optional string), noGitTag (optional boolean).
{ path: z.string().describe("Absolute path to the package directory"), bump: z .enum(["patch", "minor", "major", "prepatch", "preminor", "premajor", "prerelease"]) .describe("Version bump type"), preid: z.string().optional().describe("Prerelease identifier (e.g. alpha, beta)"), noGitTag: z.boolean().optional().describe("Skip git tag creation"), }, - src/index.ts:26-38 (helper)The run() helper function that wraps execFile to execute npm commands. Used by the version tool handler to run 'npm version <bump>'.
async function run( args: string[], cwd?: string, ): Promise<{ stdout: string; stderr: string }> { const fullArgs = [...args, ...npmrcArgs]; const opts: { cwd?: string; timeout: number; env: NodeJS.ProcessEnv; maxBuffer: number } = { timeout: 120_000, maxBuffer: 10 * 1024 * 1024, // 10MB buffer for large outputs env: { ...process.env, NO_COLOR: "1" }, }; if (cwd) opts.cwd = cwd; return exec(NPM, fullArgs, opts); }