update-mcp
Update specific packages on MCP servers by specifying package names and versions. Streamline package management and ensure consistent environment configurations.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| packageName | Yes | Package name to update | |
| version | No | Specific version to update to |
Implementation Reference
- src/tools/installation-tools.ts:122-146 (handler)Handler function for the 'update-mcp' tool. Validates input parameters, calls packageManager.updatePackage(), handles success/error responses, and returns formatted MCP content.async ({ packageName, version }, extra) => { if (!packageName.trim()) { throw new Error("Package name cannot be empty"); } const result = await packageManager.updatePackage(packageName, version); if (!result.success) { throw new Error(`Failed to update package: ${result.error}`); } return { content: [ { type: "text", text: JSON.stringify({ success: true, packageName: result.packageName, version: result.version, localPath: result.localPath }, null, 2) } ] }; }
- Input schema (Zod) for 'update-mcp' tool defining required packageName (string) and optional version (string).{ packageName: z.string().describe("Package name to update"), version: z.string().optional().describe("Specific version to update to") },
- src/tools/installation-tools.ts:116-147 (registration)Registration of the 'update-mcp' tool on the MCP server within registerInstallationTools function, specifying name, input schema, and handler.server.tool( "update-mcp", { packageName: z.string().describe("Package name to update"), version: z.string().optional().describe("Specific version to update to") }, async ({ packageName, version }, extra) => { if (!packageName.trim()) { throw new Error("Package name cannot be empty"); } const result = await packageManager.updatePackage(packageName, version); if (!result.success) { throw new Error(`Failed to update package: ${result.error}`); } return { content: [ { type: "text", text: JSON.stringify({ success: true, packageName: result.packageName, version: result.version, localPath: result.localPath }, null, 2) } ] }; } );
- Core helper method implementing the package update logic: checks if installed, executes package manager update command, refreshes version/bin info, updates local registry file, returns InstallResult.async updatePackage(packageName: string, version?: string): Promise<InstallResult> { const existing = this.getInstalledPackage(packageName); if (!existing) { return this.installPackage(packageName, version); } try { const packageDir = path.dirname(path.dirname(existing.localPath)); // Update the package const updateCmd = this.getInstallCommand(packageName, version); await exec(updateCmd, { cwd: packageDir }); // Get installed version const nodeModulesDir = path.join(packageDir, 'node_modules'); const installedVersion = await this.getInstalledVersion(nodeModulesDir, packageName); // Find bin path if it exists const binPath = await this.findPackageBin(nodeModulesDir, packageName); // Update registry const now = new Date().toISOString(); const localPath = path.join(nodeModulesDir, packageName); this.registry.packages[packageName] = { ...existing, version: installedVersion, localPath, binPath, updatedAt: now }; await this.saveRegistry(); return { success: true, packageName, version: installedVersion, localPath, binPath }; } catch (error) { return { success: false, packageName, version: version || 'latest', localPath: existing.localPath, error: error instanceof Error ? error.message : String(error) }; } }