penpot/mcp/packages/plugin/src/VersionCompatibility.ts
Robert 2d649bd53c
🐛 Ignore patch versions in the MCP version compatibility check (#12009)
The plugin compared the full major.minor.patch of the running Penpot
version with the MCP package version. The MCP package version is only
set per minor release (2.15.0, 2.16.0, 2.17.0), so every Penpot patch
release (for example 2.16.2 or 2.17.2) showed the "Version mismatch
detected" warning although nothing changed for the MCP.

Compare only major.minor, move the check into a small module with
unit tests, and update the README versioning note to match.

AI-assisted-by: claude-opus-5-5

Signed-off-by: robertkodra <36516516+robertkodra@users.noreply.github.com>
2026-11-03 16:08:54 +01:00

28 lines
1.1 KiB
TypeScript

/**
* Extracts the major.minor prefix from a version string.
*
* Patch releases of Penpot do not change the plugin API the MCP server is
* written against, and the MCP package version is only set per minor
* release, so the patch component is not part of the compatibility check.
*
* @param version - a version string starting with major.minor (e.g. "2.18.1")
* @returns the major.minor prefix, or the original string if it does not match
*/
export function extractMinorVersion(version: string): string {
const match = version.match(/^(\d+\.\d+)(?:\.|$)/);
return match ? match[1] : version;
}
/**
* Returns whether an MCP build is intended for the running Penpot version.
*
* Local development builds of Penpot report "0.0.0" and are always treated
* as compatible.
*
* @param penpotVersion - the running Penpot version, as major.minor prefix
* @param mcpVersion - the version the MCP build targets, as major.minor prefix
*/
export function isCompatibleVersion(penpotVersion: string, mcpVersion: string): boolean {
return penpotVersion === "0.0" || penpotVersion === mcpVersion;
}